Skip to content

Commit

Permalink
Merge branch 'feature-revision' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
cburstedde committed Sep 1, 2016
2 parents 6f629be + f6dec32 commit 78593e6
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 7 deletions.
58 changes: 57 additions & 1 deletion src/p4est.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,17 @@ p4est_qcoord_to_vertex (p4est_connectivity_t * connectivity,
size_t
p4est_memory_used (p4est_t * p4est)
{
const int mpisize = p4est->mpisize;
int mpisize;
size_t size;
p4est_topidx_t nt;
p4est_tree_t *tree;

/* do not assert p4est_is_valid since it is collective */
P4EST_ASSERT (p4est != NULL);
P4EST_ASSERT (p4est->connectivity != NULL);
P4EST_ASSERT (p4est->trees != NULL);

mpisize = p4est->mpisize;
size = sizeof (p4est_t) +
(mpisize + 1) * (sizeof (p4est_gloidx_t) + sizeof (p4est_quadrant_t));

Expand All @@ -163,13 +169,25 @@ p4est_memory_used (p4est_t * p4est)
}

if (p4est->data_size > 0) {
P4EST_ASSERT (p4est->user_data_pool != NULL);
size += sc_mempool_memory_used (p4est->user_data_pool);
}
P4EST_ASSERT (p4est->quadrant_pool != NULL);
size += sc_mempool_memory_used (p4est->quadrant_pool);

return size;
}

long
p4est_revision (p4est_t * p4est)
{
/* do not assert p4est_is_valid since it is collective */
P4EST_ASSERT (p4est != NULL);
P4EST_ASSERT (p4est->revision >= 0);

return p4est->revision;
}

