#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <assert.h>
#include <stdlib.h>
#include <mpi.h>
#include <yaxt.h>
#define VERBOSE
#include "tests.h"
#include "ctest_common.h"
#include "test_redist_common.h"
static void
generate_block(int *restrict voldata, int *restrict block_sizes,
int *restrict block_offsets, const int gvoldata[],
const int ig2col_off[], const int gdepth[],
const Xt_int ivec[],
int nwin)
{
int qa=0;
if (nwin > 0) {
int bsize, ofs_accum;
{
ofs_accum = block_offsets[0] = 0;
bsize = block_sizes[0] = gdepth[ia];
int ofs = ig2col_off[ia];
for (int j = 0; j < bsize; ++j, ++qa)
voldata[qa] = gvoldata[ofs + j];
}
for (int i = 1; i < nwin; i++) {
block_offsets[i] = (ofs_accum+=bsize);
bsize = block_sizes[i] = gdepth[ia];
int ofs = ig2col_off[ia];
for (int j = 0; j < bsize; ++j, ++qa)
voldata[qa] = gvoldata[ofs + j];
}
}
}
int main(int argc, char **argv) {
int rank, size;
Xt_config config = redist_exchanger_option(&argc, &argv);
{
enum { dataSize = 10 };
Xt_int src_index_list[dataSize];
int src_num_indices = dataSize;
for (int i = 0; i < src_num_indices; ++i)
src_index_list[i] = (
Xt_int)(rank * dataSize + i);
Xt_int dst_index_list[dataSize];
int dst_num_indices = dataSize;
for (int i = 0; i < dst_num_indices; ++i)
dst_index_list[i] = (
Xt_int)((rank * dataSize + i + 2)
% (size * dataSize));
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
double src_data[dataSize];
double dst_data[dataSize];
for (int i = 0; i < src_num_indices; ++i)
src_data[i] = (double)(rank * dataSize + i);
check_redist(redist, src_data, dataSize, dst_data, fill_array_double, NULL,
dst_index_list, MPI_DOUBLE, XT_INT_MPIDT);
}
{
int src_num_indices = (rank == 0) ? size : 0;
for (int i = 0; i < src_num_indices; ++i)
src_index_list[i] = (
Xt_int)i;
int dst_num_indices = size;
for (int i = 0; i < dst_num_indices; ++i)
dst_index_list[i] = (
Xt_int)i;
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
double src_data[size];
double dst_data[size];
if (rank == 0)
for (int i = 0; i < size; ++i)
src_data[i] = (double)i;
else
for (int i = 0; i < size; ++i)
src_data[i] = -2.0;
check_redist(redist, src_data, (size_t)size, dst_data,
fill_array_double, NULL, NULL, MPI_DOUBLE, MPI_DATATYPE_NULL);
}
{
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
#elif defined __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare"
#endif
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
#pragma GCC diagnostic pop
#endif
int ngdom = 2*size;
int gdoma[ngdom];
int gdomb[ngdom];
int gsurfdata[ngdom];
int gdepth[ngdom];
int gvol_size;
int ig2col_off[ngdom];
gvol_size = 0;
for (int i = 0; i < ngdom; i++) {
gdoma[i] = i;
gdomb[i] = ngdom-1-i;
gsurfdata[i] = 100+i;
gdepth[i] = i+1;
ig2col_off[i] = gvol_size;
gvol_size += gdepth[i];
}
int nwin = ngdom/size;
int ig0 = rank*nwin;
if (nwin*size != ngdom) PUT_ERR("internal error\n");
Xt_int iveca[nwin], ivecb[nwin];
for (int i = 0; i < nwin; i++) {
int ig = ig0+i;
iveca[i]= (
Xt_int)(gdoma[ig]);
ivecb[i]= (
Xt_int)(gdomb[ig]);
}
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
int a_surfdata[nwin];
int b_surfdata[nwin];
int b_surfdata_ref[nwin];
for (int i = 0; i < nwin; i++) {
a_surfdata[i] = gsurfdata[iveca[i]];
b_surfdata_ref[i] = gsurfdata[ivecb[i]];
}
check_redist(redist, a_surfdata, (size_t)nwin, b_surfdata,
fill_array_int, NULL, b_surfdata_ref, MPI_INT, MPI_INT);
int gvoldata[gvol_size];
for (int i = 0; i < ngdom; i++) {
int ofs = ig2col_off[i];
for (int j = 0; j < gdepth[i]; j++)
gvoldata[ofs + j] = i*100 + j;
}
int src_block_offsets[nwin];
int src_block_sizes[nwin];
int dst_block_offsets[nwin];
int dst_block_sizes[nwin];
int a_voldata[gvol_size];
int b_voldata[gvol_size];
int b_voldata_ref[gvol_size];
for (int i = 0; i < gvol_size; i++) {
a_voldata[i] = -1;
b_voldata_ref[i] = -1;
}
generate_block(a_voldata, src_block_sizes, src_block_offsets,
gvoldata, ig2col_off, gdepth, iveca, nwin);
generate_block(b_voldata_ref, dst_block_sizes, dst_block_offsets,
gvoldata, ig2col_off, gdepth, ivecb, nwin);
xmap, src_block_offsets, src_block_sizes, nwin,
dst_block_offsets, dst_block_sizes, nwin,
MPI_INT, config);
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
check_redist(block_redist, a_voldata, (size_t)gvol_size, b_voldata,
fill_array_int, NULL, b_voldata_ref, MPI_INT, MPI_INT);
xmap, src_block_sizes, nwin, dst_block_sizes, nwin, MPI_INT, config);
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
check_redist(block_redist2, a_voldata, (size_t)gvol_size, b_voldata,
fill_array_int, NULL, b_voldata_ref, MPI_INT, MPI_INT);
}
MPI_Finalize();
return TEST_EXIT_CODE;
}
struct Xt_config_ * Xt_config
void xt_config_delete(Xt_config config)
void xt_initialize(MPI_Comm default_comm)
struct Xt_xmap_ * Xt_xmap
struct Xt_idxlist_ * Xt_idxlist
struct Xt_redist_ * Xt_redist
void xt_idxlist_delete(Xt_idxlist idxlist)
Xt_idxlist xt_idxvec_new(const Xt_int *idxlist, int num_indices)
#define xt_mpi_call(call, comm)
void xt_redist_delete(Xt_redist redist)
MPI_Comm xt_redist_get_MPI_Comm(Xt_redist redist)
Xt_redist xt_redist_p2p_custom_new(Xt_xmap xmap, MPI_Datatype datatype, Xt_config config)
Xt_redist xt_redist_p2p_blocks_custom_new(Xt_xmap xmap, const int *src_block_sizes, int src_block_num, const int *dst_block_sizes, int dst_block_num, MPI_Datatype datatype, Xt_config config)
Xt_redist xt_redist_p2p_blocks_off_custom_new(Xt_xmap xmap, const int *src_block_offsets, const int *src_block_sizes, int src_block_num, const int *dst_block_offsets, const int *dst_block_sizes, int dst_block_num, MPI_Datatype datatype, Xt_config config)
void xt_xmap_delete(Xt_xmap xmap)
Xt_xmap xt_xmap_all2all_new(Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm comm)