int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int size, rank; 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); (void) check_backward_compatibility (); check_int_types (); #ifndef P4_TO_P8 check_all (mpicomm, p4est_connectivity_new_unitsquare (), "test_unitsquare", 0xef45243bU, 0xbc5d0907U); check_all (mpicomm, p4est_connectivity_new_rotwrap (), "test_rotwrap2", 0x266d2739U, 0x29a31248U); check_all (mpicomm, p4est_connectivity_new_corner (), "test_corner", 0x9dad92ccU, 0x937b27afU); check_all (mpicomm, p4est_connectivity_new_moebius (), "test_moebius", 0xbbc10f7fU, 0x09b6319eU); check_all (mpicomm, p4est_connectivity_new_star (), "test_star", 0xfb28233fU, 0x8e8a32b3); #else check_all (mpicomm, p8est_connectivity_new_unitcube (), "test_unitcube", 0x2574801fU, 0x312559a7U); check_all (mpicomm, p8est_connectivity_new_periodic (), "test_periodic3", 0xdc7e8a93U, 0x0787ca2dU); check_all (mpicomm, p8est_connectivity_new_rotwrap (), "test_rotwrap", 0xa675888dU, 0x626cbe90U); check_all (mpicomm, p8est_connectivity_new_twocubes (), "test_twocubes", 0x7188978aU, 0x4124bcabU); check_all (mpicomm, p8est_connectivity_new_twowrap (), "test_twowrap", 0x8e3f994cU, 0x9dd49e94); check_all (mpicomm, p8est_connectivity_new_rotcubes (), "test_rotcubes", 0xc0e1b235U, 0x974af07a); check_all (mpicomm, p8est_connectivity_new_shell (), "test_shell", 0x558723a2U, 0x4dedf35eU); check_all (mpicomm, p8est_connectivity_new_brick (2, 3, 4, 0, 0, 1), "test_brick", 0x82174e14U, 0x211da6c5); #endif /* clean up and exit */ sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int sc_allgather (void *sendbuf, int sendcount, sc_MPI_Datatype sendtype, void *recvbuf, int recvcount, sc_MPI_Datatype recvtype, sc_MPI_Comm mpicomm) { int mpiret; int mpisize; int mpirank; size_t datasize; #ifdef SC_DEBUG size_t datasize2; #endif SC_ASSERT (sendcount >= 0 && recvcount >= 0); /* *INDENT-OFF* HORRIBLE indent bug */ datasize = (size_t) sendcount * sc_mpi_sizeof (sendtype); #ifdef SC_DEBUG datasize2 = (size_t) recvcount * sc_mpi_sizeof (recvtype); #endif /* *INDENT-ON* */ SC_ASSERT (datasize == datasize2); mpiret = sc_MPI_Comm_size (mpicomm, &mpisize); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank); SC_CHECK_MPI (mpiret); memcpy (((char *) recvbuf) + mpirank * datasize, sendbuf, datasize); sc_allgather_recursive (mpicomm, (char *) recvbuf, (int) datasize, mpisize, mpirank, mpirank); return sc_MPI_SUCCESS; }
void p6est_comm_parallel_env_get_info (p6est_t * p6est) { int mpiret; mpiret = sc_MPI_Comm_size (p6est->mpicomm, &(p6est->mpisize)); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (p6est->mpicomm, &(p6est->mpirank)); SC_CHECK_MPI (mpiret); }
void sc_srand (unsigned int seed) { int mpiret; int mpirank; mpiret = sc_MPI_Comm_rank (sc_MPI_COMM_WORLD, &mpirank); SC_CHECK_MPI (mpiret); /* mpirank + seed * large_prime */ srand ((unsigned int) mpirank + seed * 393919); }
void sc_srand_time () { int mpiret; int mpirank; mpiret = sc_MPI_Comm_rank (sc_MPI_COMM_WORLD, &mpirank); SC_CHECK_MPI (mpiret); /* time + mpirank * small_prime */ srand ((unsigned int) time (NULL) + mpirank * 353); }
int main (int argc, char **argv) { int mpirank, mpisize; int mpiret; sc_MPI_Comm mpicomm; p4est_t *p4est; p4est_connectivity_t *connectivity; 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); /* create connectivity and forest structures */ #ifdef P4_TO_P8 connectivity = p8est_connectivity_new_rotcubes (); #else connectivity = p4est_connectivity_new_star (); #endif p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0, 1, NULL, NULL); p4est_refine_ext (p4est, 1, P4EST_QMAXLEVEL, refine_fn, NULL, replace_fn); p4est_coarsen_ext (p4est, 1, 0, coarsen_fn, NULL, replace_fn); p4est_balance_ext (p4est, P4EST_CONNECT_FULL, NULL, replace_fn); 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) { int mpiret; int wrongusage; const char *usage; mpi_context_t mpi_context, *mpi = &mpi_context; p4est_connectivity_t *connectivity; simple_config_t config; /* initialize MPI and p4est internals */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpi->mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_size (mpi->mpicomm, &mpi->mpisize); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpi->mpicomm, &mpi->mpirank); SC_CHECK_MPI (mpiret); sc_init (mpi->mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); /* process command line arguments */ usage = "Arguments: <configuration> <level>\n Configuration can be any of\n" #ifndef P4_TO_P8 " unit|three|moebius|star|periodic|rotwrap|cubed|disk\n" #else " unit|periodic|rotwrap|twocubes|twowrap|rotcubes|shell|sphere\n" #endif " Level controls the maximum depth of refinement\n"; wrongusage = 0; config = P4EST_CONFIG_NULL; if (!wrongusage && argc != 3) { wrongusage = 1; } if (!wrongusage) { if (!strcmp (argv[1], "unit")) { #ifndef P4_TO_P8 config = P4EST_CONFIG_UNIT; #else config = P8EST_CONFIG_UNIT; #endif } #ifndef P4_TO_P8 else if (!strcmp (argv[1], "three")) { config = P4EST_CONFIG_THREE; } else if (!strcmp (argv[1], "moebius")) { config = P4EST_CONFIG_MOEBIUS; } else if (!strcmp (argv[1], "star")) { config = P4EST_CONFIG_STAR; } else if (!strcmp (argv[1], "periodic")) { config = P4EST_CONFIG_PERIODIC; } else if (!strcmp (argv[1], "rotwrap")) { config = P4EST_CONFIG_ROTWRAP; } else if (!strcmp (argv[1], "cubed")) { config = P4EST_CONFIG_CUBED; } else if (!strcmp (argv[1], "disk")) { config = P4EST_CONFIG_DISK; } #else else if (!strcmp (argv[1], "periodic")) { config = P8EST_CONFIG_PERIODIC; } else if (!strcmp (argv[1], "rotwrap")) { config = P8EST_CONFIG_ROTWRAP; } else if (!strcmp (argv[1], "twocubes")) { config = P8EST_CONFIG_TWOCUBES; } else if (!strcmp (argv[1], "twowrap")) { config = P8EST_CONFIG_TWOWRAP; } else if (!strcmp (argv[1], "rotcubes")) { config = P8EST_CONFIG_ROTCUBES; } else if (!strcmp (argv[1], "shell")) { config = P8EST_CONFIG_SHELL; } else if (!strcmp (argv[1], "sphere")) { config = P8EST_CONFIG_SPHERE; } #endif else { wrongusage = 1; } } if (wrongusage) { P4EST_GLOBAL_LERROR (usage); sc_abort_collective ("Usage error"); } /* assign variables based on configuration */ refine_level = atoi (argv[2]); /* create connectivity and forest structures */ if (0) { } #ifndef P4_TO_P8 else if (config == P4EST_CONFIG_THREE) { connectivity = p4est_connectivity_new_corner (); } else if (config == P4EST_CONFIG_MOEBIUS) { connectivity = p4est_connectivity_new_moebius (); } else if (config == P4EST_CONFIG_STAR) { connectivity = p4est_connectivity_new_star (); } else if (config == P4EST_CONFIG_PERIODIC) { connectivity = p4est_connectivity_new_periodic (); } else if (config == P4EST_CONFIG_ROTWRAP) { connectivity = p4est_connectivity_new_rotwrap (); } else if (config == P4EST_CONFIG_CUBED) { connectivity = p4est_connectivity_new_cubed (); } else if (config == P4EST_CONFIG_DISK) { connectivity = p4est_connectivity_new_disk (); } #else else if (config == P8EST_CONFIG_PERIODIC) { connectivity = p8est_connectivity_new_periodic (); } else if (config == P8EST_CONFIG_ROTWRAP) { connectivity = p8est_connectivity_new_rotwrap (); } else if (config == P8EST_CONFIG_TWOCUBES) { connectivity = p8est_connectivity_new_twocubes (); } else if (config == P8EST_CONFIG_TWOWRAP) { connectivity = p8est_connectivity_new_twowrap (); } else if (config == P8EST_CONFIG_ROTCUBES) { connectivity = p8est_connectivity_new_rotcubes (); } else if (config == P8EST_CONFIG_SHELL) { connectivity = p8est_connectivity_new_shell (); } else if (config == P8EST_CONFIG_SPHERE) { connectivity = p8est_connectivity_new_sphere (); } #endif else { #ifndef P4_TO_P8 connectivity = p4est_connectivity_new_unitsquare (); #else connectivity = p8est_connectivity_new_unitcube (); #endif } #if 0 /* hack test */ hack_test (mpi, connectivity); #else /* run mesh tests */ mesh_run (mpi, connectivity, 1, 0, 1, P4EST_CONNECT_FULL); mesh_run (mpi, connectivity, 0, 1, 0, P4EST_CONNECT_FULL); mesh_run (mpi, connectivity, 0, 0, 0, P4EST_CONNECT_FACE); mesh_run (mpi, connectivity, 1, 1, 1, P4EST_CONNECT_FACE); #endif /* clean up and exit */ p4est_connectivity_destroy (connectivity); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int p6est_profile_sync (p6est_profile_t * profile) { p4est_lnodes_t *lnodes = profile->lnodes; p4est_locidx_t nln = lnodes->num_local_nodes; sc_array_t lrview; p4est_lnodes_buffer_t *countbuf; sc_array_t *sharers; size_t zz, nsharers; int nleft; int8_t *recv, *send; int *array_of_indices; p4est_locidx_t recv_total; p4est_locidx_t *recv_offsets, recv_offset; p4est_locidx_t send_total; p4est_locidx_t *send_offsets, send_offset; p4est_locidx_t (*lr)[2]; sc_array_t *lc = profile->lnode_columns; sc_MPI_Request *recv_request, *send_request; sc_array_t *work; int any_change = 0; int any_global_change; int mpiret, mpirank; int evenodd = profile->evenodd; lr = (p4est_locidx_t (*)[2]) profile->lnode_ranges; sharers = lnodes->sharers; nsharers = sharers->elem_count; mpiret = sc_MPI_Comm_rank (lnodes->mpicomm, &mpirank); SC_CHECK_MPI (mpiret); sc_array_init_data (&lrview, lr, 2 * sizeof (p4est_locidx_t), nln); countbuf = p4est_lnodes_share_all_begin (&lrview, lnodes); send_offsets = P4EST_ALLOC (p4est_locidx_t, nsharers + 1); send_offset = 0; for (zz = 0; zz < nsharers; zz++) { p4est_lnodes_rank_t *sharer; sc_array_t *send_buf; size_t zy, nnodes; send_offsets[zz] = send_offset; sharer = p4est_lnodes_rank_array_index (sharers, zz); if (sharer->rank == mpirank) { continue; } send_buf = (sc_array_t *) sc_array_index (countbuf->send_buffers, zz); nnodes = sharer->shared_nodes.elem_count; P4EST_ASSERT (nnodes == send_buf->elem_count); P4EST_ASSERT (send_buf->elem_size == 2 * sizeof (p4est_locidx_t)); for (zy = 0; zy < nnodes; zy++) { p4est_locidx_t *lp = (p4est_locidx_t *) sc_array_index (send_buf, zy); P4EST_ASSERT (lp[0] >= 0); P4EST_ASSERT (lp[1] >= 0); send_offset += lp[1]; } } send_total = send_offsets[nsharers] = send_offset; p4est_lnodes_share_all_end (countbuf); recv_offsets = P4EST_ALLOC (p4est_locidx_t, nsharers + 1); recv_offset = 0; for (zz = 0; zz < nsharers; zz++) { p4est_lnodes_rank_t *sharer; sc_array_t *recv_buf; size_t zy, nnodes; recv_offsets[zz] = recv_offset; sharer = p4est_lnodes_rank_array_index (sharers, zz); if (sharer->rank == mpirank) { continue; } recv_buf = (sc_array_t *) sc_array_index (countbuf->recv_buffers, zz); nnodes = sharer->shared_nodes.elem_count; P4EST_ASSERT (nnodes == recv_buf->elem_count); P4EST_ASSERT (recv_buf->elem_size == 2 * sizeof (p4est_locidx_t)); for (zy = 0; zy < nnodes; zy++) { p4est_locidx_t *lp = (p4est_locidx_t *) sc_array_index (recv_buf, zy); P4EST_ASSERT (lp[0] >= 0); P4EST_ASSERT (lp[1] >= 0); recv_offset += lp[1]; } } recv_total = recv_offsets[nsharers] = recv_offset; recv = P4EST_ALLOC (int8_t, recv_total); recv_request = P4EST_ALLOC (sc_MPI_Request, nsharers); send = P4EST_ALLOC (int8_t, send_total); send_request = P4EST_ALLOC (sc_MPI_Request, nsharers); /* post receives */ nleft = 0; for (zz = 0; zz < nsharers; zz++) { p4est_lnodes_rank_t *sharer; int icount = recv_offsets[zz + 1] - recv_offsets[zz]; sharer = p4est_lnodes_rank_array_index (sharers, zz); if (sharer->rank == mpirank) { recv_request[zz] = sc_MPI_REQUEST_NULL; continue; } if (icount) { mpiret = sc_MPI_Irecv (recv + recv_offsets[zz], icount * sizeof (int8_t), sc_MPI_BYTE, sharer->rank, P6EST_COMM_BALANCE, lnodes->mpicomm, recv_request + zz); SC_CHECK_MPI (mpiret); nleft++; } else { recv_request[zz] = sc_MPI_REQUEST_NULL; } } /* post sends */ for (zz = 0; zz < nsharers; zz++) { p4est_lnodes_rank_t *sharer; size_t zy, nnodes; int icount; sc_array_t *shared_nodes; sharer = p4est_lnodes_rank_array_index (sharers, zz); if (sharer->rank == mpirank) { send_request[zz] = sc_MPI_REQUEST_NULL; continue; } shared_nodes = &sharer->shared_nodes; nnodes = shared_nodes->elem_count; icount = 0; for (zy = 0; zy < nnodes; zy++) { p4est_locidx_t nidx; int8_t *c; nidx = *((p4est_locidx_t *) sc_array_index (shared_nodes, zy)); if (lr[nidx][1]) { c = (int8_t *) sc_array_index (lc, lr[nidx][0]); memcpy (send + send_offsets[zz] + icount, c, lr[nidx][1] * sizeof (int8_t)); icount += lr[nidx][1]; } else { P4EST_ASSERT (!lr[nidx][0]); } } P4EST_ASSERT (icount == send_offsets[zz + 1] - send_offsets[zz]); if (icount) { mpiret = sc_MPI_Isend (send + send_offsets[zz], icount * sizeof (int8_t), sc_MPI_BYTE, sharer->rank, P6EST_COMM_BALANCE, lnodes->mpicomm, send_request + zz); SC_CHECK_MPI (mpiret); } else { send_request[zz] = sc_MPI_REQUEST_NULL; } } work = sc_array_new (sizeof (int8_t)); array_of_indices = P4EST_ALLOC (int, nsharers); while (nleft) { int outcount; int i; mpiret = sc_MPI_Waitsome (nsharers, recv_request, &outcount, array_of_indices, sc_MPI_STATUSES_IGNORE); SC_CHECK_MPI (mpiret); for (i = 0; i < outcount; i++) { p4est_lnodes_rank_t *sharer; size_t zy, nnode; sc_array_t *shared_nodes; sc_array_t *recv_buf; zz = array_of_indices[i]; sharer = p4est_lnodes_rank_array_index (sharers, zz); shared_nodes = &sharer->shared_nodes; recv_buf = (sc_array_t *) sc_array_index (countbuf->recv_buffers, zz); nnode = shared_nodes->elem_count; P4EST_ASSERT (nnode == recv_buf->elem_count); recv_offset = recv_offsets[zz]; for (zy = 0; zy < nnode; zy++) { p4est_locidx_t *lp; p4est_locidx_t nidx; sc_array_t oldview, newview; nidx = *((p4est_locidx_t *) sc_array_index (shared_nodes, zy)); lp = (p4est_locidx_t *) sc_array_index (recv_buf, zy); sc_array_init_view (&oldview, lc, lr[nidx][0], lr[nidx][1]); sc_array_init_data (&newview, recv + recv_offset, sizeof (int8_t), lp[1]); if (profile->ptype == P6EST_PROFILE_UNION) { p6est_profile_union (&oldview, &newview, work); if (work->elem_count > oldview.elem_count) { int8_t *c; any_change = 1; lr[nidx][0] = lc->elem_count; lr[nidx][1] = work->elem_count; profile->lnode_changed[evenodd][nidx] = 1; c = (int8_t *) sc_array_push_count (lc, work->elem_count); memcpy (c, work->array, work->elem_count * work->elem_size); } } else { p6est_profile_intersection (&oldview, &newview, work); P4EST_ASSERT (work->elem_count <= oldview.elem_count); if (work->elem_count < oldview.elem_count) { lr[nidx][1] = work->elem_count; memcpy (oldview.array, work->array, work->elem_count * work->elem_size); } } recv_offset += lp[1]; } P4EST_ASSERT (recv_offset == recv_offsets[zz + 1]); } nleft -= outcount; P4EST_ASSERT (nleft >= 0); } P4EST_FREE (array_of_indices); sc_array_destroy (work); p6est_profile_compress (profile); p4est_lnodes_buffer_destroy (countbuf); P4EST_FREE (recv_request); P4EST_FREE (recv_offsets); P4EST_FREE (recv); { mpiret = sc_MPI_Waitall (nsharers, send_request, sc_MPI_STATUSES_IGNORE); SC_CHECK_MPI (mpiret); P4EST_FREE (send_request); P4EST_FREE (send_offsets); P4EST_FREE (send); any_global_change = any_change; mpiret = sc_MPI_Allreduce (&any_change, &any_global_change, 1, sc_MPI_INT, sc_MPI_LOR, lnodes->mpicomm); SC_CHECK_MPI (mpiret); } return any_global_change; }
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; }
void sc_init (sc_MPI_Comm mpicomm, int catch_signals, int print_backtrace, sc_log_handler_t log_handler, int log_threshold) { int w; const char *trace_file_name; const char *trace_file_prio; sc_identifier = -1; sc_mpicomm = sc_MPI_COMM_NULL; sc_print_backtrace = print_backtrace; if (mpicomm != sc_MPI_COMM_NULL) { int mpiret; sc_mpicomm = mpicomm; mpiret = sc_MPI_Comm_rank (sc_mpicomm, &sc_identifier); SC_CHECK_MPI (mpiret); } sc_set_signal_handler (catch_signals); sc_package_id = sc_package_register (log_handler, log_threshold, "libsc", "The SC Library"); trace_file_name = getenv ("SC_TRACE_FILE"); if (trace_file_name != NULL) { char buffer[BUFSIZ]; if (sc_identifier >= 0) { snprintf (buffer, BUFSIZ, "%s.%d.log", trace_file_name, sc_identifier); } else { snprintf (buffer, BUFSIZ, "%s.log", trace_file_name); } SC_CHECK_ABORT (sc_trace_file == NULL, "Trace file not NULL"); sc_trace_file = fopen (buffer, "wb"); SC_CHECK_ABORT (sc_trace_file != NULL, "Trace file open"); trace_file_prio = getenv ("SC_TRACE_LP"); if (trace_file_prio != NULL) { if (!strcmp (trace_file_prio, "SC_LP_TRACE")) { sc_trace_prio = SC_LP_TRACE; } else if (!strcmp (trace_file_prio, "SC_LP_DEBUG")) { sc_trace_prio = SC_LP_DEBUG; } else if (!strcmp (trace_file_prio, "SC_LP_VERBOSE")) { sc_trace_prio = SC_LP_VERBOSE; } else if (!strcmp (trace_file_prio, "SC_LP_INFO")) { sc_trace_prio = SC_LP_INFO; } else if (!strcmp (trace_file_prio, "SC_LP_STATISTICS")) { sc_trace_prio = SC_LP_STATISTICS; } else if (!strcmp (trace_file_prio, "SC_LP_PRODUCTION")) { sc_trace_prio = SC_LP_PRODUCTION; } else if (!strcmp (trace_file_prio, "SC_LP_ESSENTIAL")) { sc_trace_prio = SC_LP_ESSENTIAL; } else if (!strcmp (trace_file_prio, "SC_LP_ERROR")) { sc_trace_prio = SC_LP_ERROR; } else { SC_ABORT ("Invalid trace priority"); } } } w = 24; SC_GLOBAL_ESSENTIALF ("This is %s\n", SC_PACKAGE_STRING); #if 0 SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "F77", SC_F77); SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "FFLAGS", SC_FFLAGS); #endif SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "CPP", SC_CPP); SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "CPPFLAGS", SC_CPPFLAGS); SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "CC", SC_CC); #if 0 SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "C_VERSION", SC_C_VERSION); #endif SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "CFLAGS", SC_CFLAGS); SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "LDFLAGS", SC_LDFLAGS); SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "LIBS", SC_LIBS); #if 0 SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "BLAS_LIBS", SC_BLAS_LIBS); SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "LAPACK_LIBS", SC_LAPACK_LIBS); SC_GLOBAL_PRODUCTIONF ("%-*s %s\n", w, "FLIBS", SC_FLIBS); #endif #if defined(SC_ENABLE_MPI) && defined(SC_ENABLE_MPICOMMSHARED) if (mpicomm != MPI_COMM_NULL) { int mpiret; MPI_Comm intranode, internode; /* compute the node comms by default */ sc_mpi_comm_attach_node_comms (mpicomm, 0); sc_mpi_comm_get_node_comms (mpicomm, &intranode, &internode); if (intranode == MPI_COMM_NULL) { SC_GLOBAL_STATISTICS ("No shared memory node communicators\n"); } else { int intrasize; mpiret = MPI_Comm_size (intranode, &intrasize); SC_CHECK_MPI (mpiret); SC_GLOBAL_STATISTICSF ("Shared memory node communicator size: %d\n", intrasize); } } #endif }
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; }
int main (int argc, char **argv) { int mpiret; int mpirank, mpisize; int i, j; char cvalue, cresult; int ivalue, iresult; unsigned short usvalue, usresult; long lvalue, lresult; float fvalue[3], fresult[3], fexpect[3]; double dvalue, dresult; sc_MPI_Comm mpicomm; 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); /* test allreduce int max */ ivalue = mpirank; sc_allreduce (&ivalue, &iresult, 1, sc_MPI_INT, sc_MPI_MAX, mpicomm); SC_CHECK_ABORT (iresult == mpisize - 1, "Allreduce mismatch"); /* test reduce float max */ fvalue[0] = (float) mpirank; fexpect[0] = (float) (mpisize - 1); fvalue[1] = (float) (mpirank % 9 - 4); fexpect[1] = (float) (mpisize >= 9 ? 4 : (mpisize - 1) % 9 - 4); fvalue[2] = (float) (mpirank % 6); fexpect[2] = (float) (mpisize >= 6 ? 5 : (mpisize - 1) % 6); for (i = 0; i < mpisize; ++i) { sc_reduce (fvalue, fresult, 3, sc_MPI_FLOAT, sc_MPI_MAX, i, mpicomm); if (i == mpirank) { for (j = 0; j < 3; ++j) { SC_CHECK_ABORTF (fresult[j] == fexpect[j], /* ok */ "Reduce mismatch in %d", j); } } } /* test allreduce char min */ cvalue = (char) (mpirank % 127); sc_allreduce (&cvalue, &cresult, 1, sc_MPI_CHAR, sc_MPI_MIN, mpicomm); SC_CHECK_ABORT (cresult == 0, "Allreduce mismatch"); /* test reduce unsigned short min */ usvalue = (unsigned short) (mpirank % 32767); for (i = 0; i < mpisize; ++i) { sc_reduce (&usvalue, &usresult, 1, sc_MPI_UNSIGNED_SHORT, sc_MPI_MIN, i, mpicomm); if (i == mpirank) { SC_CHECK_ABORT (usresult == 0, "Reduce mismatch"); } } /* test allreduce long sum */ lvalue = (long) mpirank; sc_allreduce (&lvalue, &lresult, 1, sc_MPI_LONG, sc_MPI_SUM, mpicomm); SC_CHECK_ABORT (lresult == ((long) (mpisize - 1)) * mpisize / 2, "Allreduce mismatch"); /* test reduce double sum */ dvalue = (double) mpirank; for (i = 0; i < mpisize; ++i) { sc_reduce (&dvalue, &dresult, 1, sc_MPI_DOUBLE, sc_MPI_SUM, i, mpicomm); if (i == mpirank) { SC_CHECK_ABORT (dresult == ((double) (mpisize - 1)) * mpisize / 2., /* ok */ "Reduce mismatch"); } } sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
/** The main function of the step1 example program. * * It creates a connectivity and forest, refines it, and writes a VTK file. */ int main (int argc, char **argv) { p4est_wrapper_t *p4estw; int refinement_list[2], refine_list_len; int mpi_rank, mpi_num_proc, mpiret; int num_nodes, num_elements; int *lnodes; // TODO: unable to pass dynamicaly alocated 2D array //double coordinates[][NUM_DIMS]; double coordinates[100][NUM_DIMS]; mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); sc_MPI_Comm mpicomm = sc_MPI_COMM_WORLD; sc_MPI_Comm_rank(mpicomm, &mpi_rank); sc_MPI_Comm_size(mpicomm, &mpi_num_proc); // so far all scenarios for 2 processors only assert(mpi_num_proc == 2); p4estw = p4estw_create(mpicomm); p4estw_refine_all(p4estw); p4estw_partition(p4estw); refinement_list[0] = refinement_list[1] = 0; if(SCENARIO == 1) { if(mpi_rank == 1) { refinement_list[0] = refinement_list[1] = 1; refine_list_len = 2; } } else if(SCENARIO == 2) { if(mpi_rank == 1) { refinement_list[0] = 1; refine_list_len = 1; } } else if((SCENARIO == 3) || (SCENARIO == 5)) { if(mpi_rank == 0) { refinement_list[1] = 1; refine_list_len = 1; } } if(SCENARIO != 4) p4estw_refine_selected(p4estw, refine_list_len, refinement_list); if(SCENARIO == 5) p4estw_partition(p4estw); p4estw_get_dimensions(p4estw, &num_elements, &num_nodes); lnodes = malloc(num_elements * NUM_ELEM_NODES * sizeof(int)); //coordinates = calloc(num_nodes * NUM_DIMS, sizeof *coordinates); p4estw_get_data(p4estw, lnodes, coordinates); p4estw_destroy(p4estw); print_my_structures(p4estw, coordinates); /* Verify that allocations internal to p4est and sc do not leak memory. * This should be called if sc_init () has been called earlier. */ sc_finalize (); /* This is standard MPI programs. Without --enable-mpi, this is a dummy. */ mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
void problem_init ( int argc, char* argv [], p4est_t* p4est, p4est_geometry_t* p4est_geom, dgmath_jit_dbase_t* dgmath_jit_dbase, int proc_size, sc_MPI_Comm mpicomm, int load_from_checkpoint ) { mpi_assert((P4EST_DIM) == 2 || (P4EST_DIM) == 3); int world_rank, world_size; sc_MPI_Comm_rank(sc_MPI_COMM_WORLD, &world_rank); sc_MPI_Comm_size(sc_MPI_COMM_WORLD, &world_size); double* Au = P4EST_ALLOC_ZERO(double, 1); double* rhs = P4EST_ALLOC_ZERO(double, 1); double* u = P4EST_ALLOC_ZERO(double, 1); double* f = P4EST_ALLOC_ZERO(double, 1); double* u_analytic = P4EST_ALLOC_ZERO(double, 1); int local_nodes = 1; problem_input_t input = problem_input("options.input"); int endlevel = input.endlevel; int degree = input.degree; ip_flux_params_t ip_flux_params; ip_flux_params.ip_flux_penalty_prefactor = input.ip_flux_penalty; ip_flux_params.ip_flux_penalty_calculate_fcn = sipg_flux_vector_calc_penalty_maxp2_over_minh; p4est_ghost_t* ghost = p4est_ghost_new (p4est, P4EST_CONNECT_FACE); /* create space for storing the ghost data */ element_data_t* ghost_data = P4EST_ALLOC (element_data_t, ghost->ghosts.elem_count); p4est_partition(p4est, 0, NULL); p4est_balance (p4est, P4EST_CONNECT_FACE, NULL); grid_fcn_t boundary_flux_fcn = zero_fcn; problem_data_t prob_vecs; prob_vecs.rhs = rhs; prob_vecs.Au = Au; prob_vecs.u = u; prob_vecs.f = f; prob_vecs.local_nodes = local_nodes; for (int level = 0; level < endlevel; ++level){ if (level != 0){ p4est_refine_ext(p4est, 0, -1, refine_function, NULL, NULL ); p4est_balance_ext ( p4est, P4EST_CONNECT_FACE, NULL, NULL ); p4est_ghost_destroy(ghost); P4EST_FREE(ghost_data); ghost = p4est_ghost_new(p4est, P4EST_CONNECT_FACE); ghost_data = P4EST_ALLOC(element_data_t, ghost->ghosts.elem_count); } } p4est_partition(p4est, 1, NULL); p4est_balance_ext ( p4est, P4EST_CONNECT_FACE, NULL, NULL ); p4est_ghost_destroy(ghost); P4EST_FREE(ghost_data); ghost = p4est_ghost_new(p4est, P4EST_CONNECT_FACE); ghost_data = P4EST_ALLOC(element_data_t, ghost->ghosts.elem_count); weakeqn_ptrs_t prob_fcns; prob_fcns.apply_lhs = problem_apply_aij; element_data_init(p4est, degree); local_nodes = element_data_get_local_nodes(p4est); printf("RANK %d: Nodes = %d\n", world_rank, local_nodes); Au = P4EST_REALLOC(Au, double, local_nodes); u = P4EST_REALLOC(u, double, local_nodes); f = P4EST_REALLOC(f, double, local_nodes); rhs = P4EST_REALLOC(rhs, double, local_nodes); u_analytic = P4EST_REALLOC(u_analytic, double, local_nodes); prob_vecs.Au = Au; prob_vecs.u = u; prob_vecs.f = f; prob_vecs.rhs = rhs; prob_vecs.local_nodes = local_nodes; linalg_fill_vec(u, 0., local_nodes); element_data_init_node_vec(p4est,f,f_fcn,dgmath_jit_dbase); prob_vecs.vector_flux_fcn_data = sipg_flux_vector_dirichlet_fetch_fcns ( boundary_fcn, &ip_flux_params ); prob_vecs.scalar_flux_fcn_data = sipg_flux_scalar_dirichlet_fetch_fcns ( boundary_flux_fcn ); problem_build_rhs ( p4est, &prob_vecs, &prob_fcns, ghost, ghost_data, dgmath_jit_dbase ); clock_t begin = 0; clock_t end = -1; if (world_rank == 0){ begin = clock(); } int vcycle_iter = 3; double vcycle_rtol = 1e-3; double vcycle_atol = 0.; int smooth_iter = 8; int cg_eigs_iter = 10; double max_eig_factor = 1.1; int max_eig_reuse = 1; double lmax_lmin_rat = 30.; int coarse_iter = 100; double coarse_rtol = 1e-8; int save_vtk_snapshot = 0; int perform_checksum = 0; multigrid_data_t* mg_data = multigrid_data_init ( world_rank, endlevel, vcycle_iter, vcycle_rtol, vcycle_atol, smooth_iter, cg_eigs_iter, max_eig_factor, max_eig_reuse, lmax_lmin_rat, CG, coarse_iter, coarse_rtol, save_vtk_snapshot, perform_checksum, RES_AND_EIG_LOG, dgmath_jit_dbase ); multigrid_solve ( p4est, &prob_vecs, &prob_fcns, mg_data, &ghost, &ghost_data ); multigrid_data_destroy(mg_data); element_data_init_node_vec(p4est, u_analytic, analytic_solution_fcn, dgmath_jit_dbase); linalg_vec_axpy(-1., u, u_analytic, local_nodes); double local_l2_norm_sqr = element_data_compute_l2_norm_sqr_no_local ( p4est, u_analytic, dgmath_jit_dbase ); double local_nodes_dbl = (double)local_nodes; double local_reduce [2]; local_reduce[0] = local_nodes_dbl; local_reduce[1] = local_l2_norm_sqr; double global_reduce [2]; sc_reduce ( &local_reduce[0], &global_reduce[0], 2, sc_MPI_DOUBLE, sc_MPI_SUM, 0, sc_MPI_COMM_WORLD ); double global_nodes_dbl = global_reduce[0]; double global_l2_norm_sqr = global_reduce[1]; if (world_rank == 0){ end = clock(); double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printf ( "\n\n[HP_AMR]: %d %d %d %.25f %f \n\n", degree, (int)p4est->global_num_quadrants, (int)global_nodes_dbl, sqrt(global_l2_norm_sqr), /* info.iterations, */ /* info.residual_norm, */ time_spent ); } if (ghost) { p4est_ghost_destroy (ghost); P4EST_FREE (ghost_data); ghost = NULL; ghost_data = NULL; } P4EST_FREE(f); P4EST_FREE(Au); P4EST_FREE(rhs); P4EST_FREE(u_analytic); P4EST_FREE(u); }
int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int mpirank; int first_arg; const char *prefix; p4est_connectivity_t *connectivity; sc_options_t *opt; /* initialize MPI */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpicomm = sc_MPI_COMM_WORLD; mpiret = sc_MPI_Comm_rank (mpicomm, &mpirank); SC_CHECK_MPI (mpiret); /* initialize libsc and p4est */ sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); /* handle command line options */ opt = sc_options_new (argv[0]); sc_options_add_int (opt, 'l', "level", &refine_level, default_refine_level, "Refinement level"); sc_options_add_string (opt, 'o', "oprefix", &prefix, P4EST_STRING, "Output prefix"); first_arg = sc_options_parse (p4est_package_id, SC_LP_INFO, opt, argc, argv); SC_CHECK_ABORT (first_arg >= 0, "Option error"); /* create connectivity */ #ifndef P4_TO_P8 connectivity = p4est_connectivity_new_star (); #else connectivity = p8est_connectivity_new_rotcubes (); #endif /* test with vertex information */ test_loadsave (connectivity, prefix, mpicomm, mpirank); /* test without vertex information */ connectivity->num_vertices = 0; P4EST_FREE (connectivity->vertices); connectivity->vertices = NULL; P4EST_FREE (connectivity->tree_to_vertex); connectivity->tree_to_vertex = NULL; p4est_connectivity_set_attr (connectivity, 1); memset (connectivity->tree_to_attr, 0, connectivity->num_trees * sizeof (int8_t)); test_loadsave (connectivity, prefix, mpicomm, mpirank); /* clean up and exit */ p4est_connectivity_destroy (connectivity); sc_options_destroy (opt); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main (int argc, char **argv) { int rank; int mpiret; sc_MPI_Comm mpicomm; p4est_t *p4est; p4est_connectivity_t *connectivity; 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); p4est_init (NULL, SC_LP_DEFAULT); /* create connectivity and forest structures */ connectivity = p4est_connectivity_new_star (); p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0, sizeof (user_data_t), init_fn, NULL); /* refine to make the number of elements interesting */ p4est_refine (p4est, 1, refine_fn, init_fn); /* balance the forest */ p4est_balance (p4est, P4EST_CONNECT_FULL, init_fn); /* do a uniform partition, include the weight function for testing */ p4est_partition (p4est, 0, weight_one); p4est_check_local_order (p4est, connectivity); /* do a weighted partition with many zero weights */ weight_counter = 0; weight_index = (rank == 1) ? 1342 : 0; p4est_partition (p4est, 0, weight_once); p4est_check_local_order (p4est, connectivity); /* clean up */ p4est_destroy (p4est); p4est_connectivity_destroy (connectivity); /* create connectivity and forest structures */ connectivity = p4est_connectivity_new_periodic (); p4est = p4est_new_ext (mpicomm, connectivity, 15, 0, 0, sizeof (user_data_t), init_fn, NULL); /* refine to make the number of elements interesting */ p4est_refine (p4est, 1, refine_fn, init_fn); /* balance the forest */ p4est_balance (p4est, P4EST_CONNECT_FULL, init_fn); /* do a uniform partition, include the weight function for testing */ p4est_partition (p4est, 0, weight_one); p4est_check_local_order (p4est, connectivity); /* clean up and exit */ 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) { p4est_quadrant_t root; p4est_quadrant_t p; p4est_quadrant_t q; p4est_quadrant_t desc; int face, corner; #ifndef P4_TO_P8 int maxlevel = 9; #else int edge; int maxlevel = 6; #endif int mpiret, mpisize, mpirank; sc_MPI_Comm mpicomm; uint64_t i, ifirst, ilast; int level; sc_array_t *seeds, *seeds_check; int testval; int checkval; int j, nrand = 1000; /* 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); srandom (9212007); sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT); p4est_init (NULL, SC_LP_DEFAULT); seeds = sc_array_new (sizeof (p4est_quadrant_t)); seeds_check = sc_array_new (sizeof (p4est_quadrant_t)); memset (&root, 0, sizeof (p4est_quadrant_t)); root.level = 2; root.x = P4EST_QUADRANT_LEN (2); root.y = P4EST_QUADRANT_LEN (2); #ifdef P4_TO_P8 root.z = P4EST_QUADRANT_LEN (2); #endif P4EST_QUADRANT_INIT (&p); P4EST_QUADRANT_INIT (&q); #if 1 for (face = 0; face < P4EST_FACES; face++) { p4est_quadrant_face_neighbor (&root, face ^ 1, &p); P4EST_GLOBAL_VERBOSEF ("Testing face %d\n", face); for (level = 4; level <= maxlevel; level++) { P4EST_GLOBAL_VERBOSEF (" level %d\n", level); p4est_quadrant_first_descendant (&root, &desc, level); ifirst = p4est_quadrant_linear_id (&desc, level); p4est_quadrant_last_descendant (&root, &desc, level); ilast = p4est_quadrant_linear_id (&desc, level); for (i = ifirst; i <= ilast; i += P4EST_CHILDREN) { p4est_quadrant_set_morton (&q, level, i); #ifndef P4_TO_P8 testval = p4est_balance_seeds_face (&q, &p, face, P4EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P4EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p4est_balance_seeds_face error"); compare_seeds (seeds, seeds_check); #else testval = p4est_balance_seeds_face (&q, &p, face, P8EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_face error"); compare_seeds (seeds, seeds_check); testval = p4est_balance_seeds_face (&q, &p, face, P8EST_CONNECT_EDGE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_EDGE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_face error"); compare_seeds (seeds, seeds_check); #endif testval = p4est_balance_seeds_face (&q, &p, face, P4EST_CONNECT_FULL, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P4EST_CONNECT_FULL, seeds_check); SC_CHECK_ABORT (testval == checkval, "p4est_balance_seeds_face error"); compare_seeds (seeds, seeds_check); } } if (!face) { P4EST_GLOBAL_VERBOSE (" random levels\n"); for (j = 0; j < (int) nrand; j++) { level = ((random ()) % (P4EST_QMAXLEVEL - maxlevel)) + maxlevel + 1; p4est_quadrant_first_descendant (&root, &desc, level); ifirst = p4est_quadrant_linear_id (&desc, level); p4est_quadrant_last_descendant (&root, &desc, level); ilast = p4est_quadrant_linear_id (&desc, level); i = ((random ()) % (ilast + 1 - ifirst)) + ifirst; p4est_quadrant_set_morton (&q, level, i); #ifndef P4_TO_P8 testval = p4est_balance_seeds_face (&q, &p, face, P4EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P4EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p4est_balance_seeds_face error"); compare_seeds (seeds, seeds_check); #else testval = p4est_balance_seeds_face (&q, &p, face, P8EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_face error"); compare_seeds (seeds, seeds_check); testval = p4est_balance_seeds_face (&q, &p, face, P8EST_CONNECT_EDGE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_EDGE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_face error"); compare_seeds (seeds, seeds_check); #endif testval = p4est_balance_seeds_face (&q, &p, face, P4EST_CONNECT_FULL, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P4EST_CONNECT_FULL, seeds_check); SC_CHECK_ABORT (testval == checkval, "p4est_balance_seeds_face error"); compare_seeds (seeds, seeds_check); } } } #ifdef P4_TO_P8 for (edge = 0; edge < P8EST_EDGES; edge++) { p8est_quadrant_edge_neighbor (&root, edge ^ 3, &p); P4EST_GLOBAL_VERBOSEF ("Testing edge %d\n", edge); for (level = 4; level <= maxlevel; level++) { P4EST_GLOBAL_VERBOSEF (" level %d\n", level); p4est_quadrant_first_descendant (&root, &desc, level); ifirst = p4est_quadrant_linear_id (&desc, level); p4est_quadrant_last_descendant (&root, &desc, level); ilast = p4est_quadrant_linear_id (&desc, level); for (i = ifirst; i <= ilast; i += P4EST_CHILDREN) { p4est_quadrant_set_morton (&q, level, i); testval = p8est_balance_seeds_edge (&q, &p, edge, P8EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_edge error"); compare_seeds (seeds, seeds_check); testval = p8est_balance_seeds_edge (&q, &p, edge, P8EST_CONNECT_EDGE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_EDGE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_edge error"); compare_seeds (seeds, seeds_check); testval = p8est_balance_seeds_edge (&q, &p, edge, P8EST_CONNECT_FULL, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_FULL, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_edge error"); compare_seeds (seeds, seeds_check); } } if (!edge) { P4EST_GLOBAL_VERBOSE (" random levels\n"); for (j = 0; j < (int) nrand; j++) { level = ((random ()) % (P4EST_QMAXLEVEL - maxlevel)) + maxlevel + 1; p4est_quadrant_first_descendant (&root, &desc, level); ifirst = p4est_quadrant_linear_id (&desc, level); p4est_quadrant_last_descendant (&root, &desc, level); ilast = p4est_quadrant_linear_id (&desc, level); i = ((random ()) % (ilast + 1 - ifirst)) + ifirst; p4est_quadrant_set_morton (&q, level, i); testval = p8est_balance_seeds_edge (&q, &p, edge, P8EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_edge error"); compare_seeds (seeds, seeds_check); testval = p8est_balance_seeds_edge (&q, &p, edge, P8EST_CONNECT_EDGE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_EDGE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_edge error"); compare_seeds (seeds, seeds_check); testval = p8est_balance_seeds_edge (&q, &p, edge, P8EST_CONNECT_FULL, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_FULL, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_edge error"); compare_seeds (seeds, seeds_check); } } } #endif #endif for (corner = 0; corner < P4EST_FACES; corner++) { p4est_quadrant_corner_neighbor (&root, corner ^ (P4EST_CHILDREN - 1), &p); P4EST_GLOBAL_VERBOSEF ("Testing corner %d\n", corner); for (level = 4; level <= maxlevel; level++) { P4EST_GLOBAL_VERBOSEF (" level %d\n", level); p4est_quadrant_first_descendant (&root, &desc, level); ifirst = p4est_quadrant_linear_id (&desc, level); p4est_quadrant_last_descendant (&root, &desc, level); ilast = p4est_quadrant_linear_id (&desc, level); for (i = ifirst; i <= ilast; i += P4EST_CHILDREN) { p4est_quadrant_set_morton (&q, level, i); #ifndef P4_TO_P8 testval = p4est_balance_seeds_corner (&q, &p, corner, P4EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P4EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p4est_balance_seeds_corner error"); compare_seeds (seeds, seeds_check); #else testval = p4est_balance_seeds_corner (&q, &p, corner, P8EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_corner error"); compare_seeds (seeds, seeds_check); testval = p4est_balance_seeds_corner (&q, &p, corner, P8EST_CONNECT_EDGE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_EDGE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_corner error"); compare_seeds (seeds, seeds_check); #endif testval = p4est_balance_seeds_corner (&q, &p, corner, P4EST_CONNECT_FULL, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P4EST_CONNECT_FULL, seeds_check); SC_CHECK_ABORT (testval == checkval, "p4est_balance_seeds_corner error"); compare_seeds (seeds, seeds_check); } } if (!corner) { P4EST_GLOBAL_VERBOSE (" random levels\n"); for (j = 0; j < (int) nrand; j++) { level = ((random ()) % (P4EST_QMAXLEVEL - maxlevel)) + maxlevel + 1; p4est_quadrant_first_descendant (&root, &desc, level); ifirst = p4est_quadrant_linear_id (&desc, level); p4est_quadrant_last_descendant (&root, &desc, level); ilast = p4est_quadrant_linear_id (&desc, level); i = ((random ()) % (ilast + 1 - ifirst)) + ifirst; p4est_quadrant_set_morton (&q, level, i); #ifndef P4_TO_P8 testval = p4est_balance_seeds_corner (&q, &p, corner, P4EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P4EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p4est_balance_seeds_corner error"); compare_seeds (seeds, seeds_check); #else testval = p4est_balance_seeds_corner (&q, &p, corner, P8EST_CONNECT_FACE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_FACE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_corner error"); compare_seeds (seeds, seeds_check); testval = p4est_balance_seeds_corner (&q, &p, corner, P8EST_CONNECT_EDGE, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P8EST_CONNECT_EDGE, seeds_check); SC_CHECK_ABORT (testval == checkval, "p8est_balance_seeds_corner error"); compare_seeds (seeds, seeds_check); #endif testval = p4est_balance_seeds_corner (&q, &p, corner, P4EST_CONNECT_FULL, seeds); standard_seeds (seeds); checkval = check_balance_seeds (&q, &p, P4EST_CONNECT_FULL, seeds_check); SC_CHECK_ABORT (testval == checkval, "p4est_balance_seeds_corner error"); compare_seeds (seeds, seeds_check); } } } sc_array_destroy (seeds); sc_array_destroy (seeds_check); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
int main(int argc, char *argv[]) { int mpiret; sc_MPI_Comm mpicomm; int proc_size; p4est_connectivity_t *conn; p4est_geometry_t *geom; p4est_t* p4est; int seed = time(NULL); srand(seed); /* MPI init */ mpiret = sc_MPI_Init(&argc, &argv); SC_CHECK_MPI(mpiret); mpicomm = sc_MPI_COMM_WORLD; sc_init (mpicomm, 1, 1, NULL, SC_LP_ESSENTIAL); mpiret = MPI_Comm_size(mpicomm, &proc_size); SC_CHECK_MPI (mpiret); /* pXest init */ p4est_init(NULL, SC_LP_PRODUCTION); conn = p4est_connectivity_new_disk(); /* geom = p4est_geometry_new_connectivity(conn); */ geom = p4est_geometry_new_disk(conn,1.,2.); p4est = p4est_new_ext (mpicomm, conn, -1, 0, 1, sizeof(curved_element_data_t), NULL, NULL); int world_rank,world_size; sc_MPI_Comm_rank(sc_MPI_COMM_WORLD, &world_rank); sc_MPI_Comm_size(sc_MPI_COMM_WORLD, &world_size); /* start just-in-time dg-math */ dgmath_jit_dbase_t* dgmath_jit_dbase = dgmath_jit_dbase_init(); geometric_factors_t* geometric_factors = geometric_factors_init(p4est); curved_element_data_init(p4est, geometric_factors, dgmath_jit_dbase, geom, 4); /* int local_nodes = curved_element_data_get_local_nodes(p4est); */ /* double* u = P4EST_ALLOC(double, local_nodes); */ /* for (int i = 0; i < local_nodes; i++){ */ /* /\* u = x *\/ */ /* u[i] = geometric_factors->xyz[i]; */ /* } */ int num_of_refinements = 2; /* p4est_vtk_write_all */ /* (p4est, */ /* geom, */ /* 0.99, */ /* 1, */ /* 1, */ /* 1, */ /* 0, */ /* 0, */ /* 0, */ /* "disk0" */ /* ); */ for (int i = 0; i < num_of_refinements; i++){ p4est_refine_ext (p4est, 0, -1, random_h_refine, NULL, refine_uniform_replace_callback); p4est_balance_ext(p4est, P4EST_CONNECT_FACE, NULL, refine_uniform_replace_callback); /* p4est_vtk_write_all */ /* (p4est, */ /* geom, */ /* 0.99, */ /* 1, */ /* 1, */ /* 1, */ /* 0, */ /* 0, */ /* 0, */ /* "disk" */ /* ); */ } curved_element_data_init(p4est, geometric_factors, dgmath_jit_dbase, geom, -1); int local_nodes = curved_element_data_get_local_nodes(p4est); double* u = P4EST_ALLOC(double, local_nodes); for (int i = 0; i < local_nodes; i++){ /* u = x */ u[i] = geometric_factors->xyz[i]; } /* curved_element_data_init(p4est, geometric_factors, dgmath_jit_dbase, geom, -1); */ /* store vector */ curved_element_data_copy_from_vec_to_storage ( p4est, u ); test_curved_data_t test_curved_data; test_curved_data.mortar_err = 0.; test_curved_data.hanging_proj_err = 0.; test_curved_data.full_proj_err = 0.; test_curved_data.print_data = 1; test_curved_data.no_reorient = 0; test_curved_data.geom = geom; p4est_ghost_t* ghost = p4est_ghost_new (p4est, P4EST_CONNECT_FACE); /* create space for storing the ghost data */ curved_element_data_t* ghost_data = P4EST_ALLOC (curved_element_data_t, ghost->ghosts.elem_count); p4est_ghost_exchange_data (p4est, ghost, ghost_data); curved_compute_flux_user_data_t curved_compute_flux_user_data; curved_compute_flux_user_data.dgmath_jit_dbase = dgmath_jit_dbase; curved_flux_fcn_ptrs_t flux_fcns = (test_curved_data_fetch_fcns(&test_curved_data)); curved_compute_flux_user_data.flux_fcn_ptrs = &flux_fcns; p4est->user_pointer = &curved_compute_flux_user_data; p4est_iterate (p4est, ghost, (void *) ghost_data, NULL, curved_compute_flux_on_local_elements, #if (P4EST_DIM)==3 NULL, #endif NULL); test_curved_data.mortar_err = 0.; if (world_rank == 0) printf("mortar_err = %.20f\n", test_curved_data.mortar_err ); p4est_ghost_destroy (ghost); P4EST_FREE (ghost_data); ghost = NULL; ghost_data = NULL; /* curved_hp_amr(p4est, */ /* &u, */ /* test_nonconform_random_hp, */ /* NULL, */ /* NULL, */ /* NULL, */ /* dgmath_jit_dbase */ /* ); */ /* curved_element_data_init(p4est, geometric_factors, dgmath_jit_dbase, geom, -1); */ /* double* u_vertex = P4EST_ALLOC(double, p4est->local_num_quadrants*(P4EST_CHILDREN)); */ /* element_data_store_nodal_vec_in_vertex_array */ /* ( */ /* p4est, */ /* u, */ /* u_vertex */ /* ); */ /* char sol_save_as [500]; */ /* sprintf(sol_save_as, "%s_test_nonconform_sym_level_%d_u", P4EST_STRING, i); */ /* curved_hacked_p4est_vtk_write_all */ /* (p4est, */ /* NULL, */ /* 0.99, */ /* 0, */ /* 1, */ /* 1, */ /* 0, */ /* 1, */ /* 0, */ /* sol_save_as, */ /* "u", */ /* u_vertex */ /* ); */ /* P4EST_FREE(u_vertex); */ /* ip_flux_params_t ip_flux_params; */ /* ip_flux_params.ip_flux_penalty_prefactor = atoi(argv[6]); */ /* ip_flux_params.ip_flux_penalty_calculate_fcn = sipg_flux_vector_calc_penalty_maxp2_over_minh; */ /* problem_data_t vecs; */ /* vecs.u = u; */ /* vecs.local_nodes = element_data_get_local_nodes(p4est); */ /* vecs.vector_flux_fcn_data = sipg_flux_vector_dirichlet_fetch_fcns */ /* ( */ /* zero_fcn, */ /* &ip_flux_params */ /* ); */ /* vecs.scalar_flux_fcn_data = sipg_flux_scalar_dirichlet_fetch_fcns(zero_fcn); */ /* weakeqn_ptrs_t fcns; */ /* fcns.apply_lhs = poisson_apply_aij; */ /* matrix_sym_tester */ /* ( */ /* p4est, */ /* &vecs, /\* only needed for # of nodes *\/ */ /* &fcns, */ /* .000000000000001, */ /* dgmath_jit_dbase, */ /* 0, */ /* 0 */ /* ); */ /* } */ P4EST_FREE(u); geometric_factors_destroy(geometric_factors); /* free pointers */ dgmath_jit_dbase_destroy(dgmath_jit_dbase); /* free pXest */ p4est_destroy(p4est); /* p4est_destroy(p4est); */ if (geom != NULL) { p4est_geometry_destroy (geom); } p4est_connectivity_destroy(conn); /* finalize mpi stuff */ sc_finalize(); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI(mpiret); }
int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int mpisize, mpirank; p4est_t *p4est; p4est_connectivity_t *conn; sc_array_t *points_per_dim, *cone_sizes, *cones, *cone_orientations, *coords, *children, *parents, *childids, *leaves, *remotes; p4est_locidx_t first_local_quad = -1; /* 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 conn = p4est_connectivity_new_moebius (); #else conn = p8est_connectivity_new_rotcubes (); #endif p4est = p4est_new_ext (mpicomm, conn, 0, 1, 1, 0, NULL, NULL); p4est_refine (p4est, 1, refine_fn, NULL); p4est_balance (p4est, P4EST_CONNECT_FULL, NULL); p4est_partition (p4est, 0, NULL); points_per_dim = sc_array_new (sizeof (p4est_locidx_t)); cone_sizes = sc_array_new (sizeof (p4est_locidx_t)); cones = sc_array_new (sizeof (p4est_locidx_t)); cone_orientations = sc_array_new (sizeof (p4est_locidx_t)); coords = sc_array_new (3 * sizeof (double)); children = sc_array_new (sizeof (p4est_locidx_t)); parents = sc_array_new (sizeof (p4est_locidx_t)); childids = sc_array_new (sizeof (p4est_locidx_t)); leaves = sc_array_new (sizeof (p4est_locidx_t)); remotes = sc_array_new (2 * sizeof (p4est_locidx_t)); p4est_get_plex_data (p4est, P4EST_CONNECT_FULL, (mpisize > 1) ? 2 : 0, &first_local_quad, points_per_dim, cone_sizes, cones, cone_orientations, coords, children, parents, childids, leaves, remotes); #ifdef P4EST_WITH_PETSC { PetscErrorCode ierr; DM plex, refTree; PetscInt pStart, pEnd; PetscSection parentSection; PetscSF pointSF; size_t zz, count; locidx_to_PetscInt (points_per_dim); locidx_to_PetscInt (cone_sizes); locidx_to_PetscInt (cones); locidx_to_PetscInt (cone_orientations); coords_double_to_PetscScalar (coords); locidx_to_PetscInt (children); locidx_to_PetscInt (parents); locidx_to_PetscInt (childids); locidx_to_PetscInt (leaves); locidx_pair_to_PetscSFNode (remotes); P4EST_GLOBAL_PRODUCTION ("Begin PETSc routines\n"); ierr = PetscInitialize (&argc, &argv, 0, help); CHKERRQ (ierr); ierr = DMPlexCreate (mpicomm, &plex); CHKERRQ (ierr); ierr = DMSetDimension (plex, P4EST_DIM); CHKERRQ (ierr); ierr = DMSetCoordinateDim (plex, 3); CHKERRQ (ierr); ierr = DMPlexCreateFromDAG (plex, P4EST_DIM, (PetscInt *) points_per_dim->array, (PetscInt *) cone_sizes->array, (PetscInt *) cones->array, (PetscInt *) cone_orientations->array, (PetscScalar *) coords->array); CHKERRQ (ierr); ierr = PetscSFCreate (mpicomm, &pointSF); CHKERRQ (ierr); ierr = DMPlexCreateDefaultReferenceTree (mpicomm, P4EST_DIM, PETSC_FALSE, &refTree); CHKERRQ (ierr); ierr = DMPlexSetReferenceTree (plex, refTree); CHKERRQ (ierr); ierr = DMDestroy (&refTree); CHKERRQ (ierr); ierr = PetscSectionCreate (mpicomm, &parentSection); CHKERRQ (ierr); ierr = DMPlexGetChart (plex, &pStart, &pEnd); CHKERRQ (ierr); ierr = PetscSectionSetChart (parentSection, pStart, pEnd); CHKERRQ (ierr); count = children->elem_count; for (zz = 0; zz < count; zz++) { PetscInt child = *((PetscInt *) sc_array_index (children, zz)); ierr = PetscSectionSetDof (parentSection, child, 1); CHKERRQ (ierr); } ierr = PetscSectionSetUp (parentSection); CHKERRQ (ierr); ierr = DMPlexSetTree (plex, parentSection, (PetscInt *) parents->array, (PetscInt *) childids->array); CHKERRQ (ierr); ierr = PetscSectionDestroy (&parentSection); CHKERRQ (ierr); ierr = PetscSFSetGraph (pointSF, pEnd - pStart, (PetscInt) leaves->elem_count, (PetscInt *) leaves->array, PETSC_COPY_VALUES, (PetscSFNode *) remotes->array, PETSC_COPY_VALUES); CHKERRQ (ierr); ierr = DMViewFromOptions (plex, NULL, "-dm_view"); CHKERRQ (ierr); /* TODO: test with rigid body modes as in plex ex3 */ ierr = DMDestroy (&plex); CHKERRQ (ierr); ierr = PetscFinalize (); P4EST_GLOBAL_PRODUCTION ("End PETSc routines\n"); } #endif sc_array_destroy (points_per_dim); sc_array_destroy (cone_sizes); sc_array_destroy (cones); sc_array_destroy (cone_orientations); sc_array_destroy (coords); sc_array_destroy (children); sc_array_destroy (parents); sc_array_destroy (childids); sc_array_destroy (leaves); sc_array_destroy (remotes); p4est_destroy (p4est); p4est_connectivity_destroy (conn); sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }
p4est_t * p4est_new_points (sc_MPI_Comm mpicomm, p4est_connectivity_t * connectivity, int maxlevel, p4est_quadrant_t * points, p4est_locidx_t num_points, p4est_locidx_t max_points, size_t data_size, p4est_init_t init_fn, void *user_pointer) { int mpiret; int num_procs, rank; int i, isizet; size_t lcount; size_t *nmemb; #ifdef P4EST_ENABLE_DEBUG size_t zz; #endif p4est_topidx_t jt, num_trees; p4est_topidx_t first_tree, last_tree, next_tree; p4est_quadrant_t *first_quad, *next_quad, *quad; p4est_quadrant_t a, b, c, f, l, n; p4est_tree_t *tree; p4est_t *p4est; p4est_points_state_t ppstate; P4EST_GLOBAL_PRODUCTIONF ("Into " P4EST_STRING "_new_points with max level %d max points %lld\n", maxlevel, (long long) max_points); p4est_log_indent_push (); P4EST_ASSERT (p4est_connectivity_is_valid (connectivity)); P4EST_ASSERT (max_points >= -1); /* retrieve MPI information */ mpiret = sc_MPI_Comm_size (mpicomm, &num_procs); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_rank (mpicomm, &rank); SC_CHECK_MPI (mpiret); /* This implementation runs in O(P/p * maxlevel) * with P the total number of points, p the number of processors. * Two optimizations are possible: * 1. At startup remove points that lead to duplicate quadrants. * 2. Use complete_region between successive points instead of * the call to refine. This should give O(N/p) * maxlevel * with N the total number of quadrants. */ /* parallel sort the incoming points */ lcount = (size_t) num_points; nmemb = P4EST_ALLOC_ZERO (size_t, num_procs); isizet = (int) sizeof (size_t); mpiret = sc_MPI_Allgather (&lcount, isizet, sc_MPI_BYTE, nmemb, isizet, sc_MPI_BYTE, mpicomm); SC_CHECK_MPI (mpiret); sc_psort (mpicomm, points, nmemb, sizeof (p4est_quadrant_t), p4est_quadrant_compare_piggy); P4EST_FREE (nmemb); #ifdef P4EST_ENABLE_DEBUG first_quad = points; for (zz = 1; zz < lcount; ++zz) { next_quad = points + zz; P4EST_ASSERT (p4est_quadrant_compare_piggy (first_quad, next_quad) <= 0); first_quad = next_quad; } #endif /* create the p4est */ p4est = P4EST_ALLOC_ZERO (p4est_t, 1); ppstate.points = points; ppstate.num_points = num_points; ppstate.max_points = max_points; ppstate.current = 0; ppstate.maxlevel = maxlevel; /* assign some data members */ p4est->data_size = 2 * sizeof (p4est_locidx_t); /* temporary */ p4est->user_pointer = &ppstate; p4est->connectivity = connectivity; num_trees = connectivity->num_trees; /* create parallel environment */ p4est_comm_parallel_env_create (p4est, mpicomm); /* allocate memory pools */ p4est->user_data_pool = sc_mempool_new (p4est->data_size); p4est->quadrant_pool = sc_mempool_new (sizeof (p4est_quadrant_t)); P4EST_GLOBAL_PRODUCTIONF ("New " P4EST_STRING " with %lld trees on %d processors\n", (long long) num_trees, num_procs); /* allocate trees */ p4est->trees = sc_array_new (sizeof (p4est_tree_t)); sc_array_resize (p4est->trees, num_trees); for (jt = 0; jt < num_trees; ++jt) { tree = p4est_tree_array_index (p4est->trees, jt); sc_array_init (&tree->quadrants, sizeof (p4est_quadrant_t)); P4EST_QUADRANT_INIT (&tree->first_desc); P4EST_QUADRANT_INIT (&tree->last_desc); tree->quadrants_offset = 0; for (i = 0; i <= P4EST_QMAXLEVEL; ++i) { tree->quadrants_per_level[i] = 0; } for (; i <= P4EST_MAXLEVEL; ++i) { tree->quadrants_per_level[i] = -1; } tree->maxlevel = 0; } p4est->local_num_quadrants = 0; p4est->global_num_quadrants = 0; /* create point based partition */ P4EST_QUADRANT_INIT (&f); p4est->global_first_position = P4EST_ALLOC_ZERO (p4est_quadrant_t, num_procs + 1); if (num_points == 0) { P4EST_VERBOSE ("Empty processor"); first_tree = p4est->first_local_tree = -1; first_quad = NULL; } else { /* we are probably not empty */ if (rank == 0) { first_tree = p4est->first_local_tree = 0; p4est_quadrant_set_morton (&f, maxlevel, 0); } else { first_tree = p4est->first_local_tree = points->p.which_tree; p4est_node_to_quadrant (points, maxlevel, &f); } first_quad = &f; } last_tree = p4est->last_local_tree = -2; p4est_comm_global_partition (p4est, first_quad); first_quad = p4est->global_first_position + rank; next_quad = p4est->global_first_position + (rank + 1); next_tree = next_quad->p.which_tree; if (first_tree >= 0 && p4est_quadrant_is_equal (first_quad, next_quad) && first_quad->p.which_tree == next_quad->p.which_tree) { /* if all our points are consumed by the next processor we are empty */ first_tree = p4est->first_local_tree = -1; } if (first_tree >= 0) { /* we are definitely not empty */ if (next_quad->x == 0 && next_quad->y == 0 #ifdef P4_TO_P8 && next_quad->z == 0 #endif ) { last_tree = p4est->last_local_tree = next_tree - 1; } else { last_tree = p4est->last_local_tree = next_tree; } P4EST_ASSERT (first_tree <= last_tree); } /* fill the local trees */ P4EST_QUADRANT_INIT (&a); P4EST_QUADRANT_INIT (&b); P4EST_QUADRANT_INIT (&c); P4EST_QUADRANT_INIT (&l); n = *next_quad; n.level = (int8_t) maxlevel; for (jt = first_tree; jt <= last_tree; ++jt) { int onlyone = 0; int includeb = 0; tree = p4est_tree_array_index (p4est->trees, jt); /* determine first local quadrant of this tree */ if (jt == first_tree) { a = *first_quad; a.level = (int8_t) maxlevel; first_quad = next_quad = NULL; /* free to use further down */ P4EST_ASSERT (p4est_quadrant_is_valid (&a)); } else { p4est_quadrant_set_morton (&a, maxlevel, 0); P4EST_ASSERT (jt < next_tree || p4est_quadrant_compare (&a, &n) < 0); } /* enlarge first local quadrant if possible */ if (jt < next_tree) { while (p4est_quadrant_child_id (&a) == 0 && a.level > 0) { p4est_quadrant_parent (&a, &a); } P4EST_ASSERT (jt == first_tree || a.level == 0); } else { for (c = a; p4est_quadrant_child_id (&c) == 0; a = c) { p4est_quadrant_parent (&c, &c); p4est_quadrant_last_descendant (&c, &l, maxlevel); if (p4est_quadrant_compare (&l, &n) >= 0) { break; } } P4EST_ASSERT (a.level > 0); P4EST_ASSERT ((p4est_quadrant_last_descendant (&a, &l, maxlevel), p4est_quadrant_compare (&l, &n) < 0)); } p4est_quadrant_first_descendant (&a, &tree->first_desc, P4EST_QMAXLEVEL); /* determine largest possible last quadrant of this tree */ if (jt < next_tree) { p4est_quadrant_last_descendant (&a, &l, maxlevel); p4est_quadrant_set_morton (&b, 0, 0); p4est_quadrant_last_descendant (&b, &b, maxlevel); if (p4est_quadrant_is_equal (&l, &b)) { onlyone = 1; } else { includeb = 1; for (c = b; p4est_quadrant_child_id (&c) == P4EST_CHILDREN - 1; b = c) { p4est_quadrant_parent (&c, &c); p4est_quadrant_first_descendant (&c, &f, maxlevel); if (p4est_quadrant_compare (&l, &f) >= 0) { break; } } } } else { b = n; } /* create a complete tree */ if (onlyone) { quad = p4est_quadrant_array_push (&tree->quadrants); *quad = a; p4est_quadrant_init_data (p4est, jt, quad, p4est_points_init); tree->maxlevel = a.level; ++tree->quadrants_per_level[a.level]; } else { p4est_complete_region (p4est, &a, 1, &b, includeb, tree, jt, p4est_points_init); quad = p4est_quadrant_array_index (&tree->quadrants, tree->quadrants.elem_count - 1); } tree->quadrants_offset = p4est->local_num_quadrants; p4est->local_num_quadrants += tree->quadrants.elem_count; p4est_quadrant_last_descendant (quad, &tree->last_desc, P4EST_QMAXLEVEL); /* verification */ #ifdef P4EST_ENABLE_DEBUG first_quad = p4est_quadrant_array_index (&tree->quadrants, 0); for (zz = 1; zz < tree->quadrants.elem_count; ++zz) { next_quad = p4est_quadrant_array_index (&tree->quadrants, zz); P4EST_ASSERT (((p4est_locidx_t *) first_quad->p.user_data)[1] == ((p4est_locidx_t *) next_quad->p.user_data)[0]); first_quad = next_quad; } #endif } if (last_tree >= 0) { for (; jt < num_trees; ++jt) { tree = p4est_tree_array_index (p4est->trees, jt); tree->quadrants_offset = p4est->local_num_quadrants; } } /* compute some member variables */ p4est->global_first_quadrant = P4EST_ALLOC (p4est_gloidx_t, num_procs + 1); p4est_comm_count_quadrants (p4est); /* print more statistics */ P4EST_VERBOSEF ("total local quadrants %lld\n", (long long) p4est->local_num_quadrants); P4EST_ASSERT (p4est_is_valid (p4est)); p4est_log_indent_pop (); P4EST_GLOBAL_PRODUCTIONF ("Done " P4EST_STRING "_new_points with %lld total quadrants\n", (long long) p4est->global_num_quadrants); /* refine to have one point per quadrant */ if (max_points >= 0) { p4est_refine_ext (p4est, 1, maxlevel, p4est_points_refine, p4est_points_init, NULL); #ifdef P4EST_ENABLE_DEBUG for (jt = first_tree; jt <= last_tree; ++jt) { tree = p4est_tree_array_index (p4est->trees, jt); first_quad = p4est_quadrant_array_index (&tree->quadrants, 0); for (zz = 1; zz < tree->quadrants.elem_count; ++zz) { next_quad = p4est_quadrant_array_index (&tree->quadrants, zz); P4EST_ASSERT (((p4est_locidx_t *) first_quad->p.user_data)[1] == ((p4est_locidx_t *) next_quad->p.user_data)[0]); first_quad = next_quad; } } #endif } /* initialize user pointer and data size */ p4est_reset_data (p4est, data_size, init_fn, user_pointer); return p4est; }
int main (int argc, char **argv) { sc_MPI_Comm mpicomm; int mpiret; int mpisize, mpirank; p4est_t *p4est; p4est_connectivity_t *connectivity; sc_dmatrix_t *vtkvec; p4est_tree_t *tree; sc_array_t *quadrants; size_t zz, count; p4est_quadrant_t *q; int i; #ifndef P4_TO_P8 char filename[] = "p4est_balance_face"; #else char filename[] = "p8est_balance_edge"; #endif p4est_vtk_context_t *context; sc_array_t *level; int retval; /* 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_unitsquare (); #else connectivity = p8est_connectivity_new_unitcube (); #endif p4est = p4est_new_ext (mpicomm, connectivity, 0, 2, 1, sizeof (balance_seeds_elem_t), init_fn, NULL); p4est_refine (p4est, 1, refine_fn, init_fn); context = p4est_vtk_context_new (p4est, filename); p4est_vtk_context_set_scale (context, 1. - 2. * SC_EPS); context = p4est_vtk_write_header (context); SC_CHECK_ABORT (context != NULL, P4EST_STRING "_vtk: Error writing header"); vtkvec = sc_dmatrix_new (p4est->local_num_quadrants, P4EST_CHILDREN); tree = p4est_tree_array_index (p4est->trees, 0); quadrants = &(tree->quadrants); count = quadrants->elem_count; for (zz = 0; zz < count; zz++) { q = p4est_quadrant_array_index (quadrants, zz); for (i = 0; i < P4EST_CHILDREN; i++) { vtkvec->e[zz][i] = (double) ((balance_seeds_elem_t *) (q->p.user_data))->flag; } } level = sc_array_new_data ((void *) vtkvec->e[0], sizeof (double), count * P4EST_CHILDREN); context = p4est_vtk_write_point_dataf (context, 1, 0, "level", level, context); SC_CHECK_ABORT (context != NULL, P4EST_STRING "_vtk: Error writing point data"); sc_array_destroy (level); retval = p4est_vtk_write_footer (context); SC_CHECK_ABORT (!retval, P4EST_STRING "_vtk: Error writing footer"); sc_dmatrix_destroy (vtkvec); 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 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; }
/* main */ int main (int argc, char **argv) { int rank, num_procs, mpiret, i; sc_MPI_Comm mpicomm = sc_MPI_COMM_WORLD; p4est_t *p4est_1tree, *p4est_ntrees; p4est_connectivity_t *connectivity_1tree, *connectivity_ntrees; /* initialize MPI and p4est internals */ mpiret = sc_MPI_Init (&argc, &argv); SC_CHECK_MPI (mpiret); mpiret = sc_MPI_Comm_size (mpicomm, &num_procs); 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 connectivity */ #ifdef P4_TO_P8 connectivity_1tree = p8est_connectivity_new_unitcube (); connectivity_ntrees = p8est_connectivity_new_twocubes (); #else connectivity_1tree = p4est_connectivity_new_unitsquare (); connectivity_ntrees = p4est_connectivity_new_corner (); #endif /* create p4est structure */ p4est_1tree = p4est_new_ext (mpicomm, connectivity_1tree, 15, 0, 0, sizeof (user_data_t), init_fn, NULL); p4est_ntrees = p4est_new_ext (mpicomm, connectivity_ntrees, 15, 0, 0, sizeof (user_data_t), init_fn, NULL); /* write output: new */ p4est_vtk_write_file (p4est_1tree, NULL, P4EST_STRING "_partition_corr_1tree_new"); p4est_vtk_write_file (p4est_ntrees, NULL, P4EST_STRING "_partition_corr_ntrees_new"); /* refine */ p4est_refine (p4est_1tree, 1, refine_fn, init_fn); p4est_refine (p4est_ntrees, 1, refine_fn, init_fn); /* write output: refined */ p4est_vtk_write_file (p4est_1tree, NULL, P4EST_STRING "_partition_corr_1tree_refined"); p4est_vtk_write_file (p4est_ntrees, NULL, P4EST_STRING "_partition_corr_ntrees_refined"); /* run partition and coarsen till one quadrant per tree remains */ i = 0; while (p4est_1tree->global_num_quadrants > 1 && i <= P4EST_MAXLEVEL) { (void) p4est_partition_ext (p4est_1tree, 1, NULL); p4est_coarsen (p4est_1tree, 0, coarsen_fn, init_fn); i++; } SC_CHECK_ABORT (p4est_1tree->global_num_quadrants == 1, "coarsest forest with one tree was not achieved"); i = 0; while (p4est_ntrees->global_num_quadrants > connectivity_ntrees->num_trees && i <= P4EST_MAXLEVEL) { (void) p4est_partition_ext (p4est_ntrees, 1, NULL); p4est_coarsen (p4est_ntrees, 0, coarsen_fn, init_fn); i++; } SC_CHECK_ABORT (p4est_ntrees->global_num_quadrants == connectivity_ntrees->num_trees, "coarsest forest with multiple trees was not achieved"); /* run partition on coarse forest (one quadrant per tree) once again */ (void) p4est_partition_ext (p4est_1tree, 1, NULL); (void) p4est_partition_ext (p4est_ntrees, 1, NULL); /* write output: coarsened */ p4est_vtk_write_file (p4est_1tree, NULL, P4EST_STRING "_partition_corr_1tree_coarsened"); p4est_vtk_write_file (p4est_ntrees, NULL, P4EST_STRING "_partition_corr_ntrees_coarsened"); /* destroy the p4est and its connectivity structure */ p4est_destroy (p4est_1tree); p4est_destroy (p4est_ntrees); p4est_connectivity_destroy (connectivity_1tree); p4est_connectivity_destroy (connectivity_ntrees); /* clean up and exit */ sc_finalize (); mpiret = sc_MPI_Finalize (); SC_CHECK_MPI (mpiret); return 0; }