Ejemplo n.º 1
0
void _random_fill (VsgPRTree2d *tree, guint np)
{
  gint i;
  Pt *pt;
  VsgVector2d lb, ub;
  GRand *rand = g_rand_new_with_seed (_random_seed);

  vsg_prtree2d_get_bounds (tree, &lb, &ub);

  _ref_count = 0;

  for (i=0; i< np; i++)
    {
      gdouble x1, y1;
      gint c;

      x1 = g_rand_double_range (rand, lb.x, ub.x);
      y1 = g_rand_double_range (rand, lb.y, ub.y);

      c = i+1;

      _ref_count += c;

      if (i%_flush_interval == 0)
        {
          vsg_prtree2d_migrate_flush (tree);
          if (i%(_flush_interval*10) == 0)
            {
              if (_verbose && rk == 0)
                g_printerr ("%d: contiguous dist before %dth point\n", rk, i);
              _distribute (tree);
            }
        }

      if (i%sz != rk) continue;

      if (i % 10000 == 0 && _verbose)
        g_printerr ("%d: insert %dth point\n", rk, i);

      pt = pt_alloc (TRUE, NULL);
      pt->vector.x = x1;
      pt->vector.y = y1;
      pt->weight = c;

      vsg_prtree2d_insert_point (tree, pt);
    }

  vsg_prtree2d_migrate_flush (tree);

  _distribute (tree);

  g_rand_free (rand);
}
Ejemplo n.º 2
0
/* faster algorithm for circle distribution */
void _circle_fill (VsgPRTree2d *tree, guint np)
{
  gint i;
  Pt *pt;
  const gdouble r = 0.95;
  gdouble dtheta = 2. * G_PI / (np-1) / sz;
  gdouble theta0 = 2. * rk * G_PI / sz;

  for (i=0; i<np; i++)
    {
      gint c;

      c = i+1;

      _ref_count += c;

      if (i%_flush_interval == 0)
        {
          vsg_prtree2d_migrate_flush (tree);
          if (i%(_flush_interval*10) == 0)
            {
              if (_verbose && rk == 0)
                g_printerr ("%d: contiguous dist before %dth point\n", rk, i);
              _distribute (tree);
            }
        }
      if (i%sz != rk) continue;

      if (i % 10000 == 0 && _verbose)
        g_printerr ("%d: insert %dth point\n", rk, i);

      pt = pt_alloc (TRUE, NULL);

      pt->vector.x = r * cos (theta0 + i * dtheta);
      pt->vector.y = r * sin (theta0 + i * dtheta);
      pt->weight = c;

      vsg_prtree2d_insert_point (tree, pt);
    }

  vsg_prtree2d_migrate_flush (tree);
  _distribute (tree);
}
Ejemplo n.º 3
0
void _circle2_fill (VsgPRTree2d *tree, guint np)
{
  gint i;
  Pt *pt;
  const gdouble r = 0.95;
  gdouble dtheta = 2. * G_PI / (np-1);
  gdouble theta0 = 0.;

  pt = pt_alloc (TRUE, NULL);

  for (i=0; i<np; i++)
    {
      gint c;

      c = i+1;

      _ref_count += c;

      pt->vector.x = r * cos (theta0 + i * dtheta);
      pt->vector.y = r * sin (theta0 + i * dtheta);
      pt->weight = c;

      if (vsg_prtree2d_insert_point_local (tree, pt))
        {
          if (i % 10000 == 0 && _verbose)
            g_printerr ("%d: insert %dth point\n", rk, i);

          pt = pt_alloc (TRUE, NULL);
        }

      if (i%(_flush_interval*10) == 0)
        {
          if (_verbose && rk == 0)
            g_printerr ("%d: contiguous dist before %dth point\n", rk, i);
          _distribute (tree);
        }
    }

  pt_destroy (pt, TRUE, NULL);

  _distribute (tree);
}
Ejemplo n.º 4
0
/**
 * Generate a hash table to map the key,value pairs found in the
 * specified datafile, and write a compileable C file to the output
 * file.
 */
int generate_hash_simple(lua_State *L, const char *datafile_name,
    const char *prefix1, const char *ofname)
{
    FILE *ifile;

    state.hashfunc = _find_hashfunc(hashfunc_name);
    state.seed = 0;
    prefix = prefix1;

    ifile = fopen(datafile_name, "r");
    if (!ifile)
	return luaL_error(L, "Can't open %s for reading: %s", datafile_name,
	    strerror(errno));

    // Count the number of entries in the hash table; that's the desired
    // size of the hash table.  Each bucket should contain, on average,
    // one entry.
    bucket_count = _count_lines(ifile);
    _build_hash_table(L, ifile);
    fclose(ifile);

    _distribute(L);

    ofile = fopen(ofname, "w");
    if (!ofile)
	return luaL_error(L, "Can't open %s for writing: %s", ofname,
	    strerror(errno));
    _output_values(L, ofile);
    _output_buckets(L, ofile);
    _output_meta();
    _show_statistics();
    _cleanup();

    fclose(ofile);
    return 0;
}