示例#1
0
文件: mrow.c 项目: soc-lip6/gecos
void hash_delete()
{
	//populate
	int i;
	node_t **hd;
	lock_t *lck;

#ifdef COUNT_HASH_EMPTY
	int empty = 0;
	for(i=0; i< nbkeys; i++)
	{
		get_buckets(i, &hd, &lck);
		if(*hd==NULL) empty++;
	}
	printf("empty = %d, total = %d, ratio: %d\n", empty, nbkeys, empty/nbkeys);
#endif
	
	for(i=0; i< nbkeys; i++)
	{
		get_buckets(i, &hd, &lck);
		delete(i, hd, lck);
	}

#ifdef SET_TAIL
	//printf("SET TAIL\n");
	//insert max key
	get_buckets(i, &hd, &lck);
	delete(nbkeys+1, hd, lck);
#endif
	free((void*)hash.heads);
	free((void*)hash.locks);

}
示例#2
0
文件: mrow.c 项目: soc-lip6/gecos
void hash_init() 
{
	int i;

	hash.heads = calloc(sizeof(struct node_t*), nbbuckets);
	hash.locks = calloc(sizeof(lock_t), nbbuckets);

	for(i=0; i < nbbuckets; i++)
	{
		lock_init(&hash.locks[i]);
	} 

	//populate
	node_t **hd;
	lock_t *lck;

#ifdef POPULATE
	unsigned nbcores = get_nbcores();
	unsigned percorekeys = (nbkeys/nbcores)+1;
	unsigned nextcore = 1;
	//printf("npn %d %d %d\n", nbcores, percorekeys, nextcore);
	for(i=0; i< nbkeys; i++)
	{
		if(!(i%percorekeys))
		{
			//printf("switching to core %d at %d keys\n", nextcore, i);
			set_affinity(nextcore%nbcores);
			nextcore++;
		} 
		get_buckets(i, &hd, &lck);
		insert(i, hd, lck);
	}
	//printf("empty = %d, total = %d\n", empty, nbkeys);
#endif

#ifdef SET_TAIL
	printf("SET TAIL\n");
	//insert max key
	get_buckets(i, &hd, &lck);
	insert(nbkeys+1, hd, lck);
#endif
}
示例#3
0
文件: chm2.cpp 项目: ahiguti/pxc
  Tm *find_internal(const Tk& k, size_type bkt) const {
    node_type **const buckets = get_buckets();
    assert(bkt < h.num_buckets);
    for (node_type *p = buckets[bkt]; p != 0; p = p->next) {
      entry_type& pe = p->entry;
      if (eq(pe.first, k)) {
	return &pe.second;
      }
    }
    return 0;
  }
示例#4
0
文件: chm2.cpp 项目: ahiguti/pxc
  ~hashmap_buckets() {
    hashmap_buckets_hdr& h = *hdr;
    node_type **const buckets = get_buckets();
    for (size_type i = 0; i < h.num_buckets; ++i) {
      node_type *p = buckets[i];
      while (p != 0) {
	node_type *np = p->next;
	delete p;
	p = np;
      }
    }
    free(hdr);
  }
STKUNIT_UNIT_TEST( PerformanceTestSelector, start)
{
  size_t N = 5;
  VariableSelectorFixture fix(N);
  stk::mesh::Selector selectUnion;
  for (size_t part_i = 0 ; part_i<N ; ++part_i) {
    selectUnion |= *fix.m_declared_part_vector[part_i];
  }
  std::vector<stk::mesh::Bucket*> buckets_out;
  unsigned entity_rank = 0;
  get_buckets(selectUnion, fix.m_BulkData.buckets(entity_rank), buckets_out);
  STKUNIT_ASSERT_EQUAL( buckets_out.size(), N );
  // Construct once for large N
  // Graph time for get_buckets against 1..N
}
示例#6
0
文件: chm2.cpp 项目: ahiguti/pxc
 hashmap_buckets(size_type ini_num_buckets, modulo_func mf) {
   hdr = static_cast<hashmap_buckets_hdr *>(malloc(
     sizeof(hashmap_buckets_hdr) +
     ini_num_buckets * sizeof(node_type *)));
     /* FIXME: check overflow */
   if (hdr == 0) {
     throw std::bad_alloc();
   }
   hashmap_buckets_hdr& h = *hdr;
   node_type **const buckets = get_buckets();
   h.num_entries = 0;
   h.num_buckets = ini_num_buckets;
   h.buckets_modf = mf;
   for (size_type i = 0; i < ini_num_buckets; ++i) {
     buckets[i] = 0;
   }
 }
