Commit 07501b30 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Extract test code into function.

* This follows the example of the Fortran test.
parent 1ee64b1c
......@@ -57,10 +57,16 @@
#include "core/ppm_xfuncs.h"
static void
test_repeated_redist(int cache_size);
simple_test(MPI_Comm comm);
static void
test_displacement_variations(void);
test_empty_redist(MPI_Comm comm);
static void
test_repeated_redist(MPI_Comm comm, int cache_size);
static void
test_displacement_variations(MPI_Comm comm);
int main(void) {
......@@ -71,119 +77,119 @@ int main(void) {
xt_initialize(MPI_COMM_WORLD);
{ // general test with one redist
// set up data
enum { nvalues = 5, nselect = (nvalues + 1)/2 };
Xt_xmap xmap = build_odd_selection_xmap(nvalues);
simple_test(MPI_COMM_WORLD);
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
test_empty_redist(MPI_COMM_WORLD);
xt_xmap_delete(xmap);
// generate redist_collection
Xt_redist redist_coll
= xt_redist_collection_new(&redist, 1, -1, MPI_COMM_WORLD);
// test communicator of redist
// test with one redist used three times (with two different input data
// displacements -> test of cache) (with default cache size)
// set up data
test_repeated_redist(MPI_COMM_WORLD, -1);
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test with one redist used three times (with two different input data
// displacements -> test of cache) (with cache size == 0)
// set up data
test_repeated_redist(MPI_COMM_WORLD, 0);
xt_redist_delete(redist);
test_displacement_variations(MPI_COMM_WORLD);
// test exchange
xt_finalize();
MPI_Finalize();
static const double src_data[nvalues] = {1,2,3,4,5};
double dst_data[nselect];
static const double ref_dst_data[nselect] = {1,3,5};
return TEST_EXIT_CODE;
}
check_redist(redist_coll, src_data, nselect,
dst_data, fill_array_double, NULL,
ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
static void
simple_test(MPI_Comm comm)
{ // general test with one redist
// set up data
enum { nvalues = 5, nselect = (nvalues + 1)/2 };
Xt_xmap xmap = build_odd_selection_xmap(nvalues);
Xt_redist redist_coll_copy = xt_redist_copy(redist_coll);
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
check_redist(redist_coll_copy, src_data, nselect,
dst_data, fill_array_double, NULL,
ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_xmap_delete(xmap);
xt_redist_delete(redist_coll_copy);
xt_redist_delete(redist_coll);
}
// generate redist_collection
{ // test empty redist
Xt_idxlist src_idxlist = xt_idxempty_new();
Xt_idxlist dst_idxlist = xt_idxempty_new();
Xt_xmap xmap =
xt_xmap_all2all_new(src_idxlist, dst_idxlist, MPI_COMM_WORLD);
Xt_redist redist_coll
= xt_redist_collection_new(&redist, 1, -1, comm);
xt_idxlist_delete(src_idxlist);
xt_idxlist_delete(dst_idxlist);
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
xt_redist_delete(redist);
xt_xmap_delete(xmap);
// test exchange
static const double src_data[nvalues] = {1,2,3,4,5};
double dst_data[nselect];
static const double ref_dst_data[nselect] = {1,3,5};
// generate redist_collection
check_redist(redist_coll, src_data, nselect,
dst_data, fill_array_double, NULL,
ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_coll
= xt_redist_collection_new(&redist, 1, -1, MPI_COMM_WORLD);
Xt_redist redist_coll_copy = xt_redist_copy(redist_coll);
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
check_redist(redist_coll_copy, src_data, nselect,
dst_data, fill_array_double, NULL,
ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_coll_copy);
xt_redist_delete(redist_coll);
}
xt_redist_delete(redist);
static void
test_empty_redist(MPI_Comm comm)
{ // test empty redist
Xt_idxlist src_idxlist = xt_idxempty_new();
Xt_idxlist dst_idxlist = xt_idxempty_new();
Xt_xmap xmap = xt_xmap_all2all_new(src_idxlist, dst_idxlist, comm);
// test exchange
xt_idxlist_delete(src_idxlist);
xt_idxlist_delete(dst_idxlist);
static const double src_data[1] = {-1};
double dst_data[1] = {-2};
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
xt_redist_s_exchange1(redist_coll, src_data, dst_data);
xt_xmap_delete(xmap);
static const double ref_dst_data[1] = {-2};
// generate redist_collection
Xt_redist redist_coll = xt_redist_collection_new(&redist, 1, -1, comm);
if (ref_dst_data[0] != dst_data[0])
PUT_ERR("error in xt_redist_s_exchange\n");
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
Xt_redist redist_coll_copy = xt_redist_copy(redist_coll);
dst_data[0] = -2;
xt_redist_delete(redist);
xt_redist_s_exchange1(redist_coll_copy, src_data, dst_data);
// test exchange
static const double src_data[1] = {-1};
double dst_data[1] = {-2};
if (ref_dst_data[0] != dst_data[0])
PUT_ERR("error in xt_redist_s_exchange\n");
xt_redist_s_exchange1(redist_coll, src_data, dst_data);
// clean up
xt_redist_delete(redist_coll_copy);
xt_redist_delete(redist_coll);
}
static const double ref_dst_data[1] = {-2};
// test with one redist used three times (with two different input data
// displacements -> test of cache) (with default cache size)
// set up data
test_repeated_redist(-1);
if (ref_dst_data[0] != dst_data[0])
PUT_ERR("error in xt_redist_s_exchange\n");
// test with one redist used three times (with two different input data
// displacements -> test of cache) (with cache size == 0)
// set up data
test_repeated_redist(0);
Xt_redist redist_coll_copy = xt_redist_copy(redist_coll);
dst_data[0] = -2;
test_displacement_variations();
xt_redist_s_exchange1(redist_coll_copy, src_data, dst_data);
xt_finalize();
MPI_Finalize();
if (ref_dst_data[0] != dst_data[0])
PUT_ERR("error in xt_redist_s_exchange\n");
return TEST_EXIT_CODE;
// clean up
xt_redist_delete(redist_coll_copy);
xt_redist_delete(redist_coll);
}
static void
test_repeated_redist(int cache_size)
test_repeated_redist(MPI_Comm comm, int cache_size)
{
Xt_xmap xmap = build_odd_selection_xmap(5);
......@@ -194,12 +200,11 @@ test_repeated_redist(int cache_size)
// generate redist_collection
Xt_redist redists[3] = {redist, redist, redist};
Xt_redist redist_coll
= xt_redist_collection_new(redists, 3, cache_size, MPI_COMM_WORLD);
= xt_redist_collection_new(redists, 3, cache_size, comm);
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll),
MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......@@ -323,7 +328,7 @@ run_displacement_check(Xt_redist redist_coll, int sync)
static void
test_displacement_variations(void)
test_displacement_variations(MPI_Comm comm)
{
// test with one redist used three times (with different input
// data displacements until the cache is full)
......@@ -339,12 +344,11 @@ test_displacement_variations(void)
Xt_redist redists[num_redists] = {redist, redist, redist};
Xt_redist redist_coll
= xt_redist_collection_new(redists, num_redists, -1, MPI_COMM_WORLD);
= xt_redist_collection_new(redists, num_redists, -1, comm);
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll),
MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment