/** * aran_solver3d_insert_point: * @solver: an #AranSolver3d. * @point: a particle. * * Inserts a particle @point into the associated #VsgPRTree3d. */ void aran_solver3d_insert_point (AranSolver3d *solver, VsgPoint3 point) { g_return_if_fail (solver != NULL); vsg_prtree3d_insert_point (solver->prtree, point); }
static void random_fill (VsgPRTree3d *tree, guint np) { gint i; VsgVector3d *pt; Sphere *c; VsgVector3d lb, ub; GRand *rand = g_rand_new_with_seed (_random_seed); vsg_prtree3d_get_bounds (tree, &lb, &ub); for (i=0; i< np; i++) { gdouble x1, x2, y1, y2, z1, z2, r; x1 = g_rand_double_range (rand, lb.x, ub.x); y1 = g_rand_double_range (rand, lb.y, ub.y); z1 = g_rand_double_range (rand, lb.z, ub.z); x2 = g_rand_double_range (rand, lb.x, ub.x); y2 = g_rand_double_range (rand, lb.y, ub.y); z2 = g_rand_double_range (rand, lb.z, ub.z); r = g_rand_double_range (rand, 0., 0.1); if (i%_flush_interval == 0) vsg_prtree3d_migrate_flush (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->x = x1; pt->y = y1; pt->z = z1; vsg_prtree3d_insert_point (tree, pt); if (_put_regions) { c = rg_alloc (TRUE, NULL); c->center.x = x2; c->center.y = y2; c->center.z = z2; c->radius = r; vsg_prtree3d_insert_region (tree, c); } /* g_printerr ("%d: %d\n", rk, i); */ } vsg_prtree3d_migrate_flush (tree); g_rand_free (rand); }
static void _exterior_points (VsgPRTree3d *tree) { VsgVector3d lb, ub; VsgVector3d *pt; if (_verbose) g_printerr ("%d: exterior points\n", rk); vsg_prtree3d_get_bounds (tree, &lb, &ub); pt = pt_alloc (TRUE, NULL); pt->x = ub.x+rk+1.; pt->y = ub.y+rk+1.; pt->z = ub.z+rk+1.; vsg_prtree3d_insert_point (tree, pt); vsg_prtree3d_migrate_flush (tree); if (_verbose) g_printerr ("%d: exterior points ok\n", rk); }
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; }
gint main (gint argc, gchar ** argv) { gint ret = 0; VsgVector3d lb = {-1., -1., -1.}; VsgVector3d ub = {1., 1., 1.}; VsgVector3d points[] = { {-0.5, -0.5, -.5}, {0.5, -0.5, -.5}, {-0.5, 0.5, .5}, {0.25, 0.25, .5}, {0.75, 0.75, .5}, {1.75, 1.75, 1.}, /* exterior point */ {1.75, 100.75, 1.}, /* another exterior point */ {1.75, -100.75, 1.}, /* another exterior point */ }; const guint n = sizeof (points) / sizeof (VsgVector3d); VsgPRTree3d *tree; gint i; if (argc > 1 && g_ascii_strncasecmp (argv[1], "--version", 9) == 0) { g_print ("%s\n", PACKAGE_VERSION); return 0; } vsg_init_gdouble (); /* create the tree */ tree = vsg_prtree3d_new_full (&lb, &ub, (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc, (VsgPoint3dDistFunc) vsg_vector3d_dist, NULL, 1); /* insert some points */ for (i=0; i<n; i++) { vsg_prtree3d_insert_point (tree, &points[i]); } /* do some traversal */ i=0; vsg_prtree3d_traverse (tree, G_PRE_ORDER, (VsgPRTree3dFunc) traverse_point_count, &i); /* check the results */ if (i != n) { g_printerr ("ERROR: traverse point count %d (should be %d)\n", i, n); ret ++; } /* remove the points */ for (i=0; i<n; i++) { vsg_prtree3d_remove_point (tree, &points[i]); } /* destroy the tree */ vsg_prtree3d_free (tree); return ret; }
gint main (gint argc, gchar ** argv) { gint ret = 0; VsgVector3d lb = {-1., -1., -1.}; VsgVector3d ub = {1., 1., 1.}; NodeCounter counter = {0, 0}; const guint m = 100; const guint n = 1000; Pt points[m*n]; VsgPRTree3d *tree; gint i; if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0) { g_print ("%s\n", PACKAGE_VERSION); return 0; } vsg_init_gdouble (); /* create the tree */ tree = vsg_prtree3d_new (&lb, &ub, NULL); vsg_prtree3d_set_node_data (tree, TYPE_NODE_COUNTER, &counter); /* create the points */ create_points (points, m, n); /* insert the points into the tree */ for (i=0; i<m*n; i++) { vsg_prtree3d_insert_point (tree, &points[i]); } /* g_printerr ("ok depth = %d size = %d\n", */ /* vsg_prtree3d_depth (tree), */ /* vsg_prtree3d_point_count (tree)); */ /* accumulate the point counts across the tree */ vsg_prtree3d_traverse (tree, G_POST_ORDER, (VsgPRTree3dFunc) up, NULL); /* do some near/far traversal */ vsg_prtree3d_near_far_traversal (tree, (VsgPRTree3dFarInteractionFunc) far, (VsgPRTree3dInteractionFunc) near, &ret); /* distribute back the point counts across the tree */ vsg_prtree3d_traverse (tree, G_PRE_ORDER, (VsgPRTree3dFunc) down, NULL); /* check the results */ for (i=0; i<m*n; i++) { if (points[i].count != m*n) { g_printerr ("ERROR: wrong count on point %d: %d (should be %d).\n", i, points[i].count, n); ret ++; } } /* remove the points */ for (i=0; i<m*n; i++) { vsg_prtree3d_remove_point (tree, &points[i]); } /* destroy the tree */ vsg_prtree3d_free (tree); return ret; }
gint main (gint argc, gchar ** argv) { gint ret = 0; VsgVector3d lb = {-1., -1., -1.}; VsgVector3d ub = {1., 1., 1.}; VsgVector3d *points; gint lvl = 1; gint n, np; VsgPRTree3d *tree; gint i, j, k, l; if (argc > 1 && g_strncasecmp (argv[1], "--version", 9) == 0) { g_print ("%s\n", PACKAGE_VERSION); return 0; } if (argc > 1) { sscanf (argv[1], "%d", &lvl); } n = 1<<lvl; np = n*n*n; vsg_init_gdouble (); /* create the points */ points = g_malloc (np * sizeof (VsgVector3d)); l = 0; for (i=0; i<n; i++) { gdouble x = 2. * ((i+0.5)/n) - 1.; for (j=0; j<n; j++) { gdouble y = 2. * ((j+0.5)/n) - 1.; for (k=0; k<n; k++) { gdouble z = 2. * ((k+0.5)/n) - 1.; vsg_vector3d_set (&points[l], x, y, z); l ++; } } } /* create the tree */ tree = vsg_prtree3d_new_full (&lb, &ub, (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc, (VsgPoint3dDistFunc) vsg_vector3d_dist, NULL, 1); /* configure for hilbert curve order traversal */ vsg_prtree3d_set_children_order (tree, hilbert3_order, GINT_TO_POINTER (HK3_0_2_1)); /* insert some points */ for (i=0; i<np; i++) { vsg_prtree3d_insert_point (tree, &points[i]); } /* do some traversal */ i=0; vsg_prtree3d_traverse (tree, G_PRE_ORDER, (VsgPRTree3dFunc) traverse_point_count, &i); /* check the results */ if (i != np) { g_printerr ("ERROR: traverse point count %d (should be %d)\n", i, n); ret ++; } /* remove the points */ for (i=0; i<np; i++) { vsg_prtree3d_remove_point (tree, &points[i]); } g_free (points); /* destroy the tree */ vsg_prtree3d_free (tree); return ret; }