示例#7
0
文件: chm2.cpp 项目: ahiguti/pxc
  bool insert(const Tk& k, const Tm& m, size_type bkt) {
    hashmap_buckets_hdr& h = *hdr;
    node_type **const buckets = get_buckets();
    assert(bkt < h.num_buckets);
    node_type *cur = buckets[bkt];
    for (node_type *p = cur; p != 0; p = p->next) {
      entry_type& pe = p->entry;
      if (eq(pe.first, k)) {
	pe.second = m;
	return false; /* not created */
      }
    }
    /* append to the end of the buket */
    node_type *const nn = new node_type(cur, k, m);
    buckets[bkt] = nn;
    ++h.num_entries;
    return true; /* created */
  }
STKUNIT_UNIT_TEST( PerformanceTestSelector, timings)
{
  // Construction

  // If we are running with STL in debug mode we shrink the problem
  // down in order to keep things running in a reasonable amount of
  // time.
#ifdef _GLIBCXX_DEBUG
  size_t N = 1000;
#else
  size_t N = 10000;
#endif

  VariableSelectorFixture fix(N);

  std::vector<double> selector_creation(N/2);
  std::vector<double> get_buckets_usage(N/2);
  double start_time = stk::wall_time();
  size_t timing_index = 0;
  for (size_t n = 1 ; n<N; n*=2) {
    // Selector creation
    stk::mesh::Selector selectUnion;
    for (size_t part_i = 0 ; part_i<n ; ++part_i) {
      selectUnion |= *fix.m_declared_part_vector[part_i];
    }
    selector_creation[timing_index] = stk::wall_dtime(start_time);

    // Selector usage:
    std::vector<stk::mesh::Bucket*> buckets_out;
    unsigned entity_rank = 0;
    get_buckets(selectUnion, fix.m_BulkData.buckets(entity_rank), buckets_out);
    get_buckets_usage[timing_index] = stk::wall_dtime(start_time);
    ++timing_index;
  }

  // Print out table
  std::cout << "\"N\" \"selector_creation_time\" \"get_buckets_time\" " << std::endl;
  timing_index = 0;
  for (size_t n = 1 ; n<N; n*=2) {
    std::cout << n << " " << selector_creation[timing_index] << " " << get_buckets_usage[timing_index] << std::endl;
    ++timing_index;
  }
  STKUNIT_EXPECT_TRUE(true);
}
示例#9
0
bool Selector::is_empty(EntityRank entity_rank) const
{
    if (m_expr.empty()) {
        return true;
    }

    BulkData * mesh = this->find_mesh();
    ThrowRequireMsg(mesh != NULL,
                    "ERROR, Selector::empty not available if selector expression does not involve any mesh Parts.");
    if (mesh->in_modifiable_state()) {
      BucketVector const& buckets = this->get_buckets(entity_rank);
      for(size_t i=0; i<buckets.size(); ++i) {
          if (buckets[i]->size() >0) {
              return false;
          }
      }
      return true;
    }
    return get_buckets(entity_rank).empty();
}
示例#10
0
void bucket_traverse(const EntitySelector &entity_selector, const RelationSelector &relation_selector, Visitor &visitor, Mesh &mesh)
{
  typedef typename sierra::mesh::mesh_traits<Mesh>::bucket_key bucket_key;
  typedef typename sierra::mesh::mesh_traits<Mesh>::selected_bucket_range selected_bucket_range;
  typedef typename sierra::mesh::mesh_traits<Mesh>::bucket_key bucket_descriptor;
  typedef typename sierra::mesh::mesh_traits<Mesh>::bucket_entity_range bucket_entity_range;
  typedef typename sierra::mesh::mesh_traits<Mesh>::bucket_entity_iterator bucket_entity_iterator;
  typedef typename sierra::mesh::mesh_traits<Mesh>::selected_bucket_iterator selected_bucket_iterator;
  typedef typename sierra::mesh::mesh_traits<Mesh>::entity_descriptor entity_descriptor;
  typedef typename sierra::mesh::mesh_traits<Mesh>::entity_descriptor_range entity_descriptor_range;
  typedef typename sierra::mesh::mesh_traits<Mesh>::relation_range relation_range;
  typedef typename sierra::mesh::mesh_traits<Mesh>::relation_descriptor relation_descriptor;
  typedef typename sierra::mesh::mesh_traits<Mesh>::relation_iterator relation_iterator;
  typedef typename sierra::mesh::mesh_traits<Mesh>::entity_rank entity_rank;

  visitor.initialize(mesh);

  selected_bucket_range buckets = get_buckets(entity_selector, mesh);
  for (selected_bucket_iterator b_iter = boost::begin(buckets), b_end = boost::end(buckets);  b_iter != b_end; ++b_iter) {
    bucket_descriptor bucket = *b_iter;
    visitor.discover_bucket(bucket, mesh);

    bucket_entity_range entities = get_entities(*b_iter, mesh);
    for (bucket_entity_iterator ent_iter = boost::begin(entities), ent_end = boost::end(entities); ent_iter != ent_end; ++ent_iter) {
      entity_descriptor entity = *ent_iter;
      visitor.discover_entity(entity, mesh);

      relation_range entity_relations = sierra::mesh::get_relations(entity, relation_selector, mesh);
      visitor.examine_relation_range(entity_relations, mesh);

      for (relation_iterator rel_iter = boost::begin(entity_relations), rel_end = boost::end(entity_relations); rel_iter != rel_end; ++rel_iter) {
        relation_descriptor relation = *rel_iter;
        visitor.examine_relation(relation, mesh);
      }

      visitor.finish_entity(entity, mesh);
    }
    visitor.finish_bucket(bucket, mesh);
  }
  visitor.finalize(mesh);
}
示例#11
0
文件: mrow.c 项目: soc-lip6/gecos
void* run(void* arg)
{
	unsigned long i;
	char iamreader;
	int key; long t = (long) arg; long nbn;//same cache line for the best rand!
	double start, end;
	node_t **hd;
	lock_t *lck;

	set_affinity(t);

	/************ init *****************/
	thd_ins = 0;
	thd_del = 0;
	thd_sea = 0;
	nbmallocs = 0;
	nbretry = 0;
	nbrelink = 0;
	nbreprev = 0;
	nbfl = 0;
	thread=t;
	thd_nbupdaters=nbupdaters;
	setsignals();
	iamreader = t >= nbupdaters ? 1 : 0;
	if(!iamreader)	prealloc();
	mysrand(t^time(NULL));
	/************** init done **************/

	/************** barrier ****************/
	atomic_xadd4(&ready, 1);
	while(!go) memory_barrier();

	/******************* START ****************/
	start = d_gettimeofday();
#ifdef RCU
	rcu_register_thread();
#endif

	i=0;
	do{
		key = myrand()%nbkeys;
		//key = rand_r(&thd_seed)%nbthreads;
		//key = (t+key)%nbkeys;
		//key = random() % nbkeys;
		//if(i%100000) printf("%d %d\n", thread, key);

		get_buckets(key, &hd, &lck);
		if(iamreader)
		{
			thd_sea += search(key, hd, lck);
			if(i>= NB_TEST) break;
		}
		else
		{
			if(i%2)
				thd_ins += insert(key, hd, lck);
			else
				thd_del += delete(key, hd, lck);
			if(done) {
				//printf("writer stopped\n");
				break;
			}
		}
		//if(!(i%10000)) 
			//printf("%d loop %d\n", t, i);
#ifdef RCU_QSBR
#if ((defined RCU_QSBR_ACCELERATE) || (defined RCU_Q10))
#ifdef RCU_Q10
		if(!(i%10)) 
#else
		if(!(i%100)) 
#endif
#endif
			rcu_quiescent_state();
#endif
	}while(++i);

#ifdef RCU
	//if(!iamreader) rcu_barrier();
	//printf("iamreader %d, ops %d\n", iamreader, i);
	rcu_unregister_thread();
#endif

	end = d_gettimeofday(); 
	/******************* END ****************/

	
	//number of ops done
	thd_ops[t] = i;
	
	//printf("nbmallocs %g\n", nbmallocs);
	thd_mallocs[t] = nbmallocs;
	thd_retry[t] = nbretry;
	thd_relink[t] = nbrelink;
	thd_reprev[t] = nbreprev;

	//if(t==0) printf("%lu | nbblocked %g\n", t, nbblockeds);
#ifdef RCU
	thd_blockeds[t] = atomic_read_ptr(&rcublockeds);
#else
	thd_blockeds[t] = nbblockeds;
#endif

	//average time per ops
	avg_time[t] = (((end - start))/i);

	//total time
	thd_time[t] = (end - start);

	suc_ins[t] = thd_ins;
	suc_sea[t] = thd_sea;
	suc_del[t] = thd_del;

	return NULL;
}
示例#12
0
 stk::mesh::BucketVector const& get_buckets()
 {
     return get_buckets(stk::mesh::selectField(scalarField));
 }