p4est_t *
p4est_new (sc_MPI_Comm mpicomm, p4est_connectivity_t * connectivity,
size_t data_size, p4est_init_t init_fn, void *user_pointer)
Expand Down Expand Up @@ -467,6 +485,7 @@ p4est_new_ext (sc_MPI_Comm mpicomm, p4est_connectivity_t * connectivity,
P4EST_VERBOSEF ("total local quadrants %lld\n",
(long long) p4est->local_num_quadrants);

P4EST_ASSERT (p4est->revision == 0);
P4EST_ASSERT (p4est_is_valid (p4est));
p4est_log_indent_pop ();
P4EST_GLOBAL_PRODUCTIONF ("Done " P4EST_STRING
Expand Down Expand Up @@ -595,6 +614,9 @@ p4est_copy_ext (p4est_t * input, int copy_data, int duplicate_mpicomm)
memcpy (p4est->global_first_position, input->global_first_position,
(p4est->mpisize + 1) * sizeof (p4est_quadrant_t));

/* the copy starts with a revision count of zero */
p4est->revision = 0;

/* check for valid p4est and return */
P4EST_ASSERT (p4est_is_valid (p4est));

Expand Down Expand Up @@ -667,6 +689,7 @@ p4est_refine_ext (p4est_t * p4est, int refine_recursive, int allowed_level,
int firsttime;
int i, maxlevel;
p4est_topidx_t nt;
p4est_gloidx_t old_gnq;
size_t incount, current, restpos, movecount;
sc_list_t *list;
p4est_tree_t *tree;
Expand All @@ -692,6 +715,9 @@ p4est_refine_ext (p4est_t * p4est, int refine_recursive, int allowed_level,
P4EST_ASSERT (0 <= allowed_level && allowed_level <= P4EST_QMAXLEVEL);
P4EST_ASSERT (refine_fn != NULL);

/* remember input quadrant count; it will not decrease */
old_gnq = p4est->global_num_quadrants;

/*
q points to a quadrant that is an array member
qalloc is a quadrant that has been allocated through quadrant_pool
Expand Down Expand Up @@ -887,6 +913,10 @@ p4est_refine_ext (p4est_t * p4est, int refine_recursive, int allowed_level,

/* compute global number of quadrants */
p4est_comm_count_quadrants (p4est);
P4EST_ASSERT (p4est->global_num_quadrants >= old_gnq);
if (old_gnq != p4est->global_num_quadrants) {
++p4est->revision;
}

P4EST_ASSERT (p4est_is_valid (p4est));
p4est_log_indent_pop ();
Expand Down Expand Up @@ -918,6 +948,7 @@ p4est_coarsen_ext (p4est_t * p4est,
size_t window, start, length, cidz;
p4est_locidx_t num_quadrants, prev_offset;
p4est_topidx_t jt;
p4est_gloidx_t old_gnq;
p4est_tree_t *tree;
p4est_quadrant_t *c[P4EST_CHILDREN];
p4est_quadrant_t *cfirst, *clast;
Expand All @@ -931,6 +962,9 @@ p4est_coarsen_ext (p4est_t * p4est,
P4EST_ASSERT (p4est_is_valid (p4est));
P4EST_ASSERT (coarsen_fn != NULL);

/* remember input quadrant count; it will not increase */
old_gnq = p4est->global_num_quadrants;

P4EST_QUADRANT_INIT (&qtemp);

/* loop over all local trees */
Expand Down Expand Up @@ -1084,6 +1118,10 @@ p4est_coarsen_ext (p4est_t * p4est,

/* compute global number of quadrants */
p4est_comm_count_quadrants (p4est);
P4EST_ASSERT (p4est->global_num_quadrants <= old_gnq);
if (old_gnq != p4est->global_num_quadrants) {
++p4est->revision;
}

P4EST_ASSERT (p4est_is_valid (p4est));
p4est_log_indent_pop ();
Expand Down Expand Up @@ -1224,6 +1262,7 @@ p4est_balance_ext (p4est_t * p4est, p4est_connect_type_t btype,
p4est_topidx_t qtree, nt;
p4est_topidx_t first_tree, last_tree;
p4est_locidx_t skipped;
p4est_gloidx_t old_gnq;
p4est_balance_peer_t *peers, *peer;
p4est_tree_t *tree;
p4est_quadrant_t mylow, nextlow;
Expand Down Expand Up @@ -1294,6 +1333,9 @@ p4est_balance_ext (p4est_t * p4est, p4est_connect_type_t btype,
btype == P8EST_CONNECT_CORNER);
#endif

/* remember input quadrant count; it will not decrease */
old_gnq = p4est->global_num_quadrants;

#ifdef P4EST_ENABLE_DEBUG
data_pool_size = 0;
if (p4est->user_data_pool != NULL) {
Expand Down Expand Up @@ -2357,6 +2399,10 @@ p4est_balance_ext (p4est_t * p4est, p4est_connect_type_t btype,

/* compute global number of quadrants */
p4est_comm_count_quadrants (p4est);
P4EST_ASSERT (p4est->global_num_quadrants >= old_gnq);
if (old_gnq != p4est->global_num_quadrants) {
++p4est->revision;
}

/* some sanity checks */
P4EST_ASSERT ((p4est_locidx_t) all_outcount == p4est->local_num_quadrants);
Expand Down Expand Up @@ -2426,6 +2472,9 @@ p4est_partition_ext (p4est_t * p4est, int partition_for_coarsening,
/* this function does nothing in a serial setup */
if (p4est->mpisize == 1) {
P4EST_GLOBAL_PRODUCTION ("Done " P4EST_STRING "_partition no shipping\n");

/* in particular, there is no need to bumb the revision counter */
P4EST_ASSERT (global_shipped == 0);
return global_shipped;
}

Expand Down Expand Up @@ -2507,6 +2556,9 @@ p4est_partition_ext (p4est_t * p4est, int partition_for_coarsening,
p4est_log_indent_pop ();
P4EST_GLOBAL_PRODUCTION ("Done " P4EST_STRING
"_partition no shipping\n");

/* in particular, there is no need to bumb the revision counter */
P4EST_ASSERT (global_shipped == 0);
return global_shipped;
}

Expand Down Expand Up @@ -2709,6 +2761,10 @@ p4est_partition_ext (p4est_t * p4est, int partition_for_coarsening,

/* run the partition algorithm with proper quadrant counts */
global_shipped = p4est_partition_given (p4est, num_quadrants_in_proc);
if (global_shipped) {
/* the partition of the forest has changed somewhere */
++p4est->revision;
}
P4EST_FREE (num_quadrants_in_proc);

/* check validity of the p4est */
Expand Down
22 changes: 20 additions & 2 deletions src/p4est.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ typedef struct p4est
void *user_pointer; /**< convenience pointer for users,
never touched by p4est */

long revision; /**< Gets bumped on mesh change */
p4est_topidx_t first_local_tree; /**< 0-based index of first local
tree, must be -1 for an empty
processor */
Expand Down Expand Up @@ -166,14 +167,25 @@ typedef struct p4est
}
p4est_t;

/** Calculate memory usage of a forest structure.
/** Calculate local memory usage of a forest structure.
* Not collective. The memory used on the current rank is returned.
* The connectivity structure is not counted since it is not owned;
* use p4est_connectivity_memory_usage (p4est->connectivity).
* \param [in] p4est Forest structure.
* \param [in] p4est Valid forest structure.
* \return Memory used in bytes.
*/
size_t p4est_memory_used (p4est_t * p4est);

/** Return the revision counter of the forest.
* Not collective, even though the revision value is the same on all ranks.
* A newly created forest starts with a revision counter of zero.
* Every refine, coarsen, partition, and balance that actually changes the mesh
* increases the counter by one. Operations with no effect keep the old value.
* \param [in] p8est The forest must be valid.
* \return Non-negative number.
*/
long p4est_revision (p4est_t * p4est);

/** Callback function prototype to initialize the quadrant's user data.
* \param [in] p4est the forest
* \param [in] which_tree the tree containing \a quadrant
Expand Down Expand Up @@ -275,6 +287,7 @@ void p4est_destroy (p4est_t * p4est);
* \param [in] copy_data If true, data are copied.
* If false, data_size is set to 0.
* \return Returns a valid p4est that does not depend on the input.
* The revision counter of the copy is set to zero.
*/
p4est_t *p4est_copy (p4est_t * input, int copy_data);

Expand Down Expand Up @@ -373,6 +386,9 @@ unsigned p4est_checksum (p4est_t * p4est);
* header. This makes the file depend on mpisize. For changing this see
* p4est_save_ext() in p4est_extended.h.
*
* The revision counter is not saved to the file, since that would make files
* different that come from different revisions but store the same mesh.
*
* \param [in] filename Name of the file to write.
* \param [in] p4est Valid forest structure.
* \param [in] save_data If true, the element data is saved.
Expand All @@ -396,6 +412,8 @@ void p4est_save (const char *filename, p4est_t * p4est,
* that it was stored with. The defaults can be changed with p4est_load_ext()
* in p4est_extended.h.
*
* The revision counter of the loaded p4est is set to zero.
*
* \param [in] filename Name of the file to read.
* \param [in] mpicomm A valid MPI communicator.
* \param [in] data_size Size of data for each quadrant which can be
Expand Down
7 changes: 7 additions & 0 deletions src/p4est_algorithms.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ p4est_is_valid (p4est_t * p4est)
goto failtest;
}

/* make sure the revision counter is legitimate */
if (p4est->revision < 0) {
P4EST_NOTICE ("p4est invalid revision counter\n");
failed = 1;
goto failtest;
}

/* check last item of global partition */
if (!(p4est->global_first_position[num_procs].p.which_tree ==
p4est->connectivity->num_trees &&
Expand Down
1 change: 1 addition & 0 deletions src/p4est_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ p4est_inflate (sc_MPI_Comm mpicomm, p4est_connectivity_t * connectivity,
P4EST_VERBOSEF ("total local quadrants %lld\n",
(long long) p4est->local_num_quadrants);

P4EST_ASSERT (p4est->revision == 0);
P4EST_ASSERT (p4est_is_valid (p4est));
p4est_log_indent_pop ();
P4EST_GLOBAL_PRODUCTION ("Done " P4EST_STRING "_inflate\n");
Expand Down
3 changes: 2 additions & 1 deletion src/p4est_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sc_array_t *p4est_deflate_quadrants (p4est_t * p4est,
sc_array_t ** data);

/** Create a new p4est based on serialized data.
* Its revision counter is set to zero.
* See p4est.h and p4est_communication.h for more information on parameters.
* \param [in] mpicomm A valid MPI communicator.
* \param [in] connectivity This is the connectivity information that
Expand All @@ -55,7 +56,7 @@ sc_array_t *p4est_deflate_quadrants (p4est_t * p4est,
* The elem_size of this array informs data_size.
* Its elem_count equals the number of local quads.
* \param [in] user_pointer Assign to the user_pointer member of the p4est.
* \return The newly created p4est.
* \return The newly created p4est with a zero revision counter.
*/
p4est_t *p4est_inflate (sc_MPI_Comm mpicomm,
p4est_connectivity_t * connectivity,
Expand Down
1 change: 1 addition & 0 deletions src/p4est_to_p8est.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
/* functions in p4est */
#define p4est_qcoord_to_vertex p8est_qcoord_to_vertex
#define p4est_memory_used p8est_memory_used
#define p4est_revision p8est_revision
#define p4est_new p8est_new
#define p4est_destroy p8est_destroy
#define p4est_copy p8est_copy
Expand Down
22 changes: 20 additions & 2 deletions src/p8est.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ typedef struct p8est
void *user_pointer; /**< convenience pointer for users,
never touched by p4est */

long revision; /**< Gets bumped on mesh change */
p4est_topidx_t first_local_tree; /**< 0-based index of first local
tree, must be -1 for an empty
processor */
Expand Down Expand Up @@ -162,14 +163,25 @@ typedef struct p8est
}
p8est_t;

/** Calculate memory usage of a forest structure.
/** Calculate local memory usage of a forest structure.
* Not collective. The memory used on the current rank is returned.
* The connectivity structure is not counted since it is not owned;
* use p8est_connectivity_memory_usage (p8est->connectivity).
* \param [in] p8est Forest structure.
* \param [in] p8est Valid forest structure.
* \return Memory used in bytes.
*/
size_t p8est_memory_used (p8est_t * p8est);

/** Return the revision counter of the forest.
* Not collective, even though the revision value is the same on all ranks.
* A newly created forest starts with a revision counter of zero.
* Every refine, coarsen, partition, and balance that actually changes the mesh
* increases the counter by one. Operations with no effect keep the old value.
* \param [in] p8est The forest must be valid.
* \return Non-negative number.
*/
long p8est_revision (p8est_t * p8est);

/** Callback function prototype to initialize the quadrant's user data.
* \param [in] p8est the forest
* \param [in] which_tree the tree containing \a quadrant
Expand Down Expand Up @@ -272,6 +284,7 @@ void p8est_destroy (p8est_t * p8est);
* \param [in] copy_data If true, data are copied.
* If false, data_size is set to 0.
* \return Returns a valid p8est that does not depend on the input.
* The revision counter of the copy is set to zero.
*/
p8est_t *p8est_copy (p8est_t * input, int copy_data);

Expand Down Expand Up @@ -373,6 +386,9 @@ unsigned p8est_checksum (p8est_t * p8est);
* header. This makes the file depend on mpisize. For changing this see
* p8est_save_ext() in p8est_extended.h.
*
* The revision counter is not saved to the file, since that would make files
* different that come from different revisions but store the same mesh.
*
* \param [in] filename Name of the file to write.
* \param [in] p8est Valid forest structure.
* \param [in] save_data If true, the element data is saved.
Expand All @@ -396,6 +412,8 @@ void p8est_save (const char *filename, p8est_t * p8est,
* that it was stored with. The defaults can be changed with p8est_load_ext()
* in p8est_extended.h.
*
* The revision counter of the loaded p4est is set to zero.
*
* \param [in] filename Name of the file to read.
* \param [in] mpicomm A valid MPI communicator.
* \param [in] data_size Size of data for each quadrant which can be
Expand Down
3 changes: 2 additions & 1 deletion src/p8est_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sc_array_t *p8est_deflate_quadrants (p8est_t * p8est,
sc_array_t ** data);

/** Create a new p4est based on serialized data.
* Its revision counter is set to zero.
* See p8est.h and p8est_communication.h for more information on parameters.
* \param [in] mpicomm A valid MPI communicator.
* \param [in] connectivity This is the connectivity information that
Expand All @@ -55,7 +56,7 @@ sc_array_t *p8est_deflate_quadrants (p8est_t * p8est,
* The elem_size of this array informs data_size.
* Its elem_count equals the number of local quads.
* \param [in] user_pointer Assign to the user_pointer member of the p4est.
* \return The newly created p4est.
* \return The newly created p4est with a zero revision counter.
*/
p8est_t *p8est_inflate (sc_MPI_Comm mpicomm,
p8est_connectivity_t * connectivity,
Expand Down

0 comments on commit 78593e6

Please sign in to comment.