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; VsgPRTree2d *tree; VsgVector2d lb; VsgVector2d ub; GTimer *timer = NULL; 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); if (nc_padding > 0) { if (_verbose && rk == 0) g_printerr ("%d: NodeCounter padding: %d\n", rk, nc_padding); _nc_padding_buffer = g_malloc (nc_padding * sizeof (char)); } points = g_ptr_array_new (); lb.x = -1.; lb.y = -1.; ub.x = 1.; ub.y = 1.; /* create the tree */ tree = vsg_prtree2d_new_full (&lb, &ub, (VsgPoint2dLocFunc) vsg_vector2d_vector2d_locfunc, (VsgPoint2dDistFunc) vsg_vector2d_dist, NULL, _maxbox); if (_hilbert) { /* configure for hilbert curve order traversal */ vsg_prtree2d_set_children_order_hilbert (tree); } if (_verbose) { MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: set_parallel begin\n", rk); } vsg_prtree2d_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); /* /\* try one exterior point *\/ */ /* if (sz > 1) */ /* { */ /* if (rk == 1) */ /* { */ /* Pt *pt; */ /* _ref_count += _np+1; */ /* pt = pt_alloc (TRUE, NULL); */ /* pt->vector.x = ub.x+1.; */ /* pt->vector.y = ub.y+1.; */ /* pt->weight = _np+1; */ /* vsg_prtree2d_insert_point (tree, pt); */ /* } */ /* else */ /* { */ /* _ref_count += _np+1; */ /* } */ /* vsg_prtree2d_migrate_flush (tree); */ /* _distribute (tree); */ /* } */ if (_verbose) { MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: fill ok\n", rk); } if (_do_write) { gchar fn[1024]; FILE *f; sprintf (fn, "comm-%03d.svg", rk); f = fopen (fn, "w"); fprintf (f, "\n<g style=\"stroke-width:0.01; stroke:black; " \ "fill:none\">\n"); fclose (f); } if (_verbose) { g_printerr ("%d: near/far traversal begin\n", rk); MPI_Barrier (MPI_COMM_WORLD); timer = g_timer_new (); } /* accumulate the point counts across the tree */ _do_upward_pass (tree); /* do some near/far traversal */ vsg_prtree2d_near_far_traversal (tree, (VsgPRTree2dFarInteractionFunc) _far, (VsgPRTree2dInteractionFunc) _near, &ret); /* accumulate from top to leaves */ vsg_prtree2d_traverse (tree, G_PRE_ORDER, (VsgPRTree2dFunc) _down, NULL); if (_verbose) { MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: near/far traversal ok elapsed=%f seconds\n", rk, g_timer_elapsed (timer, NULL)); g_timer_destroy (timer); } if (_do_write) { gchar fn[1024]; FILE *f; MPI_Barrier (MPI_COMM_WORLD); g_sprintf (fn, "prtree2parallel-%03d.txt", rk); f = fopen (fn, "w"); vsg_prtree2d_write (tree, f); fclose (f); _tree_write (tree, "prtree2parallel-"); } if (_do_write) { gchar fn[1024]; FILE *f; sprintf (fn, "comm-%03d.svg", rk); f = fopen (fn, "a"); fprintf (f, "</g>\n"); fclose (f); } if (_verbose) { gint near_count_sum, far_count_sum; MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: processor msg stats fw=%d bw=%d\n", rk, _fw_count, _bw_count); g_printerr ("%d: processor call stats near=%d far=%d\n", rk, _near_count, _far_count); MPI_Reduce (&_near_count, &near_count_sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Reduce (&_far_count, &far_count_sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); if (rk == 0) { g_printerr ("%d: mean call stats near=%f far=%f\n", rk, (1.*near_count_sum)/sz, (1.*far_count_sum)/sz); } } /* check correctness of results */ g_ptr_array_foreach (points, (GFunc) _check_pt_count, &_ref_count); /* destroy the points */ g_ptr_array_foreach (points, empty_array, NULL); g_ptr_array_free (points, TRUE); /* destroy the tree */ vsg_prtree2d_free (tree); if (nc_padding > 0) g_free (_nc_padding_buffer); MPI_Finalize (); return ret; }
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; }
int main (int argc, char **argv) { #ifdef VSG_HAVE_MPI VsgPRTreeParallelConfig pconfig = {{NULL,}}; #endif VsgVector3d lbound = {-TR, -TR, -TR}; VsgVector3d ubound = {TR, TR, TR}; VsgPRTree3d *prtree; AranSolver3d *solver; int ret = 0; GTimer *timer = NULL; #ifdef VSG_HAVE_MPI MPI_Init (&argc, &argv); MPI_Comm_size (MPI_COMM_WORLD, &sz); MPI_Comm_rank (MPI_COMM_WORLD, &rk); #endif aran_init(); parse_args (argc, argv); #ifdef VSG_HAVE_MPI pconfig.communicator = MPI_COMM_WORLD; pconfig.point = point_accum_vtable; aran_development3d_vtable_init (&pconfig.node_data, 0, order); #endif points = g_ptr_array_new (); if (check) { _cp_size = MAX (np, 128); check_points = g_malloc0 (_cp_size * sizeof (PointAccum)); } prtree = vsg_prtree3d_new_full (&lbound, &ubound, (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc, (VsgPoint3dDistFunc) vsg_vector3d_dist, (VsgRegion3dLocFunc) NULL, maxbox); solver = aran_solver3d_new (prtree, ARAN_TYPE_DEVELOPMENT3D, aran_development3d_new (0, order), (AranZeroFunc) aran_development3d_set_zero); #ifdef VSG_HAVE_MPI aran_solver3d_set_parallel (solver, &pconfig); #endif aran_solver3d_set_functions (solver, (AranParticle2ParticleFunc3d) p2p, (AranParticle2MultipoleFunc3d) p2m, m2m, m2l, l2l, (AranLocal2ParticleFunc3d) l2p); if (_hilbert) { /* configure for hilbert curve order traversal */ aran_solver3d_set_children_order_hilbert (solver); } _fill (solver); /* g_printerr ("ok depth = %d size = %d\n", */ /* aran_solver3d_depth (solver), */ /* aran_solver3d_point_count (solver)); */ if (_verbose) { g_printerr ("%d : solve begin\n", rk); #ifdef VSG_HAVE_MPI MPI_Barrier (MPI_COMM_WORLD); #endif timer = g_timer_new (); } aran_solver3d_solve (solver); if (_verbose) { #ifdef VSG_HAVE_MPI MPI_Barrier (MPI_COMM_WORLD); #endif g_printerr ("%d : solve ok elapsed=%f seconds\n", rk, g_timer_elapsed (timer, NULL)); g_timer_destroy (timer); } if (_write) { gchar fn[1024]; FILE *f; g_sprintf (fn, "tree%03d.txt", rk); f = fopen (fn, "w"); vsg_prtree3d_write (prtree, f); fclose (f); _tree_write (prtree, "solv"); _vtp_tree_write (solver, "solv"); } if (check) { gint i, j; if (sz == 1) { for (i=0; i<np; i ++) { PointAccum *pi = &check_points[i]; for (j=0; j<np; j ++) { if (j != i) { PointAccum *pj = &check_points[j]; p2p_one_way (pi, pj); } } } } else check_parallel_points (solver); aran_solver3d_foreach_point (solver, (GFunc) check_point_field, &ret); if (_verbose) g_printerr ("%d : max err = %e\n", rk, maxerr); g_free (check_points); } aran_solver3d_free (solver); #ifdef VSG_HAVE_MPI aran_development3d_vtable_clear (&pconfig.node_data); #endif g_ptr_array_free (points, TRUE); if (_load_file != NULL) g_free (_load_file); #ifdef VSG_HAVE_MPI MPI_Finalize (); #endif return ret; }
int main (int argc, char **argv) { #ifdef VSG_HAVE_MPI VsgPRTreeParallelConfig pconfig = {{NULL,}}; #endif VsgVector3d lbound = {-TR, -TR, -TR}; VsgVector3d ubound = {TR, TR, TR}; VsgPRTree3d *prtree; AranSolver3d *solver; int ret = 0; GTimer *timer = NULL; #ifdef VSG_HAVE_MPI MPI_Init (&argc, &argv); MPI_Comm_size (MPI_COMM_WORLD, &sz); MPI_Comm_rank (MPI_COMM_WORLD, &rk); #endif aran_init(); parse_args (argc, argv); #ifdef VSG_HAVE_MPI pconfig.communicator = MPI_COMM_WORLD; pconfig.point = point_accum_vtable; aran_development3d_vtable_init (&pconfig.node_data, 0, order); #endif /* points = g_ptr_array_new (); */ if (check) { _cp_size = MAX (np, 128); check_points = g_malloc0 (_cp_size * sizeof (PointAccum)); } prtree = vsg_prtree3d_new_full (&lbound, &ubound, (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc, (VsgPoint3dDistFunc) vsg_vector3d_dist, (VsgRegion3dLocFunc) NULL, maxbox); solver = aran_solver3d_new (prtree, ARAN_TYPE_DEVELOPMENT3D, aran_development3d_new (0, order), (AranZeroFunc) aran_development3d_set_zero); #ifdef VSG_HAVE_MPI aran_solver3d_set_parallel (solver, &pconfig); #endif if (virtual_maxbox != 0) aran_solver3d_set_nf_isleaf (solver, _nf_isleaf_virtual_maxbox, &virtual_maxbox); aran_solver3d_set_functions (solver, (AranParticle2ParticleFunc3d) p2p, (AranParticle2MultipoleFunc3d) p2m, m2m, m2l, l2l, (AranLocal2ParticleFunc3d) l2p); if (semifar_threshold < G_MAXUINT) { aran_solver3d_set_functions_full (solver, (AranParticle2ParticleFunc3d) p2p, (AranParticle2MultipoleFunc3d) p2m, m2m, m2l, l2l, (AranLocal2ParticleFunc3d) l2p, (AranParticle2LocalFunc3d) p2l, (AranMultipole2ParticleFunc3d) m2p, semifar_threshold); if (semifar_threshold == 0) { PointAccum p1 = {{0.1, 0.1, 0.1}, 0.1, {0., 0., 0.}, 0}; PointAccum p2 = {{-0.1, -0.1, -0.1}, 0.1, {0., 0., 0.}, 1}; /* compute operators timings to be able to compute optimal solver parameters */ aran_solver3d_profile_operators (solver, (AranParticleInitFunc3d) point_accum_clear_accum, &p1, &p2); /* alternatively, we could get timings from profile databases */ /* aran_profile_db_read_file ("./profiledb-newtonfield3.ini", NULL); */ /* aran_solver3d_db_profile_operators (solver, (gdouble) order); */ } } if (_hilbert) { /* configure for hilbert curve order traversal */ aran_solver3d_set_children_order_hilbert (solver); } if (_verbose) { g_printerr ("%d : fill begin\n", rk); g_printerr ("%d : memory peak1 count = %u\n", rk, getpeak(0)); #ifdef VSG_HAVE_MPI MPI_Barrier (MPI_COMM_WORLD); #endif timer = g_timer_new (); } _fill (solver); if (_verbose) { g_printerr ("%d : fill elapsed=%f seconds\n", rk, g_timer_elapsed (timer, NULL)); g_printerr ("%d : tree depth count = %d\n", rk, aran_solver3d_depth (solver)); g_printerr ("%d : particle count=%d\n", rk, aran_solver3d_point_count (solver)); g_timer_destroy (timer); /* g_mem_profile(); */ } if (_verbose) { g_printerr ("%d : solve begin\n", rk); g_printerr ("%d : memory peak2 count = %u\n", rk, getpeak(0)); #ifdef VSG_HAVE_MPI MPI_Barrier (MPI_COMM_WORLD); #endif timer = g_timer_new (); } aran_solver3d_solve (solver); if (_verbose) { #ifdef VSG_HAVE_MPI MPI_Barrier (MPI_COMM_WORLD); #endif g_printerr ("%d : solve ok elapsed=%f seconds\n", rk, g_timer_elapsed (timer, NULL)); g_printerr ("%d : memory peak3 count = %u\n", rk, getpeak(0)); g_timer_destroy (timer); { glong zero_count, p2p_count, p2m_count, m2m_count; glong m2l_count, l2l_count, l2p_count, p2l_count, m2p_count; glong p2p_remote_count, m2l_remote_count; aran_solver3d_get_stats (solver, &zero_count, &p2p_count, &p2m_count, &m2m_count, &m2l_count, &l2l_count, &l2p_count, &p2l_count, &m2p_count, &p2p_remote_count, &m2l_remote_count); g_printerr ("%d : zero count=%ld\n", rk, zero_count); g_printerr ("%d : p2p count=%ld\n", rk, p2p_count); g_printerr ("%d : p2p remote count=%ld\n", rk, p2p_remote_count); g_printerr ("%d : p2m count=%ld\n", rk, p2m_count); g_printerr ("%d : m2m count=%ld\n", rk, m2m_count); g_printerr ("%d : m2l count=%ld\n", rk, m2l_count); g_printerr ("%d : m2l remote count=%ld\n", rk, m2l_remote_count); g_printerr ("%d : l2l count=%ld\n", rk, l2l_count); g_printerr ("%d : l2p count=%ld\n", rk, l2p_count); g_printerr ("%d : p2l count=%ld\n", rk, p2l_count); g_printerr ("%d : m2p count=%ld\n", rk, m2p_count); } } if (_write) { gchar fn[1024]; FILE *f; g_sprintf (fn, "tree%03d.txt", rk); f = fopen (fn, "w"); vsg_prtree3d_write (prtree, f); fclose (f); _tree_write (prtree, "solv"); _vtp_tree_write (solver, "solv"); } if (_save_fma_filename != NULL) { FILE *file = fopen (_save_fma_filename, "w"); aran_solver3d_write_fma (solver, file); fclose (file); } if (check) { guint64 i, j; if (sz == 1) { for (i=0; i<np; i ++) { PointAccum *pi = &check_points[i]; for (j=0; j<np; j ++) { if (j != i) { PointAccum *pj = &check_points[j]; p2p_one_way (pi, pj); } } } } else check_parallel_points (solver); aran_solver3d_foreach_point (solver, (GFunc) check_point_field, &ret); if (_verbose) g_printerr ("%d : max err = %e\n", rk, maxerr); g_free (check_points); } aran_solver3d_free (solver); #ifdef VSG_HAVE_MPI aran_development3d_vtable_clear (&pconfig.node_data); #endif /* g_ptr_array_free (points, TRUE); */ if (_load_file != NULL) g_free (_load_file); #ifdef VSG_HAVE_MPI MPI_Finalize (); #endif return ret; }