#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <mpi.h>
#include <yaxt.h>
#include "tests.h"
#include "ctest_common.h"
#include "test_idxlist_utils.h"
#include "test_redist_common.h"
enum {
list_a = 0,
list_b = 1,
list_all = 2,
};
static void
static void
int main(int argc, char **argv) {
Xt_config config = redist_exchanger_option(&argc, &argv);
int comm_size;
if (comm_size > 1) {
}
MPI_Finalize();
return TEST_EXIT_CODE;
}
enum { num_redists = 4 };
static void
int sync);
static void
{
int comm_rank, comm_size;
&& comm_size <= INT_MAX / comm_size);
int comm_size_sq = comm_size * comm_size;
{
int local_size[2] = { comm_size, comm_size };
};
for (size_t i = 0; i < 2; ++i)
local_start[i]);
}
{
};
}
{
&& 2 <= INT_MAX / comm_size_sq / comm_size);
.nstrides = 2*comm_size_sq*comm_size };
}
const int list_sizes[3]
= { 2*comm_size_sq, 2*comm_size_sq, 2 * comm_size_sq * comm_size };
for (size_t i = 0; i < 2; ++i)
index_vector[i] =
xmalloc((
size_t)list_sizes[i] *
sizeof (
Xt_int));
};
for (size_t i = 0; i < num_redists; ++i)
comm, config);
comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
for (size_t i = 0; i < num_redists; ++i)
exchange_4redist(redist, comm, index_vector[list_a], index_vector[list_b], 0);
exchange_4redist(redist, comm, index_vector[list_a], index_vector[list_b], 1);
exchange_4redist(redist_copy, comm,
index_vector[list_a], index_vector[list_b], 0);
exchange_4redist(redist_copy, comm,
index_vector[list_a], index_vector[list_b], 1);
for (size_t i = 0; i < 2; ++i)
free(index_vector[i]);
}
static void
check_4redist_result(int size, void *results[4],
const Xt_int *index_vector_b);
static void
int sync)
{
int comm_rank, comm_size;
size_t comm_size_ = (size_t)comm_size;
assert(comm_size_ <= SIZE_MAX / comm_size_ / comm_size_);
size_t comm_size_sq_ = comm_size_ * comm_size_,
comm_size_cb_ = comm_size_sq_ * comm_size_;
const size_t result_sizes[num_redists] =
{ 2 * comm_size_sq_,
2 * comm_size_sq_,
2 * comm_size_cb_,
2 * comm_size_cb_ };
const size_t spacing[num_redists] = { 2, 14, 5, 8 };
size_t buf_size = 0;
for (size_t i = 0; i < num_redists; ++i)
buf_size += spacing[i] + result_sizes[i];
unsigned char *temp = buf;
void *results[num_redists];
results[0] = (
void *)(temp += spacing[0] *
sizeof (
Xt_int));
for (size_t i = 1; i < num_redists; ++i)
results[i] = (void *)(
temp += (result_sizes[i-1] + spacing[i]) *
sizeof (
Xt_int));
const void *input[num_redists]
= { index_vector_a, index_vector_b, index_vector_a, index_vector_b };
exchange_func_ptr exchange_func
exchange_func(redist, num_redists, input, results);
check_4redist_result(comm_size, results, index_vector_a,
index_vector_b);
if (comm_rank == 0)
results[0] = buf;
exchange_func(redist, num_redists, input, results);
check_4redist_result(comm_size, results, index_vector_a, index_vector_b);
free(buf);
}
static void
check_4redist_result(int comm_size, void *results[4],
{
size_t comm_size_ = (size_t)comm_size,
comm_size_sq_ = comm_size_ * comm_size_,
comm_size_cb_ = comm_size_sq_ * comm_size_;
if (cmp_idx_arrays(2 * comm_size_sq_, (
Xt_int *)results[0], index_vector_b))
PUT_ERR("error on xt_redist_s_exchange\n");
if (cmp_idx_arrays(2 * comm_size_sq_, (
Xt_int *)results[1], index_vector_a))
PUT_ERR("error on xt_redist_s_exchange\n");
bool mismatch = false;
for (size_t i = 0; i < 2*comm_size_cb_; ++i)
if (mismatch)
PUT_ERR("error on xt_redist_s_exchange\n");
mismatch = false;
for (size_t i = 0; i < 2*comm_size_cb_; ++i)
if (mismatch)
PUT_ERR("error on xt_redist_s_exchange\n");
}
enum { elems_per_rank = 5, };
static void
{
int comm_rank, comm_size;
Xt_int src_indices_[elems_per_rank], dst_indices_[2][elems_per_rank];
for (
Xt_int i = 0; i < elems_per_rank; ++i) {
src_indices_[i] = (
Xt_int)(comm_rank * elems_per_rank + i);
dst_indices_[0][i]
= (
Xt_int)((src_indices_[i] + 1) % (comm_size * elems_per_rank));
dst_indices_[1][i]
= (
Xt_int)((temp < 0)?(comm_size * elems_per_rank - 1):temp);
}
for (size_t i = 0; i < 2; ++i) {
}
config);
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
for (size_t i = 0; i < 2; ++i)
Xt_int results_[2][elems_per_rank];
void *results[2] = {results_[0], results_[1]};
const void *input[2] = {src_indices_, src_indices_};
check_redist_coll(redist, sync_mode_test_all,
2, input, 2 * elems_per_rank, results,
results_, fill_array_xt_int, NULL,
check_redist_coll(redist_copy, sync_mode_test_all,
2, input, 2 * elems_per_rank, results,
results_, fill_array_xt_int, NULL,
}
add versions of standard API functions not returning on error
void xt_config_delete(Xt_config config)
void xt_initialize(MPI_Comm default_comm)
void xt_idxlist_get_indices(Xt_idxlist idxlist, Xt_int *indices)
void xt_idxlist_delete(Xt_idxlist idxlist)
Xt_idxlist xt_idxlist_collection_new(Xt_idxlist *idxlists, int num_idxlists)
Xt_idxlist xt_idxsection_new(Xt_int start, int num_dimensions, const Xt_int global_size[num_dimensions], const int local_size[num_dimensions], const Xt_int local_start[num_dimensions])
Xt_idxlist xt_idxstripes_new(struct Xt_stripe const *stripes, int num_stripes)
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)
Xt_redist xt_redist_copy(Xt_redist redist)
void xt_redist_s_exchange(Xt_redist redist, int num_arrays, const void *const src_data[], void *const dst_data[])
MPI_Comm xt_redist_get_MPI_Comm(Xt_redist redist)
Xt_redist xt_redist_collection_custom_new(Xt_redist *redists, int num_redists, int cache_size, MPI_Comm comm, Xt_config config)
Xt_redist xt_redist_p2p_new(Xt_xmap xmap, MPI_Datatype datatype)
void xt_xmap_delete(Xt_xmap xmap)
Xt_xmap xt_xmap_all2all_new(Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm comm)