17static void utest_contiguous_with_indices_null(
void);
18static void utest_contiguous_with_explicit_contiguous_indices(
void);
19static void utest_single_with_explicit_zero_index(
void);
20static void utest_single_with_explicit_non_zero_index(
void);
21static void utest_noncontiguous(
void);
22static void utest_copy(
void);
23static void utest_zero_size(
void);
25static void utest_pack_unpack(
void);
31 utest_contiguous_with_indices_null();
32 utest_contiguous_with_explicit_contiguous_indices();
33 utest_noncontiguous();
34 utest_single_with_explicit_zero_index();
35 utest_single_with_explicit_non_zero_index();
46static void utest_contiguous_with_indices_null(
void) {
51 if (sel == NULL)
PUT_ERR(
"selection is NULL");
53 PUT_ERR(
"wrong collection_size");
55 PUT_ERR(
"should be contiguous");
57 PUT_ERR(
"indices should be NULL for contiguous");
64static void utest_contiguous_with_explicit_contiguous_indices(
void) {
65 size_t idxs[] = {0, 1, 2, 3};
66 enum {
N =
sizeof(idxs) /
sizeof(idxs[0])};
70 if (sel == NULL)
PUT_ERR(
"selection is NULL");
72 PUT_ERR(
"wrong collection_size");
74 PUT_ERR(
"should be contiguous");
76 PUT_ERR(
"indices should be NULL for contiguous");
83static void utest_noncontiguous(
void) {
84 size_t idxs[] = {0, 2, 3, 5};
85 enum {
N =
sizeof(idxs) /
sizeof(idxs[0])};
89 if (sel == NULL)
PUT_ERR(
"selection is NULL");
91 PUT_ERR(
"wrong collection_size");
93 PUT_ERR(
"should not be contiguous");
95 size_t ref_max_index = 0;
98 PUT_ERR(
"indices should not be NULL for non-contiguous");
100 for (
size_t i = 0;
i <
N; ++
i) {
101 if (got[i] != idxs[i])
PUT_ERR(
"wrong index value");
102 if (ref_max_index < idxs[i]) ref_max_index = idxs[
i];
107 PUT_ERR(
"wrong maximum index");
112static void utest_copy(
void) {
119 {{.N = 3, .indices = (
size_t[]){0, 2, 5}},
120 {.N = 4, .indices = (
size_t[]){0, 1, 2, 3}},
121 {.N = 0, .indices = NULL},
122 {.N = 5, .indices = NULL}};
123 enum {
NUM_TESTS =
sizeof(test_configs) /
sizeof(test_configs[0])};
145 if (copy != NULL)
PUT_ERR(
"copy is not NULL");
149static void utest_zero_size(
void) {
154 if (sel != NULL)
PUT_ERR(
"selection is NULL");
156 PUT_ERR(
"wrong collection_size");
158 PUT_ERR(
"zero-size should be contiguous");
160 PUT_ERR(
"indices should be NULL for zero-size contiguous");
162 PUT_ERR(
"wrong maximum index");
167static void utest_single_with_explicit_zero_index(
void) {
169 enum {
N =
sizeof(idxs) /
sizeof(idxs[0])};
173 if (sel == NULL)
PUT_ERR(
"selection is NULL");
175 PUT_ERR(
"wrong collection_size");
177 PUT_ERR(
"index {0} should be treated as contiguous");
179 PUT_ERR(
"indices should be NULL for contiguous");
181 PUT_ERR(
"wrong maximum index");
186static void utest_single_with_explicit_non_zero_index(
void) {
188 enum {
N =
sizeof(idxs) /
sizeof(idxs[0])};
192 if (sel == NULL)
PUT_ERR(
"selection is NULL");
194 PUT_ERR(
"wrong collection_size");
196 PUT_ERR(
"index {7} should not be contiguous");
199 if (indices == NULL) {
200 PUT_ERR(
"indices should not be NULL for non-contiguous");
201 }
else if (indices[0] != 7) {
202 PUT_ERR(
"wrong stored index value");
205 PUT_ERR(
"wrong maximum index");
214 PUT_ERR(
"yac_collection_selection_compare(NULL, NULL) failed");
221 PUT_ERR(
"yac_collection_selection_compare(sel, NULL)");
224 PUT_ERR(
"yac_collection_selection_compare(NULL, sel)");
230 size_t indices[] = {0,1,2,3,4,5};
231 enum {
N =
sizeof(indices) /
sizeof(indices[0])};
237 PUT_ERR(
"identical contiguous selections should be equal");
239 PUT_ERR(
"identical contiguous selections should be equal");
251 PUT_ERR(
"different contiguous sizes should not be equal");
254 PUT_ERR(
"different contiguous sizes should not be equal");
261 size_t indices[] = {0, 2, 4, 6, 8};
262 enum {
N =
sizeof(indices) /
sizeof(indices[0])};
268 PUT_ERR(
"identical non-contiguous selections should be equal");
270 PUT_ERR(
"identical non-contiguous selections should be equal");
277 size_t indices_a[] = {0, 1, 2, 3, 4};
278 enum {N_a =
sizeof(indices_a) /
sizeof(indices_a[0])};
281 size_t indices_b[] = {0, 1, 3, 2, 4};
282 enum {N_b =
sizeof(indices_b) /
sizeof(indices_b[0])};
286 PUT_ERR(
"different non-contiguous selections should not be equal");
289 PUT_ERR(
"different non-contiguous selections should not be equal");
297 size_t indices[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
298 enum {
N =
sizeof(indices) /
sizeof(indices[0])};
304 PUT_ERR(
"contiguous and equivalent explicit list should be equal");
306 PUT_ERR(
"contiguous and equivalent explicit list should be equal");
313 size_t indices[] = {0, 1, 3, 4, 5, 6, 7, 8, 9, 10};
314 enum {
N =
sizeof(indices) /
sizeof(indices[0])};
320 PUT_ERR(
"contiguous and non-matching explicit list should differ");
323 PUT_ERR(
"contiguous and non-matching explicit list should differ");
329static void utest_pack_unpack(
void) {
331 MPI_Comm
comm = MPI_COMM_SELF;
338 {.N = 3, .indices = (
size_t[]){0, 2, 5}},
339 {.N = 4, .indices = (
size_t[]){0, 1, 2, 3}},
340 {.N = 0, .indices = NULL},
341 {.N = 5, .indices = NULL}
343 enum {
NUM_TESTS =
sizeof(test_configs) /
sizeof(test_configs[0]) };
349 test_configs[t].
N, test_configs[t].indices);
353 "utest_pack_unpack: pack_size must be positive");
359 orig,
buffer, (
int)pack_size, &position, comm);
362 int unpack_position = 0;
365 buffer, (
int)pack_size, &unpack_position, comm);
368 PUT_ERR(
"ERROR in pack/unpack");
384 orig,
buffer, (
int)pack_size, &position, comm);
386 int unpack_position = 0;
389 buffer, (
int)pack_size, &unpack_position, comm);
392 PUT_ERR(
"unpacked object from NULL should be NULL");
#define YAC_ASSERT(exp, msg)
int yac_collection_selection_is_contiguous(struct yac_collection_selection const *collection_selection)
Query whether a selection is contiguous.
size_t yac_collection_selection_get_collection_size(struct yac_collection_selection const *collection_selection)
Get the size of the collection selection.
struct yac_collection_selection * yac_collection_selection_unpack(void const *buffer, int buffer_size, int *position, MPI_Comm comm)
Unpack a collection selection from a contiguous MPI buffer.
size_t yac_collection_selection_get_pack_size(struct yac_collection_selection const *sel, MPI_Comm comm)
Compute the MPI pack size of a collection selection.
size_t const * yac_collection_selection_get_indices(struct yac_collection_selection const *collection_selection)
Get explicit selection indices if non-contiguous.
void yac_collection_selection_delete(struct yac_collection_selection *collection_selection)
Delete a collection selection object.
int yac_collection_selection_compare(struct yac_collection_selection const *a, struct yac_collection_selection const *b)
Compare two collection selections.
struct yac_collection_selection * yac_collection_selection_copy(const struct yac_collection_selection *collection_selection)
Selection of indices from a collection.
void yac_collection_selection_pack(struct yac_collection_selection const *sel, void *buffer, int buffer_size, int *position, MPI_Comm comm)
Pack a collection selection into a contiguous MPI buffer.
struct yac_collection_selection * yac_collection_selection_new(size_t collection_size, size_t const *selection_indices)
Create a new collection selection.
size_t yac_collection_selection_get_max_index(struct yac_collection_selection const *selection)
Get the maximum index of a collection selection.
static void test_compare(void)