Commit efdfbd58 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Extend common redist check and use where possible.

parent 832baabb
......@@ -100,14 +100,14 @@ int main(void) {
static const double ref_dst_data[nselect] = {1,3,5};
for (size_t i = 0; i < nselect; ++i) dst_data[i] = -1;
check_redist(redist_coll, src_data, nselect * sizeof (*dst_data),
dst_data, ref_dst_data);
check_redist(redist_coll, src_data, nselect,
dst_data, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_coll_copy = xt_redist_copy(redist_coll);
for (size_t i = 0; i < nselect; ++i) dst_data[i] = -1;
check_redist(redist_coll_copy, src_data, nselect * sizeof (*dst_data),
dst_data, ref_dst_data);
check_redist(redist_coll_copy, src_data, nselect,
dst_data, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_coll_copy);
......
......@@ -97,7 +97,8 @@ int main(void) {
double dst_data[] = {-1,-1,-1};
static const double ref_dst_data[] = {1,3,5};
check_redist(redist_coll, src_data,
sizeof (dst_data), dst_data, ref_dst_data);
sizeof (dst_data) / sizeof (dst_data[0]),
dst_data, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
......@@ -106,6 +107,8 @@ int main(void) {
{ // test with one redist used three times (two exchanges)
// set up data
enum { src_slice_len = 5,
dst_slice_len = (src_slice_len+1)/2 };
Xt_xmap xmap = build_odd_selection_xmap(5);
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
......@@ -137,24 +140,14 @@ int main(void) {
// test exchange
{
for (size_t j = 0; j < 3; ++j)
for (size_t i = 0; i < 3; ++i)
dst_data[j][i] = -1.0;
static const double ref_dst_data[3][3] = {{1,3,5},{6,8,10},{11,13,15}};
check_redist(redist_coll, src_data,
sizeof (dst_data), dst_data, ref_dst_data);
}
{
for (size_t j = 0; j < 3; ++j)
for (size_t i = 0; i < 3; ++i)
dst_data[j][i] = -1.0;
static const double ref_dst_data[3][3] = {{1,3,5},{6,8,10},{11,13,15}};
check_redist(redist_coll, src_data,
sizeof (dst_data), dst_data, ref_dst_data);
}
for (size_t j = 0; j < 3; ++j)
for (size_t i = 0; i < 3; ++i)
dst_data[j][i] = -1.0;
static const double ref_dst_data[3][3] = {{1,3,5},{6,8,10},{11,13,15}};
check_redist(redist_coll, src_data,
sizeof (dst_data) / sizeof (dst_data[0][0]),
dst_data, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
......
......@@ -49,9 +49,9 @@
#include "yaxt.h"
#include "tests.h"
#include "test_redist_common.h"
#include "core/core.h"
#include "core/ppm_xfuncs.h"
/*
* build xmap for destination list containing all odd elements of
* source list dimensioned 1 to src_num_indices
......@@ -91,32 +91,90 @@ int communicators_are_congruent(MPI_Comm comm1, MPI_Comm comm2) {
}
void
check_redist(Xt_redist redist, const void *src,
size_t dst_size, void *dst, const void *ref_dst_data)
check_redist_(Xt_redist redist, const void *src,
size_t dst_size, void *dst, const void *ref_dst_data,
MPI_Datatype dst_data_dt,
MPI_Datatype ref_dst_data_dt,
const char *file, int line)
{
void * tmp_dst = malloc(dst_size);
for (int i = 0; i < 2; ++i) {
memcpy(tmp_dst, dst, dst_size);
if (i == 0) {
xt_redist_s_exchange1(redist, src, tmp_dst);
MPI_Comm comm = xt_redist_get_MPI_Comm(redist);
size_t dt_extent;
{
MPI_Aint dt_lb, dt_extent_;
xt_mpi_call(MPI_Type_get_extent(dst_data_dt, &dt_lb, &dt_extent_), comm);
dt_extent = (size_t)dt_extent_;
}
size_t dst_size_ = dst_size * dt_extent;
void *tmp_dst = malloc(dst_size_);
for (int txmode = 0; txmode < 2; ++txmode) {
void *dst_target = txmode == 0 ? tmp_dst : dst;
const void *dst_orig = txmode == 0 ? dst : tmp_dst;
memcpy(dst_target, dst_orig, dst_size);
if (txmode == 0) {
xt_redist_s_exchange1(redist, src, dst);
} else {
Xt_request request;
xt_redist_a_exchange1(redist, src, tmp_dst, &request);
xt_request_wait(&request);
wrap_a_exchange1(redist, src, dst);
}
if (memcmp(tmp_dst, ref_dst_data, dst_size))
PUT_ERR("error in xt_redist_s_exchange\n");
bool compare_failed = false;
if (dst_data_dt == ref_dst_data_dt) {
compare_failed = memcmp(dst, ref_dst_data, dst_size_);
} else if (dst_data_dt == MPI_DOUBLE && ref_dst_data_dt == MPI_INT) {
const double *dst_cmp = dst;
const int *ref_dst_cmp = ref_dst_data;
for (size_t i = 0; i < dst_size; ++i)
compare_failed |= (dst_cmp[i] != ref_dst_cmp[i]);
} else if (dst_data_dt == MPI_DOUBLE && ref_dst_data_dt == MPI_LONG) {
const double *dst_cmp = dst;
const long *ref_dst_cmp = ref_dst_data;
for (size_t i = 0; i < dst_size; ++i)
compare_failed |= (dst_cmp[i] != ref_dst_cmp[i]);
} else if (dst_data_dt == MPI_DOUBLE && ref_dst_data_dt == MPI_SHORT) {
const double *dst_cmp = dst;
const short *ref_dst_cmp = ref_dst_data;
for (size_t i = 0; i < dst_size; ++i)
compare_failed |= (dst_cmp[i] != ref_dst_cmp[i]);
} else if (dst_data_dt == MPI_DOUBLE && ref_dst_data_dt == MPI_LONG_LONG) {
const double *dst_cmp = dst;
const long long *ref_dst_cmp = ref_dst_data;
for (size_t i = 0; i < dst_size; ++i)
compare_failed |= (dst_cmp[i] != ref_dst_cmp[i]);
} else if (dst_data_dt == MPI_DOUBLE
&& ref_dst_data_dt == MPI_DATATYPE_NULL) {
const double *dst_cmp = dst;
for (size_t i = 0; i < dst_size; ++i)
compare_failed |= (dst_cmp[i] != (double)i);
} else
Xt_abort(comm, "internal error: unhandled test case!", file, line);
if (compare_failed)
PUT_ERR("error in xt_redist_s/a_exchange, called from %s, line %d\n",
file, line);
}
free(tmp_dst);
}
void
check_wait_request_(Xt_request *request, const char *file, int line)
{
#ifndef VERBOSE
(void)file;
(void)line;
#endif
if (*request == XT_REQUEST_NULL)
PUT_ERR("request == XT_REQUEST_NULL before xt_request_wait: %s, line %d\n",
file, line);
xt_request_wait(request);
if (*request != XT_REQUEST_NULL)
PUT_ERR("request != XT_REQUEST_NULL after xt_request_wait: %s, line %d\n",
file, line);
}
void
wrap_a_exchange(Xt_redist redist, int num_data_p, const void *src_data_p[],
void *dst_data_p[])
{
Xt_request request;
xt_redist_a_exchange(redist, num_data_p, src_data_p, dst_data_p, &request);
xt_request_wait(&request);
check_wait_request(&request);
}
void
......@@ -124,7 +182,7 @@ wrap_a_exchange1(Xt_redist redist, const void *src_data_p, void *dst_data_p)
{
Xt_request request;
xt_redist_a_exchange1(redist, src_data_p, dst_data_p, &request);
xt_request_wait(&request);
check_wait_request(&request);
}
/*
......
......@@ -62,8 +62,16 @@ build_odd_selection_xmap(int src_num_indices);
int communicators_are_congruent(MPI_Comm comm1, MPI_Comm comm2);
void
check_redist(Xt_redist redist, const void *src,
size_t dst_size, void *dst, const void *ref_dst_data);
check_redist_(Xt_redist redist, const void *src,
size_t dst_size,
void *dst, const void *ref_dst_data,
MPI_Datatype dst_data_dt, MPI_Datatype ref_dst_data_dt,
const char *file, int line);
#define check_redist(redist, src, dst_size,dst, ref_dst_data, \
dst_data_dt, ref_dst_data_dt) \
check_redist_(redist, src, dst_size,dst, ref_dst_data, \
dst_data_dt, ref_dst_data_dt, __FILE__, __LINE__)
void
wrap_a_exchange(Xt_redist redist, int num_data_p, const void *src_data_p[],
......@@ -80,8 +88,11 @@ typedef void
(*exchange1_func_ptr)(Xt_redist redist, const void *src_data_p,
void *dst_data_p);
void
check_wait_request_(Xt_request *request, const char *file, int line);
#define check_wait_request(request) \
check_wait_request_(request, __FILE__, __LINE__)
#endif
/*
* Local Variables:
......
......@@ -101,14 +101,14 @@ int main(void) {
double dst_data[dst_num];
for (size_t i = 0; i < dst_num; ++i)
dst_data[i] = -1.0;
check_redist(redist, src_data, sizeof (src_data[0]) * num_ref_values,
dst_data, ref_dst_data);
check_redist(redist, src_data, num_ref_values,
dst_data, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
for (size_t i = 0; i < dst_num; ++i)
dst_data[i] = -1.0;
check_redist(redist_copy, src_data, sizeof (src_data[0]) * num_ref_values,
dst_data, ref_dst_data);
check_redist(redist_copy, src_data, num_ref_values,
dst_data, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_copy);
......@@ -162,14 +162,14 @@ int main(void) {
double dst_data[dst_num];
for (size_t i = 0; i < dst_num; ++i)
dst_data[i] = -1.0;
check_redist(redist, src_data, sizeof (src_data[0]) * dst_num,
dst_data, ref_dst_data);
check_redist(redist, src_data, dst_num,
dst_data, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
for (size_t i = 0; i < dst_num; ++i)
dst_data[i] = -1.0;
check_redist(redist_copy, src_data, sizeof (src_data[0]) * dst_num,
dst_data, ref_dst_data);
check_redist(redist_copy, src_data, dst_num,
dst_data, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_copy);
......@@ -220,14 +220,14 @@ int main(void) {
long dst_data[dst_num];
for (size_t i = 0; i < dst_num; ++i)
dst_data[i] = -1L;
check_redist(redist, src_data, sizeof (src_data[0]) * dst_num,
dst_data, ref_dst_data);
check_redist(redist, src_data, dst_num,
dst_data, ref_dst_data, MPI_LONG, MPI_LONG);
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
for (size_t i = 0; i < dst_num; ++i)
dst_data[i] = -1L;
check_redist(redist_copy, src_data, sizeof (src_data[0]) * dst_num,
dst_data, ref_dst_data);
check_redist(redist_copy, src_data, dst_num,
dst_data, ref_dst_data, MPI_LONG, MPI_LONG);
// clean up
xt_redist_delete(redist_copy);
......
......@@ -104,34 +104,16 @@ int main(void) {
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test synchronous and asynchronous exchange
for (int j = 0; j < 2; ++j) {
double src_data[dataSize];
double dst_data[dataSize] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
double src_data[dataSize];
double dst_data[dataSize] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
for (int i = 0; i < src_num_indices; ++i)
src_data[i] = (double)(rank * dataSize + i);
const void *src_data_p = &src_data[0];
void *dst_data_p = &dst_data[0];
if (j == 0) {
xt_redist_s_exchange(redist, 1, &src_data_p, &dst_data_p);
} else {
Xt_request request;
xt_redist_a_exchange(redist, 1, &src_data_p, &dst_data_p, &request);
xt_request_wait(&request);
}
//int i;
for (int i = 0; i < src_num_indices; ++i)
src_data[i] = (double)(rank * dataSize + i);
for (int i = 0; i < dataSize; ++i)
if (dst_index_list[i] != dst_data[i])
PUT_ERR("error in xt_redist_s/a_exchange\n");
}
check_redist(redist, src_data, dataSize, dst_data,
dst_index_list, MPI_DOUBLE, XT_INT_MPIDT);
// clean up
xt_redist_delete(redist);
xt_xmap_delete(xmap);
xt_idxlist_delete(src_idxlist);
......@@ -172,7 +154,6 @@ int main(void) {
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
double src_data[size];
double dst_data[size];
if (rank == 0)
......@@ -182,35 +163,13 @@ int main(void) {
for (int i = 0; i < size; ++i)
src_data[i] = -2.0;
const void *src_data_p = &src_data[0];
void *dst_data_p = &dst_data[0];
for (int j = 0; j < 2; ++j) {
for (int i = 0; i < size; ++i)
dst_data[i] = -1.0;
if (rank == 0)
for (int i = 0; i < size; ++i)
dst_data[i] = -1.0;
else
for (int i = 0; i < size; ++i)
dst_data[i] = -1.0;
if (j == 0) {
xt_redist_s_exchange(redist, 1, &src_data_p, &dst_data_p);
} else {
Xt_request request;
xt_redist_a_exchange(redist, 1, &src_data_p, &dst_data_p, &request);
xt_request_wait(&request);
}
//int i;
for (int i = 0; i < size; ++i)
if (dst_data[i] != i)
PUT_ERR("error in xt_redist_s_exchange\n");
}
check_redist(redist, src_data, (size_t)size, dst_data,
NULL, MPI_DOUBLE, MPI_DATATYPE_NULL);
// clean up
xt_redist_delete(redist);
xt_xmap_delete(xmap);
xt_idxlist_delete(src_idxlist);
......@@ -284,23 +243,9 @@ int main(void) {
b_surfdata_ref[i] = gsurfdata[ivecb[i]];
}
for (int j = 0; j < 2; ++j) {
for (int i = 0; i < nwin; i++) b_surfdata[i] = -1;
if (j == 0) {
xt_redist_s_exchange1(redist, a_surfdata, b_surfdata);
} else {
Xt_request request;
xt_redist_a_exchange1(redist, a_surfdata, b_surfdata, &request);
xt_request_wait(&request);
}
for (int i = 0; i < nwin; ++i) {
if (b_surfdata[i] != b_surfdata_ref[i])
PUT_ERR("error in xt_redist_s_exchange\n");
}
}
for (int i = 0; i < nwin; i++) b_surfdata[i] = -1;
check_redist(redist, a_surfdata, (size_t)nwin, b_surfdata, b_surfdata_ref,
MPI_INT, MPI_INT);
xt_redist_delete(redist);
......@@ -379,22 +324,11 @@ int main(void) {
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
for (int j = 0; j < 2; ++j) {
for (int i = 0; i < gvol_size; i++) b_voldata[i] = -1;
for (int i = 0; i < gvol_size; i++) b_voldata[i] = -1;
if (j == 0) {
xt_redist_s_exchange1(block_redist, a_voldata, b_voldata);
} else {
Xt_request request;
xt_redist_a_exchange1(block_redist, a_voldata, b_voldata, &request);
xt_request_wait(&request);
}
for (int i = 0; i < gvol_size; i++)
if (b_voldata[i] != b_voldata_ref[i])
PUT_ERR("error in xt_redist_s_exchange (1) for volume data\n");
}
check_redist(block_redist, a_voldata,
(size_t)gvol_size, b_voldata, b_voldata_ref,
MPI_INT, MPI_INT);
// redist with blocks but without explicit offsets:
Xt_redist block_redist2
......@@ -406,22 +340,12 @@ int main(void) {
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
for (int j = 0; j < 2; ++j) {
for (int i = 0; i < gvol_size; i++) b_voldata[i] = -1;
for (int i = 0; i < gvol_size; i++) b_voldata[i] = -1;
if (j == 0) {
xt_redist_s_exchange1(block_redist2, a_voldata, b_voldata);
} else {
Xt_request request;
xt_redist_a_exchange1(block_redist2, a_voldata, b_voldata, &request);
xt_request_wait(&request);
}
for (int i = 0; i < gvol_size; i++)
if (b_voldata[i] != b_voldata_ref[i])
PUT_ERR("error in xt_redist_s_exchange (2) for volume data\n");
}
check_redist(block_redist2, a_voldata,
(size_t)gvol_size, b_voldata, b_voldata_ref,
MPI_INT, MPI_INT);
xt_redist_delete(block_redist);
xt_redist_delete(block_redist2);
......
......@@ -96,7 +96,8 @@ int main(void) {
static const double ref_dst_data[] = {1,3,5};
check_redist(redist_repeat, src_data,
sizeof(dst_data), dst_data, ref_dst_data);
sizeof(dst_data) / sizeof (dst_data[0]),
dst_data, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_repeat);
......@@ -135,26 +136,15 @@ int main(void) {
xt_redist_delete(redist);
// test exchange
{
for (size_t j = 0; j < num_repetitions; ++j)
for (size_t i = 0; i < dst_slice_len; ++i)
dst_data[j][i] = -1.0;
static const double ref_dst_data[num_repetitions][dst_slice_len]
= {{1,3,5},{6,8,10},{11,13,15}};
check_redist(redist_repeat, src_data,
sizeof (dst_data), dst_data, ref_dst_data);
}
for (size_t j = 0; j < num_repetitions; ++j)
for (size_t i = 0; i < dst_slice_len; ++i)
dst_data[j][i] = -1.0;
{
for (size_t j = 0; j < num_repetitions; ++j)
for (size_t i = 0; i < dst_slice_len; ++i)
dst_data[j][i] = -1.0;
static const double ref_dst_data[num_repetitions][dst_slice_len]
= {{1,3,5},{6,8,10},{11,13,15}};
check_redist(redist_repeat, src_data,
sizeof (dst_data), dst_data, ref_dst_data);
}
static const double ref_dst_data[num_repetitions][dst_slice_len]
= {{1,3,5},{6,8,10},{11,13,15}};
check_redist(redist_repeat, src_data,
num_repetitions * dst_slice_len, dst_data, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE);
// clean up
......@@ -196,16 +186,15 @@ int main(void) {
xt_redist_delete(redist);
// test exchange
{
for (size_t j = 0; j < num_repetitions; ++j)
for (size_t i = 0; i < dst_slice_len; ++i)
dst_data[j][i] = -1.0;
static const double ref_dst_data[num_repetitions][dst_slice_len]
= {{11,13,15},{6,8,10},{1,3,5}};
check_redist(redist_repeat, src_data,
sizeof (dst_data), dst_data, ref_dst_data);
}
for (size_t j = 0; j < num_repetitions; ++j)
for (size_t i = 0; i < dst_slice_len; ++i)
dst_data[j][i] = -1.0;
static const double ref_dst_data[num_repetitions][dst_slice_len]
= {{11,13,15},{6,8,10},{1,3,5}};
check_redist(redist_repeat, src_data,
num_repetitions * dst_slice_len, dst_data, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE);
// clean up
......@@ -213,14 +202,15 @@ int main(void) {
}
{ // test with one redist used three times with gaps between the levels
enum { src_slice_len = 5, dst_slice_len = (src_slice_len+1)/2 };
enum { src_slice_len = 5, dst_slice_len = (src_slice_len+1)/2,
rep_dim_size = 5 };
Xt_xmap xmap = build_odd_selection_xmap(src_slice_len);
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
xt_xmap_delete(xmap);
// generate redist_repeatection
MPI_Aint src_extent = (MPI_Aint)(5 * sizeof (double));
MPI_Aint dst_extent = (MPI_Aint)(3 * sizeof (double));
MPI_Aint src_extent = (MPI_Aint)(src_slice_len * sizeof (double));
MPI_Aint dst_extent = (MPI_Aint)(dst_slice_len * sizeof (double));
int displacements[3] = {0, 2, 4};
Xt_redist redist_repeat
= xt_redist_repeat_new(redist, src_extent, dst_extent, 3, displacements);
......@@ -234,16 +224,15 @@ int main(void) {
xt_redist_delete(redist);
// test exchange
{
static const double src_data[5][5]
= {{1,2,3,4,5},{-1},{6,7,8,9,10},{-1},{11,12,13,14,15}};
double dst_data[5][3]
= {{-1,-1,-1},{-1,-1,-1},{-1,-1,-1},{-1,-1,-1},{-1,-1,-1}};
static const double ref_dst_data[5][3]
= {{1,3,5},{-1,-1,-1},{6,8,10},{-1,-1,-1},{11,13,15}};
check_redist(redist_repeat, src_data,
sizeof (dst_data), dst_data, ref_dst_data);
}
static const double src_data[rep_dim_size][src_slice_len]
= {{1,2,3,4,5},{-1},{6,7,8,9,10},{-1},{11,12,13,14,15}};
double dst_data[rep_dim_size][dst_slice_len]
= {{-1,-1,-1},{-1,-1,-1},{-1,-1,-1},{-1,-1,-1},{-1,-1,-1}};
static const double ref_dst_data[rep_dim_size][dst_slice_len]
= {{1,3,5},{-1,-1,-1},{6,8,10},{-1,-1,-1},{11,13,15}};
check_redist(redist_repeat, src_data,
rep_dim_size * dst_slice_len, dst_data, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE);
// clean up
......@@ -305,7 +294,8 @@ int main(void) {
// test exchange
for(int i = 0; i<npt; i++) dst_data[i] = -1;
check_redist(redist_repeat, src_data,
sizeof (dst_data), dst_data, ref_dst_data);
npt, dst_data, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist);
......
......@@ -91,13 +91,13 @@ int main(void) {
enum { num_ref_values = sizeof(ref_dst_data) / sizeof(ref_dst_data[0]) };
double dst_data[num_ref_values];
for (size_t i = 0; i < num_ref_values; ++i) dst_data[i] = -1.0;
check_redist(redist, src_data, sizeof (src_data[0]) * num_ref_values,
dst_data, ref_dst_data);
check_redist(redist, src_data, num_ref_values, dst_data, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
for (size_t i = 0; i < num_ref_values; ++i) dst_data[i] = -1.0;
check_redist(redist_copy, src_data, sizeof (src_data[0]) * num_ref_values,