Skip to content

Commit

Permalink
Test partition: surviving without ZLIB
Browse files Browse the repository at this point in the history
  • Loading branch information
cburstedde committed Dec 15, 2023
1 parent 9f30abf commit 7ea5b69
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions test/test_partition2.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,17 @@ test_pertree (p4est_t * p4est, const p4est_gloidx_t * prev_pertree,
p4est_search_partition (p4est, 1, traverse_fn, NULL, NULL);
}

static unsigned
test_checksum (p4est_t * p4est, int have_zlib)
{
return have_zlib ? p4est_checksum (p4est) : 0;
}

static void
test_partition_circle (sc_MPI_Comm mpicomm,
p4est_connectivity_t * connectivity,
p4est_gloidx_t * pertree1, p4est_gloidx_t * pertree2)
p4est_gloidx_t * pertree1, p4est_gloidx_t * pertree2,
int have_zlib)
{
int i, j;
int num_procs;
Expand All @@ -334,9 +341,9 @@ test_partition_circle (sc_MPI_Comm mpicomm,
test_pertree (p4est, NULL, pertree1);

global_num = p4est->global_num_quadrants;
crc1 = p4est_checksum (p4est);
crc1 = test_checksum (p4est, have_zlib);
copy = p4est_copy (p4est, 1);
P4EST_ASSERT (p4est_checksum (copy) == crc1);
P4EST_ASSERT (test_checksum (copy, have_zlib) == crc1);

new_counts = P4EST_ALLOC (p4est_locidx_t, num_procs);

Expand All @@ -362,7 +369,7 @@ test_partition_circle (sc_MPI_Comm mpicomm,
p4est_partition_given (p4est, new_counts);
test_transfer_post (tt, p4est);
test_pertree (p4est, pertree1, pertree2);
crc2 = p4est_checksum (p4est);
crc2 = test_checksum (p4est, have_zlib);
SC_CHECK_ABORT (crc1 == crc2, "First checksum mismatch");
}

Expand All @@ -389,7 +396,7 @@ test_partition_circle (sc_MPI_Comm mpicomm,
p4est_partition_given (p4est, new_counts);
test_transfer_post (tt, p4est);
test_pertree (p4est, pertree1, pertree2);
crc2 = p4est_checksum (p4est);
crc2 = test_checksum (p4est, have_zlib);
SC_CHECK_ABORT (crc1 == crc2, "Second checksum mismatch");
}

Expand All @@ -399,7 +406,7 @@ test_partition_circle (sc_MPI_Comm mpicomm,
p4est_partition (p4est, 0, NULL);
test_transfer_post (tt, p4est);
test_pertree (p4est, pertree1, pertree2);
crc2 = p4est_checksum (p4est);
crc2 = test_checksum (p4est, have_zlib);
SC_CHECK_ABORT (crc1 == crc2, "Third checksum mismatch");
SC_CHECK_ABORT (p4est_is_equal (p4est, copy, 1), "Forest mismatch");

Expand All @@ -414,6 +421,7 @@ main (int argc, char **argv)
int rank;
int num_procs;
int mpiret;
int have_zlib;
sc_MPI_Comm mpicomm;
p4est_t *p4est, *copy;
p4est_connectivity_t *connectivity;
Expand All @@ -439,6 +447,12 @@ main (int argc, char **argv)
sc_init (mpicomm, 1, 1, NULL, SC_LP_DEFAULT);
p4est_init (NULL, SC_LP_DEFAULT);

/* check for ZLIB usability */
if (!(have_zlib = sc_have_zlib ())) {
P4EST_GLOBAL_LERROR
("Not found a working ZLIB installation: ignoring CRCs\n");
}

/* create connectivity and forest structures */
#ifdef P4_TO_P8
connectivity = p8est_connectivity_new_twocubes ();
Expand Down Expand Up @@ -473,7 +487,7 @@ main (int argc, char **argv)
"Negative number of quadrants on the last processor");

/* Save a checksum of the original forest */
crc = p4est_checksum (p4est);
crc = test_checksum (p4est, have_zlib);

/* partition the forest */
tt = test_transfer_pre (p4est);
Expand All @@ -482,7 +496,7 @@ main (int argc, char **argv)
test_pertree (p4est, pertree1, pertree2);

/* Double check that we didn't loose any quads */
SC_CHECK_ABORT (crc == p4est_checksum (p4est),
SC_CHECK_ABORT (crc == test_checksum (p4est, have_zlib),
"bad checksum, missing a quad");

/* count the actual number of quadrants per proc */
Expand All @@ -508,12 +522,13 @@ main (int argc, char **argv)
p4est_partition (p4est, 0, weight_one);
test_transfer_post (tt, p4est);
test_pertree (p4est, pertree1, pertree2);
SC_CHECK_ABORT (crc == p4est_checksum (p4est),
SC_CHECK_ABORT (crc == test_checksum (p4est, have_zlib),
"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");
SC_CHECK_ABORT (crc == test_checksum (copy, have_zlib),
"bad checksum after copy");

/* do a weighted partition with many zero weights */
weight_counter = 0;
Expand All @@ -522,7 +537,7 @@ main (int argc, char **argv)
p4est_partition (copy, 0, weight_once);
test_transfer_post (tt, copy);
test_pertree (copy, pertree1, pertree2);
SC_CHECK_ABORT (crc == p4est_checksum (copy),
SC_CHECK_ABORT (crc == test_checksum (copy, have_zlib),
"bad checksum after unevenly weighted partition 1");

/* do a weighted partition with many zero weights */
Expand All @@ -532,7 +547,7 @@ main (int argc, char **argv)
p4est_partition (copy, 0, weight_once);
test_transfer_post (tt, copy);
test_pertree (copy, pertree1, pertree2);
SC_CHECK_ABORT (crc == p4est_checksum (copy),
SC_CHECK_ABORT (crc == test_checksum (copy, have_zlib),
"bad checksum after unevenly weighted partition 2");

/* do a weighted partition with many zero weights
Expand All @@ -547,7 +562,7 @@ main (int argc, char **argv)
p4est_partition (copy, 0, weight_once);
test_transfer_post (tt, copy);
test_pertree (copy, pertree1, pertree2);
SC_CHECK_ABORT (crc == p4est_checksum (copy),
SC_CHECK_ABORT (crc == test_checksum (copy, have_zlib),
"bad checksum after unevenly weighted partition 3");

/* check user data content */
Expand All @@ -564,7 +579,8 @@ main (int argc, char **argv)
}

/* Add another test. Overwrites pertree1, pertree2 */
test_partition_circle (mpicomm, connectivity, pertree1, pertree2);
test_partition_circle (mpicomm, connectivity, pertree1, pertree2,
have_zlib);

/* clean up and exit */
P4EST_FREE (pertree1);
Expand Down

0 comments on commit 7ea5b69

Please sign in to comment.