Esempio n. 1
0
static void rehash(sd_hash_t* a_this)
{
    size_t			i;
    int h, size;
    sd_hash_iter_t**	tab;
    sd_hash_iter_t*	p;
    sd_hash_iter_t*	q;

    size	= SD_HASH_GROWTAB * a_this->size;
    tab		= sd_calloc(size, sizeof(*tab));

    if (tab == 0) return;

    for (i = 0; i < a_this->size; i++) {
        for (p = a_this->tab[i]; p; p = q) {
            q						= p->__next;
            h						= hindex(p->__hkey,
                                             size);
            p->__next					= tab[h];
            tab[h]					= p;
            if (p->__next != 0) p->__next->__prev	= p;
            p->__prev					= 0;
        }
    }
    free(a_this->tab);

    a_this->tab		= tab;
    a_this->size	= size;
}
Esempio n. 2
0
extern void sd_hash_iter_del(sd_hash_iter_t* a_this)
{
    if (a_this == 0) return;

    if (a_this->hash->ops->data_free != 0)
        a_this->hash->ops->data_free(a_this->data);
    a_this->data	= 0;

    if (a_this->hash->ops->key_free != 0)
        a_this->hash->ops->key_free(a_this->key);
    a_this->key		= 0;

    if (a_this->__foreach == 1) {
        a_this->__foreach = 0;
        return;
    }

    if (a_this->__next != 0) a_this->__next->__prev = a_this->__prev;
    if (a_this->__prev != 0)
        a_this->__prev->__next = a_this->__next;
    else
        a_this->hash->tab[hindex(a_this->__hkey, a_this->hash->size)] =
            a_this->__next;

    a_this->hash->nelem--;

    free(a_this);
}
Esempio n. 3
0
extern sd_hash_iter_t* sd_hash_lookadd(sd_hash_t* a_this, const void* a_key)
{
    int			h;
    sd_hash_iter_t*	p;

    if (a_this == 0 || a_key == 0)			return 0;
    if ((p = sd_hash_lookup(a_this, a_key)) != 0)	return p;
    if ((p = sd_calloc(1, sizeof(*p))) == 0)		return 0;

    if (a_this->ops->key_dup != 0)
        p->key = a_this->ops->key_dup(a_key);
    else
        p->key = (void*) a_key;

    p->hash					= a_this;
    p->__hkey					= a_this->ops->hash(a_key);

    if (a_this->nelem > SD_HASH_FULLTAB * a_this->size) rehash(a_this);

    h						= hindex(p->__hkey,
                                     a_this->size);
    p->__next					= a_this->tab[h];
    a_this->tab[h]				= p;
    if (p->__next != 0) p->__next->__prev	= p;

    a_this->nelem++;

    return p;
}
Esempio n. 4
0
std::size_t grid::save(FILE* fp) const {
	std::size_t cnt = 0;
	auto foo = std::fwrite;
	{
		static hpx::mutex mtx;
		std::lock_guard < hpx::mutex > lock(mtx);
		cnt += foo(&scaling_factor, sizeof(real), 1, fp) * sizeof(real);
		cnt += foo(&max_level, sizeof(integer), 1, fp) * sizeof(integer);
		cnt += foo(&Acons, sizeof(real), 1, fp) * sizeof(real);
		cnt += foo(&Bcons, sizeof(integer), 1, fp) * sizeof(integer);
	}
	cnt += foo(&is_leaf, sizeof(bool), 1, fp) * sizeof(bool);
	cnt += foo(&is_root, sizeof(bool), 1, fp) * sizeof(bool);
	for (integer f = 0; f != NF; ++f) {
		for (integer i = H_BW; i < H_NX - H_BW; ++i) {
			for (integer j = H_BW; j < H_NX - H_BW; ++j) {
				const integer iii = hindex(i, j, H_BW);
				cnt += foo(&(U[f][iii]), sizeof(real), INX, fp) * sizeof(real);
			}
		}
	}
	for (integer i = 0; i < G_NX; ++i) {
		for (integer j = 0; j < G_NX; ++j) {
			for (integer k = 0; k < G_NX; ++k) {
				const integer iii = gindex(i, j, k);
				cnt += foo(&(G[iii][0]), sizeof(real), NGF, fp) * sizeof(real);
			}
		}
	}
	cnt += foo(U_out.data(), sizeof(real), U_out.size(), fp) * sizeof(real);
	return cnt;
}
Esempio n. 5
0
extern void sd_hash_del(sd_hash_t* a_this, const void* a_key)
{
    int			h;
    sd_hash_iter_t*	p;

    h = hindex(a_this->ops->hash(a_key), a_this->size);
    for (p = a_this->tab[h]; p != 0; p = p->__next)
        if (a_this->ops->compare(a_key, p->key) == 0) break;
    if (p == 0) return;

    sd_hash_iter_del(p);
}
Esempio n. 6
0
extern sd_hash_iter_t* sd_hash_lookup(sd_hash_t* a_this, const void* a_key)
{
    int			h;
    sd_hash_iter_t*	p;

    if (a_this == 0 || a_key == 0) return 0;

    h = hindex(a_this->ops->hash(a_key), a_this->size);
    for (p = a_this->tab[h]; p != 0; p = p->__next)
        if (a_this->ops->compare(a_key, p->key) == 0) {
            return p;
        }

    return 0;
}
Esempio n. 7
0
extern sd_hash_iter_t* sd_hash_iter_next(sd_hash_iter_t* a_this)
{
    int h;
    size_t i;

    if (a_this == 0)		return 0;
    if (a_this->__next != 0)	return a_this->__next;

    h = hindex(a_this->__hkey, a_this->hash->size);

    for (i = h + 1; i < a_this->hash->size; i++)
        if (a_this->hash->tab[i])
            return a_this->hash->tab[i];

    return 0;
}
Esempio n. 8
0
extern sd_hash_iter_t* sd_hash_iter_prev(sd_hash_iter_t* a_this)
{
    int			h, i;
    sd_hash_iter_t*	p;

    if (a_this == 0)		return 0;
    if (a_this->__prev != 0)	return a_this->__prev;

    h = hindex(a_this->__hkey, a_this->hash->size);

    for (i = h - 1; i > 0; i--)
        for (p = a_this->hash->tab[i]; p; p = p->__next)
            if (p->__next == 0)
                return p;

    return 0;
}
Esempio n. 9
0
// Compute a heuristic estimate. TODO: reimplement jumpsa and write a
// test for the new way of combining lookups.
int pancake::h(short H)
{
  int ans = 0;			// to be returned
  int val = 0;			// aux variable for heuristic values

  m_jump=0;			// by default, don't jump
  m_target.first=0;		// reset target cause we don't have one yet
  m_target.second=0;

  // no pdb
  if(!m_f || m_pdb==NULL)
    return 0;

  uint32 mask = 0;
  uint8 cost = 0;
  char ol = (pdb_type_ == OL)?1:0; // at least one lookup when using OL
  for (int d = 0; d <= dual_lookups_; ++d){
    if (d) this->dual();
    for (int y = 0; y <= sym_lookups_; ++y){
      if (y) {this->sym(y-1); cost = m_syms[y-1].m_cost;}
      else cost = 0;
      for (int o = 0; o < ord_lookups_ + ol; ++o){
	// watch(o); watch(hord_masks_[o]);
  	mask = (pdb_type_ == ORD)?hord_masks_[o]:0;
	// watch(mask);
  	// TODO: mark necessary jumps for DIDA*
	// watch(hindex(mask));
  	val = m_pdb[hindex(mask)] - cost;
  	ans = max(ans, val);
  	if (ans > H) break;
      }
      // revert sym
      if(y) this->sym(y-1);
      if (ans > H) break;
    }
    // revert dual
    if(d) this->dual();
    if (ans > H) break;
  }

  return ans;			
}
Esempio n. 10
0
grid::output_list_type grid::get_output_list(bool analytic) const {
	auto& V = TLS_V();
	compute_primitives();
	output_list_type rc;
	const integer vertex_order[8] = { 0, 1, 3, 2, 4, 5, 7, 6 };

	std::set<node_point>& node_list = rc.nodes;
	std::vector<zone_int_type>& zone_list = rc.zones;
	std::array < std::vector<real>, NF + NGF + NPF > &data = rc.data;
	std::array < std::vector<real>, NF > &A = rc.analytic;

	for (integer field = 0; field != NF + NGF + NPF; ++field) {
		data[field].reserve(INX * INX * INX);
		if (analytic) {
			A[field].reserve(INX * INX * INX);
		}
	}
	const integer this_bw = H_BW;
	zone_list.reserve(std::pow(H_NX - 2 * this_bw, NDIM) * NCHILD);
	for (integer i = this_bw; i != H_NX - this_bw; ++i) {
		for (integer j = this_bw; j != H_NX - this_bw; ++j) {
			for (integer k = this_bw; k != H_NX - this_bw; ++k) {
				const integer iii = hindex(i, j, k);
				const integer iiig = gindex(i - H_BW, j - H_BW, k - H_BW);
#ifdef EQ_ONLY
				if (!(std::abs(X[ZDIM][iii]) < dx) && !(std::abs(X[YDIM][iii]) < dx)) {
					continue;
				}
#endif
				for (integer ci = 0; ci != NVERTEX; ++ci) {
					const integer vi = vertex_order[ci];
					const integer xi = (vi >> 0) & 1;
					const integer yi = (vi >> 1) & 1;

					const integer zi = (vi >> 2) & 1;
					node_point this_x;
					this_x.pt[XDIM] = X[XDIM][iii] + (real(xi) - HALF) * dx;
					this_x.pt[YDIM] = X[YDIM][iii] + (real(yi) - HALF) * dx;
					this_x.pt[ZDIM] = X[ZDIM][iii] + (real(zi) - HALF) * dx;
					auto iter = node_list.find(this_x);
					integer index;
					if (iter != node_list.end()) {
						index = iter->index;
					} else {
						index = node_list.size();
						this_x.index = index;
						node_list.insert(this_x);
					}
					zone_list.push_back(index);
				}
				if (analytic) {
					for (integer field = 0; field != NF; ++field) {
						A[field].push_back(Ua[field][iii]);
					}
				}
				for (integer field = 0; field != NF; ++field) {
					data[field].push_back(U[field][iii]);
				}
				for (integer field = 0; field != NGF; ++field) {
					data[field + NF].push_back(G[iiig][field]);
				}
				data[NGF + NF + 0].push_back(V[vx_i][iii]);
				data[NGF + NF + 1].push_back(V[vy_i][iii]);
				data[NGF + NF + 2].push_back(V[vz_i][iii]);
				if (V[egas_i][iii] * V[rho_i][iii] < de_switch2 * U[egas_i][iii]) {
					data[NGF + NF + 3].push_back(std::pow(V[tau_i][iii], fgamma) / V[rho_i][iii]);
				} else {
					data[NGF + NF + 3].push_back(V[egas_i][iii]);
				}
				data[NGF + NF + 4].push_back(V[zz_i][iii]);
			}
		}
	}

	return rc;
}