static void check_all (sc_MPI_Comm mpicomm, p4est_connectivity_t * conn, const char *vtkname, unsigned crc_expected, unsigned gcrc_expected) { int mpiret; unsigned crc_computed, gcrc_computed; long long lsize[3], gsize[3]; size_t size_conn, size_p4est, size_ghost; p4est_t *p4est; p4est_nodes_t *nodes; p4est_ghost_t *ghost; P4EST_GLOBAL_STATISTICSF ("Testing configuration %s\n", vtkname); p4est = p4est_new_ext (mpicomm, conn, 0, 0, 0, 0, NULL, NULL); p4est_refine (p4est, 1, refine_fn, NULL); p4est_coarsen (p4est, 1, coarsen_fn, NULL); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); p4est_partition (p4est, 0, NULL); p4est_vtk_write_file (p4est, NULL, vtkname); crc_computed = p4est_checksum (p4est); P4EST_GLOBAL_STATISTICSF ("Forest checksum 0x%08x\n", crc_computed); if (p4est->mpisize == 2 && p4est->mpirank == 0) { SC_CHECK_ABORT (crc_computed == crc_expected, "Forest checksum mismatch"); } ghost = p4est_ghost_new (p4est, P4EST_CONNECT_FULL); /* compute total size of forest storage */ size_conn = p4est_connectivity_memory_used (conn); size_p4est = p4est_memory_used (p4est); size_ghost = p4est_ghost_memory_used (ghost); lsize[0] = (long long) size_conn; lsize[1] = (long long) size_p4est; lsize[2] = (long long) size_ghost; mpiret = sc_MPI_Reduce (lsize, gsize, 3, sc_MPI_LONG_LONG_INT, sc_MPI_SUM, 0, mpicomm); SC_CHECK_MPI (mpiret); P4EST_GLOBAL_INFOF ("Global byte sizes: %lld %lld %lld\n", gsize[0], gsize[1], gsize[2]); gcrc_computed = p4est_ghost_checksum (p4est, ghost); P4EST_GLOBAL_STATISTICSF ("Ghost checksum 0x%08x\n", gcrc_computed); if (p4est->mpisize == 2 && p4est->mpirank == 0) { SC_CHECK_ABORT (gcrc_computed == gcrc_expected, "Ghost checksum mismatch"); } nodes = p4est_nodes_new (p4est, ghost); p4est_nodes_destroy (nodes); p4est_ghost_destroy (ghost); p4est_destroy (p4est); p4est_connectivity_destroy (conn); }
int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int mpisize, mpirank; unsigned crc; #ifndef P4_TO_P8 size_t kz; int8_t l; p4est_quadrant_t *q; p4est_tree_t stree, *tree = &stree; #endif p4est_t *p4est; p4est_connectivity_t *connectivity; /* initialize MPI */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_size (mpicomm, &mpisize); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank); SC_CHECK_MPI (mpiret); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); #ifndef P4_TO_P8 connectivity = p4est_connectivity_new_star (); #else connectivity = p8est_connectivity_new_rotcubes (); #endif p4est = p4est_new_ext (mpicomm, connectivity, 0, 0, 0, 4, NULL, NULL); #ifndef P4_TO_P8 /* build empty tree */ sc_array_init (&tree->quadrants, sizeof (p4est_quadrant_t)); for (l = 0; l <= P4EST_MAXLEVEL; ++l) { tree->quadrants_per_level[l] = 0; } tree->maxlevel = 0; /* insert two quadrants */ sc_array_resize (&tree->quadrants, 4); q = p4est_quadrant_array_index (&tree->quadrants, 0); p4est_quadrant_set_morton (q, 3, 13); q = p4est_quadrant_array_index (&tree->quadrants, 1); p4est_quadrant_set_morton (q, 1, 1); q = p4est_quadrant_array_index (&tree->quadrants, 2); p4est_quadrant_set_morton (q, 1, 2); q = p4est_quadrant_array_index (&tree->quadrants, 3); p4est_quadrant_set_morton (q, 1, 3); for (kz = 0; kz < tree->quadrants.elem_count; ++kz) { q = p4est_quadrant_array_index (&tree->quadrants, kz); q->p.user_data = sc_mempool_alloc (p4est->user_data_pool); ++tree->quadrants_per_level[q->level]; tree->maxlevel = (int8_t) SC_MAX (tree->maxlevel, q->level); } /* balance the tree, print and destroy */ #if 0 p4est_balance_subtree (p4est, P4EST_CONNECT_FULL, 0, NULL); p4est_tree_print (SC_LP_INFO, tree); #endif for (kz = 0; kz < tree->quadrants.elem_count; ++kz) { q = p4est_quadrant_array_index (&tree->quadrants, kz); sc_mempool_free (p4est->user_data_pool, q->p.user_data); } sc_array_reset (&tree->quadrants); #endif /* !P4_TO_P8 */ /* check reset data function */ p4est_reset_data (p4est, 0, init_fn, NULL); p4est_reset_data (p4est, 0, NULL, NULL); /* refine and balance the forest */ SC_CHECK_ABORT (p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 1"); p4est_refine (p4est, 1, refine_fn, NULL); SC_CHECK_ABORT (!p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 2"); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); SC_CHECK_ABORT (p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 3"); /* check reset data function */ p4est_reset_data (p4est, 17, NULL, NULL); p4est_reset_data (p4est, 8, init_fn, NULL); /* checksum and partition */ crc = p4est_checksum (p4est); p4est_partition (p4est, 0, NULL); SC_CHECK_ABORT (p4est_checksum (p4est) == crc, "Partition"); SC_CHECK_ABORT (p4est_is_balanced (p4est, P4EST_CONNECT_FULL), "Balance 4"); /* check reset data function */ p4est_reset_data (p4est, 3, NULL, NULL); p4est_reset_data (p4est, 3, NULL, NULL); /* checksum and rebalance */ crc = p4est_checksum (p4est); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); SC_CHECK_ABORT (p4est_checksum (p4est) == crc, "Rebalance"); /* clean up and exit */ P4EST_ASSERT (p4est->user_data_pool->elem_count == (size_t) p4est->local_num_quadrants); p4est_destroy (p4est); p4est_connectivity_destroy (connectivity); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int size, rank; unsigned crcF, crcC; p4est_connectivity_t *connectivity; p4est_t *p4est; p4est_t *p4estF, *p4estC; #ifdef P4_TO_P8 unsigned crcE; p4est_t *p4estE; #endif /* initialize */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_size (mpicomm, &size); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpicomm, &rank); SC_CHECK_MPI (mpiret); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); /* create forest and refine */ #ifndef P4_TO_P8 connectivity = p4est_connectivity_new_star (); #else connectivity = p8est_connectivity_new_rotcubes (); #endif p4est = p4est_new_ext (mpicomm, connectivity, 0, 0, 0, 0, NULL, NULL); p4est_refine (p4est, 1, refine_fn, NULL); /* test face balance */ p4estF = p4est_copy (p4est, 0); #ifndef P4_TO_P8 p4est_balance (p4estF, P4EST_CONNECT_FACE, NULL); #else p4est_balance (p4estF, P8EST_CONNECT_FACE, NULL); #endif crcF = p4est_checksum (p4estF); P4EST_GLOBAL_INFOF ("Face balance with %lld quadrants and crc 0x%08x\n", (long long) p4estF->global_num_quadrants, crcF); #ifdef P4_TO_P8 /* test edge balance */ p4estE = p4est_copy (p4est, 1); p4est_balance (p4estF, P8EST_CONNECT_EDGE, NULL); p4est_balance (p4estE, P8EST_CONNECT_EDGE, NULL); crcE = p4est_checksum (p4estE); SC_CHECK_ABORT (crcE == p4est_checksum (p4estF), "mismatch A"); P4EST_GLOBAL_INFOF ("Edge balance with %lld quadrants and crc 0x%08x\n", (long long) p4estE->global_num_quadrants, crcE); #endif /* test corner balance */ p4estC = p4est_copy (p4est, 1); #ifndef P4_TO_P8 p4est_balance (p4estF, P4EST_CONNECT_CORNER, NULL); p4est_balance (p4estC, P4EST_CONNECT_CORNER, NULL); #else p4est_balance (p4estF, P8EST_CONNECT_CORNER, NULL); p4est_balance (p4estC, P8EST_CONNECT_CORNER, NULL); #endif crcC = p4est_checksum (p4estC); SC_CHECK_ABORT (crcC == p4est_checksum (p4estF), "mismatch B"); P4EST_GLOBAL_INFOF ("Corner balance with %lld quadrants and crc 0x%08x\n", (long long) p4estC->global_num_quadrants, crcC); /* destroy forests and connectivity */ p4est_destroy (p4est); p4est_destroy (p4estF); #ifdef P4_TO_P8 p4est_destroy (p4estE); #endif p4est_destroy (p4estC); p4est_connectivity_destroy (connectivity); /* clean up and exit */ sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
static void mesh_run (mpi_context_t * mpi, p4est_connectivity_t * connectivity, int uniform, int compute_tree_index, int compute_level_lists, p4est_connect_type_t mesh_btype) { int mpiret; unsigned crc; long local_used[4], global_used[4]; p4est_t *p4est; p4est_ghost_t *ghost; p4est_mesh_t *mesh; user_data_t *ghost_data; p4est = p4est_new (mpi->mpicomm, connectivity, sizeof (user_data_t), init_fn, NULL); if (!uniform) p4est_vtk_write_file (p4est, NULL, P4EST_STRING "_mesh_new"); /* refinement */ if (uniform) { p4est_refine (p4est, 1, refine_uniform, init_fn); } else { p4est_refine (p4est, 1, refine_normal, init_fn); p4est_vtk_write_file (p4est, NULL, P4EST_STRING "_mesh_refined"); } /* balance */ p4est_balance (p4est, P4EST_CONNECT_FULL, init_fn); if (!uniform) p4est_vtk_write_file (p4est, NULL, P4EST_STRING "_mesh_balanced"); /* partition */ p4est_partition (p4est, 0, NULL); if (!uniform) { p4est_vtk_write_file (p4est, NULL, P4EST_STRING "_mesh_partition"); } crc = p4est_checksum (p4est); /* print and verify forest checksum */ P4EST_GLOBAL_STATISTICSF ("Tree %s checksum 0x%08x\n", uniform ? "uniform" : "adapted", crc); /* create ghost layer and mesh */ ghost = p4est_ghost_new (p4est, P4EST_CONNECT_FULL); ghost_data = P4EST_ALLOC (user_data_t, ghost->ghosts.elem_count); p4est_ghost_exchange_data (p4est, ghost, ghost_data); mesh = p4est_mesh_new_ext (p4est, ghost, compute_tree_index, compute_level_lists, mesh_btype); test_mesh (p4est, ghost, mesh, compute_tree_index, compute_level_lists, mesh_btype, ghost_data, uniform); /* compute memory used */ local_used[0] = (long) p4est_connectivity_memory_used (p4est->connectivity); local_used[1] = (long) p4est_memory_used (p4est); local_used[2] = (long) p4est_ghost_memory_used (ghost); local_used[3] = (long) p4est_mesh_memory_used (mesh); mpiret = sc_MPI_Allreduce (local_used, global_used, 4, sc_MPI_LONG, sc_MPI_SUM, mpi->mpicomm); SC_CHECK_MPI (mpiret); P4EST_GLOBAL_PRODUCTIONF ("Total %s memory used %ld %ld %ld %ld\n", uniform ? "uniform" : "adapted", global_used[0], global_used[1], global_used[2], global_used[3]); /* destroy ghost layer and mesh */ P4EST_FREE (ghost_data); p4est_mesh_destroy (mesh); p4est_ghost_destroy (ghost); /* destroy the p4est structure */ p4est_destroy (p4est); }
static void test_loadsave (p4est_connectivity_t * connectivity, const char *prefix, sc_MPI_Comm mpicomm, int mpirank) { int mpiret, retval; unsigned csum, csum2; double elapsed, wtime; p4est_connectivity_t *conn2; p4est_t *p4est, *p4est2; sc_statinfo_t stats[STATS_COUNT]; char conn_name[BUFSIZ]; char p4est_name[BUFSIZ]; snprintf (conn_name, BUFSIZ, "%s.%s", prefix, P4EST_CONN_SUFFIX); snprintf (p4est_name, BUFSIZ, "%s.%s", prefix, P4EST_FOREST_SUFFIX); P4EST_GLOBAL_INFOF ("Using file names %s and %s\n", conn_name, p4est_name); p4est = p4est_new_ext (mpicomm, connectivity, 0, 0, 0, sizeof (int), init_fn, NULL); p4est_refine (p4est, 1, refine_fn, init_fn); test_deflate (p4est); /* save, synchronize, load connectivity and compare */ if (mpirank == 0) { retval = p4est_connectivity_save (conn_name, connectivity); SC_CHECK_ABORT (retval == 0, "connectivity_save failed"); } mpiret = sc_MPI_Barrier (mpicomm); SC_CHECK_MPI (mpiret); wtime = sc_MPI_Wtime (); conn2 = p4est_connectivity_load (conn_name, NULL); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_CONN_LOAD, elapsed, "conn load"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch A"); p4est_connectivity_destroy (conn2); /* save, synchronize, load p4est and compare */ wtime = sc_MPI_Wtime (); p4est_save (p4est_name, p4est, 1); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_SAVE1, elapsed, "p4est save 1"); wtime = sc_MPI_Wtime (); p4est2 = p4est_load (p4est_name, mpicomm, sizeof (int), 1, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_LOAD1a, elapsed, "p4est load 1a"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch Ba"); SC_CHECK_ABORT (p4est_is_equal (p4est, p4est2, 1), "load/save p4est mismatch Ba"); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); wtime = sc_MPI_Wtime (); p4est2 = p4est_load (p4est_name, mpicomm, 0, 0, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_LOAD1b, elapsed, "p4est load 1b"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch Bb"); SC_CHECK_ABORT (p4est_is_equal (p4est, p4est2, 0), "load/save p4est mismatch Bb"); test_deflate (p4est2); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); /* partition and balance */ p4est_partition (p4est, 0, NULL); p4est_balance (p4est, P4EST_CONNECT_FULL, init_fn); csum = p4est_checksum (p4est); sc_stats_set1 (stats + STATS_P4EST_ELEMS, (double) p4est->local_num_quadrants, "p4est elements"); /* save, synchronize, load p4est and compare */ wtime = sc_MPI_Wtime (); p4est_save (p4est_name, p4est, 0); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_SAVE2, elapsed, "p4est save 2"); wtime = sc_MPI_Wtime (); p4est2 = p4est_load (p4est_name, mpicomm, sizeof (int), 0, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_LOAD2, elapsed, "p4est load 2"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch C"); SC_CHECK_ABORT (p4est_is_equal (p4est, p4est2, 0), "load/save p4est mismatch C"); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); /* save, synchronize, load p4est and compare */ wtime = sc_MPI_Wtime (); p4est_save (p4est_name, p4est, 1); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_SAVE3, elapsed, "p4est save 3"); wtime = sc_MPI_Wtime (); p4est2 = p4est_load (p4est_name, mpicomm, sizeof (int), 0, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; sc_stats_set1 (stats + STATS_P4EST_LOAD3, elapsed, "p4est load 3"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch D"); SC_CHECK_ABORT (p4est_is_equal (p4est, p4est2, 0), "load/save p4est mismatch D"); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); /* Test autopartition load feature */ wtime = sc_MPI_Wtime (); p4est2 = p4est_load_ext (p4est_name, mpicomm, sizeof (int), 0, 1, 0, NULL, &conn2); elapsed = sc_MPI_Wtime () - wtime; csum2 = p4est_checksum (p4est2); sc_stats_set1 (stats + STATS_P4EST_LOAD4, elapsed, "p4est load 4"); SC_CHECK_ABORT (p4est_connectivity_is_equal (connectivity, conn2), "load/save connectivity mismatch E"); SC_CHECK_ABORT (mpirank != 0 || csum == csum2, "load/save p4est mismatch E"); p4est_destroy (p4est2); p4est_connectivity_destroy (conn2); /* destroy data structures */ p4est_destroy (p4est); /* compute and print timings */ sc_stats_compute (mpicomm, STATS_COUNT, stats); sc_stats_print (p4est_package_id, SC_LP_STATISTICS, STATS_COUNT, stats, 0, 1); }
int main (int argc, char **argv) { int rank; int num_procs; int mpiret; sc_MPI_Comm mpicomm; p4est_t *p4est, *copy; p4est_connectivity_t *connectivity; int i; p4est_topidx_t t; size_t qz; p4est_locidx_t num_quadrants_on_last; p4est_locidx_t *num_quadrants_in_proc; p4est_gloidx_t *pertree1, *pertree2; p4est_quadrant_t *quad; p4est_tree_t *tree; user_data_t *user_data; int64_t sum; unsigned crc; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_rank (mpicomm, &rank); SC_CHECK_MPI (mpiret); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); /* create connectivity and forest structures */ #ifdef P4_TO_P8 connectivity = p8est_connectivity_new_twocubes (); #else connectivity = p4est_connectivity_new_corner (); #endif p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0, sizeof (user_data_t), init_fn, NULL); pertree1 = P4EST_ALLOC (p4est_gloidx_t, p4est->connectivity->num_trees + 1); pertree2 = P4EST_ALLOC (p4est_gloidx_t, p4est->connectivity->num_trees + 1); num_procs = p4est->mpisize; num_quadrants_in_proc = P4EST_ALLOC (p4est_locidx_t, num_procs); /* refine and balance to make the number of elements interesting */ test_pertree (p4est, NULL, pertree1); p4est_refine (p4est, 1, refine_fn, init_fn); test_pertree (p4est, NULL, pertree1); /* Set an arbitrary partition. * * Since this is just a test we assume the global number of * quadrants will fit in an int32_t */ num_quadrants_on_last = (p4est_locidx_t) p4est->global_num_quadrants; for (i = 0; i < num_procs - 1; ++i) { num_quadrants_in_proc[i] = (p4est_locidx_t) i + 1; /* type ok */ num_quadrants_on_last -= (p4est_locidx_t) i + 1; /* type ok */ } num_quadrants_in_proc[num_procs - 1] = num_quadrants_on_last; SC_CHECK_ABORT (num_quadrants_on_last > 0, "Negative number of quadrants on the last processor"); /* Save a checksum of the original forest */ crc = p4est_checksum (p4est); /* partition the forest */ (void) p4est_partition_given (p4est, num_quadrants_in_proc); test_pertree (p4est, pertree1, pertree2); /* Double check that we didn't loose any quads */ SC_CHECK_ABORT (crc == p4est_checksum (p4est), "bad checksum, missing a quad"); /* count the actual number of quadrants per proc */ SC_CHECK_ABORT (num_quadrants_in_proc[rank] == p4est->local_num_quadrants, "partition failed, wrong number of quadrants"); /* check user data content */ for (t = p4est->first_local_tree; t <= p4est->last_local_tree; ++t) { tree = p4est_tree_array_index (p4est->trees, t); for (qz = 0; qz < tree->quadrants.elem_count; ++qz) { quad = p4est_quadrant_array_index (&tree->quadrants, qz); user_data = (user_data_t *) quad->p.user_data; sum = quad->x + quad->y + quad->level; SC_CHECK_ABORT (user_data->a == t, "bad user_data, a"); SC_CHECK_ABORT (user_data->sum == sum, "bad user_data, sum"); } } /* do a weighted partition with uniform weights */ p4est_partition (p4est, 0, weight_one); test_pertree (p4est, pertree1, pertree2); SC_CHECK_ABORT (crc == p4est_checksum (p4est), "bad checksum after uniformly weighted partition"); /* copy the p4est */ copy = p4est_copy (p4est, 1); SC_CHECK_ABORT (crc == p4est_checksum (copy), "bad checksum after copy"); /* do a weighted partition with many zero weights */ weight_counter = 0; weight_index = (rank == 1) ? 1342 : 0; p4est_partition (copy, 0, weight_once); test_pertree (copy, pertree1, pertree2); SC_CHECK_ABORT (crc == p4est_checksum (copy), "bad checksum after unevenly weighted partition 1"); /* do a weighted partition with many zero weights */ weight_counter = 0; weight_index = 0; p4est_partition (copy, 0, weight_once); test_pertree (copy, pertree1, pertree2); SC_CHECK_ABORT (crc == p4est_checksum (copy), "bad checksum after unevenly weighted partition 2"); /* do a weighted partition with many zero weights * * Since this is just a test we assume the local number of * quadrants will fit in an int */ weight_counter = 0; weight_index = (rank == num_procs - 1) ? ((int) copy->local_num_quadrants - 1) : 0; p4est_partition (copy, 0, weight_once); test_pertree (copy, pertree1, pertree2); SC_CHECK_ABORT (crc == p4est_checksum (copy), "bad checksum after unevenly weighted partition 3"); /* check user data content */ for (t = copy->first_local_tree; t <= copy->last_local_tree; ++t) { tree = p4est_tree_array_index (copy->trees, t); for (qz = 0; qz < tree->quadrants.elem_count; ++qz) { quad = p4est_quadrant_array_index (&tree->quadrants, qz); user_data = (user_data_t *) quad->p.user_data; sum = quad->x + quad->y + quad->level; SC_CHECK_ABORT (user_data->a == t, "bad user_data, a"); SC_CHECK_ABORT (user_data->sum == sum, "bad user_data, sum"); } } /* Add another test. Overwrites pertree1, pertree2 */ test_partition_circle (mpicomm, connectivity, pertree1, pertree2); /* clean up and exit */ P4EST_FREE (pertree1); P4EST_FREE (pertree2); P4EST_FREE (num_quadrants_in_proc); p4est_destroy (p4est); p4est_destroy (copy); p4est_connectivity_destroy (connectivity); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
static void test_partition_circle (sc_MPI_Comm mpicomm, p4est_connectivity_t * connectivity, p4est_gloidx_t * pertree1, p4est_gloidx_t * pertree2) { int i, j; int num_procs; int empty_proc1, empty_proc2; unsigned crc1, crc2; p4est_gloidx_t global_num; p4est_locidx_t *new_counts; p4est_t *p4est, *copy; /* Create a forest and make a copy */ circle_count = 0; p4est = p4est_new_ext (mpicomm, connectivity, 0, 3, 1, sizeof (int), circle_init, NULL); num_procs = p4est->mpisize; test_pertree (p4est, NULL, pertree1); global_num = p4est->global_num_quadrants; crc1 = p4est_checksum (p4est); copy = p4est_copy (p4est, 1); P4EST_ASSERT (p4est_checksum (copy) == crc1); new_counts = P4EST_ALLOC (p4est_locidx_t, num_procs); /* Partition with one empty processor */ if (num_procs > 1) { P4EST_GLOBAL_INFO ("First circle partition\n"); empty_proc1 = num_procs / 3; j = 0; for (i = 0; i < num_procs; ++i) { if (i == empty_proc1) { new_counts[i] = 0; } else { new_counts[i] = p4est_partition_cut_gloidx (global_num, j + 1, num_procs - 1) - p4est_partition_cut_gloidx (global_num, j, num_procs - 1); P4EST_ASSERT (new_counts[i] >= 0); ++j; } } P4EST_ASSERT (j == num_procs - 1); p4est_partition_given (p4est, new_counts); test_pertree (p4est, pertree1, pertree2); crc2 = p4est_checksum (p4est); SC_CHECK_ABORT (crc1 == crc2, "First checksum mismatch"); } /* Partition with two empty processors */ if (num_procs > 2) { P4EST_GLOBAL_INFO ("Second circle partition\n"); empty_proc1 = (2 * num_procs) / 3 - 2; empty_proc2 = (2 * num_procs) / 3; j = 0; for (i = 0; i < num_procs; ++i) { if (i == empty_proc1 || i == empty_proc2) { new_counts[i] = 0; } else { new_counts[i] = p4est_partition_cut_gloidx (global_num, j + 1, num_procs - 2) - p4est_partition_cut_gloidx (global_num, j, num_procs - 2); P4EST_ASSERT (new_counts[i] >= 0); ++j; } } P4EST_ASSERT (j == num_procs - 2); p4est_partition_given (p4est, new_counts); test_pertree (p4est, pertree1, pertree2); crc2 = p4est_checksum (p4est); SC_CHECK_ABORT (crc1 == crc2, "Second checksum mismatch"); } /* Uniform partition */ P4EST_GLOBAL_INFO ("Third circle partition\n"); p4est_partition (p4est, 0, NULL); test_pertree (p4est, pertree1, pertree2); crc2 = p4est_checksum (p4est); SC_CHECK_ABORT (crc1 == crc2, "Third checksum mismatch"); SC_CHECK_ABORT (p4est_is_equal (p4est, copy, 1), "Forest mismatch"); P4EST_FREE (new_counts); p4est_destroy (copy); p4est_destroy (p4est); }