Exemplo n.º 1
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgPRTree3d *tree;
  gint i;

  VsgVector3d lb;
  VsgVector3d ub;


  MPI_Init (&argc, &argv);

  MPI_Comm_size (MPI_COMM_WORLD, &sz);
  MPI_Comm_rank (MPI_COMM_WORLD, &rk);

  if (argc > 1 && g_ascii_strncasecmp (argv[1], "--version", 9) == 0)
    {
      if (rk == 0)
        g_print ("%s\n", PACKAGE_VERSION);
      return 0;
    }

  if (argc > 1 && g_ascii_strncasecmp (argv[1], "--write", 7) == 0)
    {
      _do_write = TRUE;
    }

  vsg_init_gdouble ();

  points = g_ptr_array_new ();
  regions = g_ptr_array_new ();

  if (rk == 0)
    {
      VsgVector3d *pt;
      Sphere *c;

      lb.x = -1.; lb.y = -1.; lb.z = -1.;
      ub.x = 0.; ub.y = 0.; ub.z = 0.;

      pt = pt_alloc (TRUE, NULL);
      pt->x = -0.5; pt->y = -0.5; pt->z = -0.5;

      c = rg_alloc (TRUE, NULL);
      c->center.x = -0.6; c->center.y = -0.6; c->center.z = -0.6;
      c->radius = 0.1;
    }
  else
    {
      VsgVector3d *pt;
      Sphere *c;

      lb.x = 0.; lb.y = 0.; lb.z = 0.;
      ub.x = 1.*rk; ub.y = 1.*rk; ub.z = 1.*rk;

      pt = pt_alloc (TRUE, NULL);
      pt->x = 0.5*rk; pt->y = 0.5*rk; pt->z = 0.5*rk;

      pt = pt_alloc (TRUE, NULL);
      pt->x = 0.60*rk; pt->y = 0.65*rk; pt->z = 0.70*rk;

      pt = pt_alloc (TRUE, NULL);
      pt->x = 0.15*rk; pt->y = 0.75*rk; pt->z = 0.80*rk;

      c = rg_alloc (TRUE, NULL);
      c->center.x = 0.6*rk; c->center.y = 0.6*rk; c->center.z = 0.6*rk;
      c->radius = 0.11;
    }

  /* create the tree */
  tree =
    vsg_prtree3d_new_full (&lb, &ub,
                           (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc,
                           (VsgPoint3dDistFunc) vsg_vector3d_dist,
                           (VsgRegion3dLocFunc) _sphere_loc3, 2);

  /* insert the points */
  for (i=0; i<points->len; i++)
    {
      vsg_prtree3d_insert_point (tree, g_ptr_array_index (points, i));
    }

  /* insert the regions */
  for (i=0; i<regions->len; i++)
    {
      vsg_prtree3d_insert_region (tree, g_ptr_array_index (regions, i));
    }

  /* count total created points and regions */
  init_total_points_count ();
  init_total_regions_count ();

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: set_parallel begin\n", rk); */

  vsg_prtree3d_set_parallel (tree, &pconfig);

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: set_parallel ok\n", rk); */

  ret += check_points_number (tree);
  ret += check_regions_number (tree);

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: before migrate_flush ok\n", rk); */
  {
    VsgVector3d *pt;
    Sphere *c;

    pt = pt_alloc (TRUE, NULL);
    pt->x = 0.5*rk; pt->y = 0.75*rk; pt->z = 0.75*rk;
    vsg_prtree3d_insert_point (tree, pt);

    c = rg_alloc (TRUE, NULL);
    c->center.x = 1.; c->center.y = 0.6*rk; c->center.z = 0.6*rk;
    c->radius = 0.1;
    vsg_prtree3d_insert_region (tree, c);
  }

  /* update total points and regions count */
  init_total_points_count ();
  init_total_regions_count ();

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: migrate_flush begin\n", rk); */

  vsg_prtree3d_migrate_flush (tree);

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: migrate_flush ok\n", rk); */

  ret += check_points_number (tree);
  ret += check_regions_number (tree);

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: distribute_nodes begin\n", rk); */

  for (i=0; i<sz; i++)
    {
      gint dst = (i+1) % sz;

/*       MPI_Barrier (MPI_COMM_WORLD); */
/*       g_printerr ("%d: move to %d\n", rk, dst); */

      vsg_prtree3d_distribute_concentrate (tree, dst);

      ret += check_points_number (tree);
      ret += check_regions_number (tree);
    }

/*   MPI_Barrier (MPI_COMM_WORLD); */
/*   g_printerr ("%d: split between nodes\n", rk); */

  vsg_prtree3d_distribute_scatter_leaves (tree);

  ret += check_points_number (tree);
  ret += check_regions_number (tree);

/* /\*   MPI_Barrier (MPI_COMM_WORLD); *\/ */
/* /\*   g_printerr ("%d: distribute_nodes ok\n", rk); *\/ */

  if (_do_write)
    {
      MPI_Barrier (MPI_COMM_WORLD);
      _tree_write (tree);
    }

  if (_do_write)
    {
      gchar fn[1024];
      FILE *f;

      g_sprintf (fn, "prtree3parallel-%03d.txt", rk);
      f = fopen (fn, "w");
      vsg_prtree3d_write (tree, f);
      fclose (f);
    }

  /* destroy the points */
  g_ptr_array_foreach (points, empty_array, NULL);
  g_ptr_array_free (points, TRUE);

  /* destroy the spheres */
  g_ptr_array_foreach (regions, empty_array, NULL);
  g_ptr_array_free (regions, TRUE);

  /* destroy the tree */
  vsg_prtree3d_free (tree);

  MPI_Finalize ();

  return ret;
}
Exemplo n.º 2
0
gint main (gint argc, gchar ** argv)
{
  gint ret = 0;

  VsgPRTree3d *tree;

  VsgVector3d lb;
  VsgVector3d ub;


  MPI_Init (&argc, &argv);

  MPI_Comm_size (MPI_COMM_WORLD, &sz);
  MPI_Comm_rank (MPI_COMM_WORLD, &rk);

  vsg_init_gdouble ();

  parse_args (argc, argv);

  points = g_ptr_array_new ();
  regions = g_ptr_array_new ();

  lb.x = -1.; lb.y = -1.; lb.z = -1.;
  ub.x = 1.; ub.y = 1.; ub.z = 1.;

  /* create the tree */
  tree =
    vsg_prtree3d_new_full (&lb, &ub,
                           (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc,
                           (VsgPoint3dDistFunc) vsg_vector3d_dist,
                           (VsgRegion3dLocFunc) _sphere_loc3, 2);

  if (_hilbert)
    {
      /* configure for hilbert curve order traversal */
      vsg_prtree3d_set_children_order_hilbert (tree);
    }

  if (_verbose)
    {
      MPI_Barrier (MPI_COMM_WORLD);
      g_printerr ("%d: set_parallel begin\n", rk);
    }

  vsg_prtree3d_set_parallel (tree, &pconfig);

  if (_verbose)
    {
      MPI_Barrier (MPI_COMM_WORLD);
      g_printerr ("%d: set_parallel ok\n", rk);
    }

  if (_verbose)
    {
      MPI_Barrier (MPI_COMM_WORLD);
      g_printerr ("%d: fill begin\n", rk);
    }

  _fill (tree, _np);

  _check_local_counts (tree);

  if (_verbose)
    {
      MPI_Barrier (MPI_COMM_WORLD);
      g_printerr ("%d: fill ok\n", rk);
    }

  /* update total points and regions count */
  init_total_points_count ();
  init_total_regions_count ();

  if (_scatter_before)
    {
      if (_verbose)
        {
          MPI_Barrier (MPI_COMM_WORLD);
          g_printerr ("%d: scatter nodes begin\n", rk);
        }

      vsg_prtree3d_distribute_scatter_leaves (tree);

      _check_local_counts (tree);

      ret += check_points_number (tree);
      ret += check_regions_number (tree);

      if (_verbose)
        {
          MPI_Barrier (MPI_COMM_WORLD);
          g_printerr ("%d: scatter nodes ok\n", rk);
        }

      _write_regions (tree, "rg-scatter");
      _tree_write (tree, "scatter-");
    }

  if (_do_contiguous)
    {
      if (_verbose)
        {
          MPI_Barrier (MPI_COMM_WORLD);
          g_printerr ("%d: contiguous distribute begin\n", rk);
        }

      vsg_prtree3d_distribute_contiguous_leaves (tree);

      _check_local_counts (tree);

      ret += check_points_number (tree);
      ret += check_regions_number (tree);

      if (_verbose)
        {
          MPI_Barrier (MPI_COMM_WORLD);
          g_printerr ("%d: contiguous distribute ok\n", rk);
        }

      _write_regions (tree, "rg-contiguous");
    }

  _exterior_points (tree);

  vsg_prtree3d_distribute_contiguous_leaves (tree);

  _check_local_counts (tree);

  if (_do_write)
    {
      MPI_Barrier (MPI_COMM_WORLD);
      _tree_write (tree, "prtree3parallel-");
    }

  if (_do_write)
    {
      gchar fn[1024];
      FILE *f;

      g_sprintf (fn, "prtree3parallel-%03d.txt", rk);
      f = fopen (fn, "w");
      vsg_prtree3d_write (tree, f);
      fclose (f);
    }

  /* destroy the points */
  g_ptr_array_foreach (points, empty_array, NULL);
  g_ptr_array_free (points, TRUE);

  /* destroy the spheres */
  g_ptr_array_foreach (regions, empty_array, NULL);
  g_ptr_array_free (regions, TRUE);

  /* destroy the tree */
  vsg_prtree3d_free (tree);

  MPI_Finalize ();

  return ret;
}