#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
#include <yaxt.h>
#include "tests.h"
#include "test_redist_common.h"
static void
test_repeated_redist(int cache_size);
static void
test_displacement_variations(void);
int main(void) {
{
enum { nvalues = 5, nselect = (nvalues + 1)/2 };
Xt_xmap xmap = build_odd_selection_xmap(nvalues);
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
static const double src_data[nvalues] = {1,2,3,4,5};
double dst_data[nselect] = {-1,-1,-1};
static const double ref_dst_data[nselect] = {1,3,5};
for (size_t i = 0; i < nselect; ++i)
if (ref_dst_data[i] != dst_data[i])
PUT_ERR("error in xt_redist_s_exchange\n");
for (size_t i = 0; i < nselect; ++i)
dst_data[i] = -1;
for (size_t i = 0; i < nselect; ++i)
if (ref_dst_data[i] != dst_data[i])
PUT_ERR("error in xt_redist_s_exchange\n");
}
{
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
static const double src_data[1] = {-1};
double dst_data[1] = {-2};
static const double ref_dst_data[1] = {-2};
if (ref_dst_data[0] != dst_data[0])
PUT_ERR("error in xt_redist_s_exchange\n");
dst_data[0] = -2;
if (ref_dst_data[0] != dst_data[0])
PUT_ERR("error in xt_redist_s_exchange\n");
}
test_repeated_redist(-1);
test_repeated_redist(0);
test_displacement_variations();
MPI_Finalize();
return TEST_EXIT_CODE;
}
static void
test_repeated_redist(int cache_size)
{
Xt_xmap xmap = build_odd_selection_xmap(5);
Xt_redist redists[3] = {redist, redist, redist};
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
{
static const double src_data[3][5]
= {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};
double dst_data[3][3] = {{-1,-1,-1},{-1,-1,-1},{-1,-1,-1}};
const void *src_data_p[3] = {src_data[0],src_data[1],src_data[2]};
void *dst_data_p[3] = {dst_data[0],dst_data[1],dst_data[2]};
static const double ref_dst_data[3][3] = {{1,3,5},{6,8,10},{11,13,15}};
for (size_t i = 0; i < 3; ++i)
for (size_t j = 0; j < 3; ++j)
if (ref_dst_data[i][j] != dst_data[i][j])
PUT_ERR("error in xt_redist_s_exchange\n");
}
{
static const double src_data[3][5]
= {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};
double dst_data[3][3] = {{-1,-1,-1},{-1,-1,-1},{-1,-1,-1}};
const void *src_data_p[3] = {src_data[1],src_data[0],src_data[2]};
void *dst_data_p[3] = {dst_data[1],dst_data[0],dst_data[2]};
static const double ref_dst_data[3][3] = {{1,3,5},{6,8,10},{11,13,15}};
for (size_t i = 0; i < 3; ++i)
for (size_t j = 0; j < 3; ++j)
if (ref_dst_data[i][j] != dst_data[i][j])
PUT_ERR("error in xt_redist_s_exchange\n");
}
{
static const double src_data[3][5]
= {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};
double dst_data[3][3] = {{-1,-1,-1},{-1,-1,-1},{-1,-1,-1}};
const void *src_data_p[3] = {src_data[0],src_data[1],src_data[2]};
void *dst_data_p[3] = {dst_data[0],dst_data[1],dst_data[2]};
static const double ref_dst_data[3][3] = {{1,3,5},{6,8,10},{11,13,15}};
for (size_t i = 0; i < 3; ++i)
for (size_t j = 0; j < 3; ++j)
if (ref_dst_data[i][j] != dst_data[i][j])
PUT_ERR("error in xt_redist_s_exchange\n");
}
}
enum { num_redists = 3 };
enum { nvalues = 5, nselect = nvalues/2+(nvalues&1) };
static void
run_displacement_check(
Xt_redist redist_coll)
{
static const double src_data[num_redists][nvalues]
= {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};
double dst_data[num_redists][nselect] = {{-1,-1,-1},{-1,-1,-1},{-1,-1,-1}};
enum { cache_size = 16, cache_overrun = 2 };
double src_data_[nvalues + cache_size + cache_overrun],
dst_data_[nselect + cache_size + cache_overrun];
const void *src_data_p[num_redists] = {src_data[0],src_data[1],NULL};
void *dst_data_p[num_redists] = {dst_data[0],dst_data[1],NULL};
for (size_t k = 0; k < cache_size + cache_overrun; ++k) {
memcpy(src_data_+k, src_data[2], 5 * sizeof(*src_data_));
for (size_t i = 0; i < num_redists; ++i)
for (size_t j = 0; j < nselect; ++j)
dst_data[i][j] = -1;
memcpy(dst_data_+k, dst_data[2], 3 * sizeof(*dst_data_));
src_data_p[2] = src_data_+k;
dst_data_p[2] = dst_data_+k;
static const double ref_dst_data[num_redists][nselect]
= {{1,3,5},{6,8,10},{11,13,15}};
for (size_t i = 0; i < num_redists; ++i)
for (size_t j = 0; j < nselect; ++j)
if (ref_dst_data[i][j] != ((double *)dst_data_p[i])[j])
PUT_ERR("error in xt_redist_s_exchange\n");
}
}
static void
test_displacement_variations(void)
{
Xt_xmap xmap = build_odd_selection_xmap(nvalues);
Xt_redist redists[num_redists] = {redist, redist, redist};
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
run_displacement_check(redist_coll);
run_displacement_check(redist_coll_copy);
}