Yet Another eXchange Tool 0.11.1
Loading...
Searching...
No Matches
test_redist_repeat.c
/*
* Keywords:
* Maintainer: Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
* URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the DKRZ GmbH nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdbool.h>
#include <string.h>
#include <mpi.h>
#include <yaxt.h>
#include "tests.h"
#include "ctest_common.h"
#include "test_redist_common.h"
int main(int argc, char **argv) {
test_init_mpi(&argc, &argv, MPI_COMM_WORLD);
Xt_config config = redist_exchanger_option(&argc, &argv);
{ // general test with one redist
// set up data
enum { src_slice_len = 5, dst_slice_len = 3 };
Xt_xmap xmap = build_odd_selection_xmap(src_slice_len, comm);
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
// generate redist_repeatection
static const double src_data[] = {1,2,3,4,5};
double dst_data[dst_slice_len];
MPI_Aint src_extent = (MPI_Aint)(sizeof(src_data)),
dst_extent = (MPI_Aint)(sizeof(dst_data));
static const int displacements[1] = {0};
redist, src_extent, dst_extent, 1, displacements, config);
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
static const double ref_dst_data[] = {1,3,5};
check_redist(redist_repeat, src_data, dst_slice_len, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_repeat);
}
{
// 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(src_slice_len, comm);
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
// generate redist_repeatection
enum { num_repetitions = 3 };
static const double src_data[num_repetitions][src_slice_len]
= {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};
double dst_data[num_repetitions][dst_slice_len];
MPI_Aint src_extent =
(MPI_Aint)((size_t)(src_data[1] - src_data[0]) * sizeof (double));
MPI_Aint dst_extent =
(MPI_Aint)((size_t)(dst_data[1] - dst_data[0]) * sizeof (double));
static const int displacements[num_repetitions] = {0, 1, 2};
redist, src_extent, dst_extent,
num_repetitions, displacements, config);
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
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, fill_array_double, NULL, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_repeat);
}
{
// test with one redist used three times with asymmetric displacements
// set up data
enum { src_slice_len = 5, dst_slice_len = (src_slice_len+1)/2 };
Xt_xmap xmap = build_odd_selection_xmap(src_slice_len, comm);
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
// generate redist_repetition
enum { num_repetitions = 3 };
static const double src_data[num_repetitions][src_slice_len]
= {{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}};
double dst_data[num_repetitions][dst_slice_len];
MPI_Aint src_extent =
(MPI_Aint)((size_t)(src_data[1] - src_data[0]) * sizeof (double));
MPI_Aint dst_extent =
(MPI_Aint)((size_t)(dst_data[1] - dst_data[0]) * sizeof (double));
static const int src_displacements[num_repetitions] = {0, 1, 2},
dst_displacements[num_repetitions] = {2, 1, 0};
Xt_redist redist_repeat
= xt_redist_repeat_asym_custom_new(redist, src_extent, dst_extent,
num_repetitions, src_displacements,
dst_displacements, config);
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
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, fill_array_double, NULL, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_repeat);
}
{ // 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,
rep_dim_size = 5 };
Xt_xmap xmap = build_odd_selection_xmap(src_slice_len, comm);
Xt_redist redist = xt_redist_p2p_new(xmap, MPI_DOUBLE);
// generate redist_repeatection
MPI_Aint src_extent = (MPI_Aint)(src_slice_len * sizeof (double));
MPI_Aint dst_extent = (MPI_Aint)(dst_slice_len * sizeof (double));
static const int displacements[3] = {0, 2, 4};
redist, src_extent, dst_extent, 3, displacements, config);
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
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];
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, fill_array_double, NULL, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_repeat);
}
{ // test of redist_repeat generated with overlapping repetition of input redist
enum { npt = 9 };
Xt_xmap xmap = build_odd_selection_xmap(6, comm);
static const int src_pos[npt] = {1,2,3,4,5,6,7,8,9};
static const int dst_pos[npt] = {0,2,4,6,8,10,12,14,16};
xmap, src_pos, dst_pos, MPI_DOUBLE, config);
// init data
double src_data[npt], dst_data[npt];
static const double ref_dst_data[npt]
= {102.0, 103.0, 104.0, 105.0, 106.0, 107.0, -1.0, -1.0, -1.0};
for(int i = 0; i<npt; i++) src_data[i] = 100+i+1;
for (int j = 0; j < 2; ++j) {
for(int i = 0; i<npt; i++) dst_data[i] = -1;
// generate reference destination data: {102, 103, ..., 107, -1, -1, ... }
if (j == 0) {
xt_redist_s_exchange1(redist, src_data, dst_data);
xt_redist_s_exchange1(redist, src_data+1, dst_data+1);
} else {
Xt_request request[2];
xt_redist_a_exchange1(redist, src_data, dst_data, request+0);
xt_redist_a_exchange1(redist, src_data+1, dst_data+1, request+1);
xt_request_wait(&request[0]);
xt_request_wait(&request[1]);
}
// explicit check of ref data:
bool mismatch = false;
for(int i=0; i<npt; i++)
mismatch |= (dst_data[i] != ref_dst_data[i]);
if (mismatch)
PUT_ERR("error in xt_redist_repeat\n");
}
// generate redist_repeat
MPI_Aint src_extent = (MPI_Aint)(1 * sizeof (double));
MPI_Aint dst_extent = (MPI_Aint)(1 * sizeof (double));
static const int displacements[2] = {0,1};
redist, src_extent, dst_extent, 2, displacements, config);
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
check_redist(redist_repeat, src_data, npt, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_repeat);
}
MPI_Finalize();
return TEST_EXIT_CODE;
}
/*
* Local Variables:
* c-basic-offset: 2
* coding: utf-8
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
@ MPI_COMM_WORLD
Definition core.h:73
int MPI_Comm
Definition core.h:64
void xt_config_delete(Xt_config config)
Definition xt_config.c:84
void xt_initialize(MPI_Comm default_comm)
Definition xt_init.c:70
void xt_finalize(void)
Definition xt_init.c:92
void xt_redist_delete(Xt_redist redist)
Definition xt_redist.c:73
void xt_redist_a_exchange1(Xt_redist redist, const void *src_data, void *dst_data, Xt_request *request)
Definition xt_redist.c:96
MPI_Comm xt_redist_get_MPI_Comm(Xt_redist redist)
Definition xt_redist.c:129
void xt_redist_s_exchange1(Xt_redist redist, const void *src_data, void *dst_data)
Definition xt_redist.c:91
Xt_redist xt_redist_p2p_new(Xt_xmap xmap, MPI_Datatype datatype)
Xt_redist xt_redist_p2p_off_custom_new(Xt_xmap xmap, const int *src_offsets, const int *dst_offsets, MPI_Datatype datatype, Xt_config config)
Xt_redist xt_redist_repeat_custom_new(Xt_redist redist, MPI_Aint src_extent, MPI_Aint dst_extent, int num_repetitions, const int displacements[num_repetitions], Xt_config config)
Xt_redist xt_redist_repeat_asym_custom_new(Xt_redist redist, MPI_Aint src_extent, MPI_Aint dst_extent, int num_repetitions, const int src_displacements[num_repetitions], const int dst_displacements[num_repetitions], Xt_config config)
void xt_request_wait(Xt_request *request)
Definition xt_request.c:57
void xt_xmap_delete(Xt_xmap xmap)
Definition xt_xmap.c:86