Commit 6657fe70 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Reduce redundant test code.

parent d8a8b5fc
......@@ -111,6 +111,7 @@ libtestutil_la_SOURCES = tests.c \
test_xmap_common.c test_xmap_common.h \
test_xmap_common_parallel.c \
test_xmap_common_intercomm_parallel.c \
test_redist_single_array_base_common.c \
test_redist_common.h test_redist_common.c
libtestutil_f_la_SOURCES = ftest_common.f90 \
......
......@@ -163,6 +163,15 @@ fill_array_double(void *dst, const void *dst_prep_info, size_t dst_num_elems)
a[i] = -1;
}
void
fill_array_float(void *dst, const void *dst_prep_info, size_t dst_num_elems)
{
(void)dst_prep_info;
float *restrict a = dst;
for (size_t i = 0; i < dst_num_elems; ++i)
a[i] = -1;
}
void
fill_array_long(void *dst, const void *dst_prep_info, size_t dst_num_elems)
{
......
......@@ -82,11 +82,35 @@ check_redist_(Xt_redist redist, const void *src,
void
fill_array_double(void *dst, const void *dst_prep_info, size_t dst_num_elems);
void
fill_array_float(void *dst, const void *dst_prep_info, size_t dst_num_elems);
void
fill_array_long(void *dst, const void *dst_prep_info, size_t dst_num_elems);
void
fill_array_int(void *dst, const void *dst_prep_info, size_t dst_num_elems);
void
test_redist_single_array_base_(int nsend, const struct Xt_redist_msg *send_msgs,
int nrecv, const struct Xt_redist_msg *recv_msgs,
const void *src_data,
size_t num_dst,
void *dst_data,
prepare_dst dst_prep,
const void *dst_prep_info,
const void *ref_dst_data,
MPI_Datatype dst_data_dt,
MPI_Datatype ref_dst_data_dt,
MPI_Comm comm,
const char *file, int line);
#define test_redist_single_array_base(nsend, send_msgs, nrecv, recv_msgs, \
src_data, num_dst, dst_data, dst_prep, \
dst_prep_info, ref_dst_data, \
dst_data_dt, ref_dst_data_dt, comm) \
test_redist_single_array_base_(nsend, send_msgs, nrecv, recv_msgs, \
src_data, num_dst, dst_data, dst_prep, \
dst_prep_info, ref_dst_data, \
dst_data_dt, ref_dst_data_dt, comm, __FILE__, \
__LINE__)
void
wrap_a_exchange(Xt_redist redist, int num_data_p, const void *src_data_p[],
......
......@@ -73,53 +73,31 @@ int main(void) {
// single double
{
// send and receive messages
struct Xt_redist_msg send_msgs[] = { {.rank = 0, .datatype = MPI_DOUBLE} };
struct Xt_redist_msg recv_msgs[] = { {.rank = 0, .datatype = MPI_DOUBLE} };
static const struct Xt_redist_msg send_msgs[] = { {.rank = 0, .datatype = MPI_DOUBLE} },
recv_msgs[] = { {.rank = 0, .datatype = MPI_DOUBLE} };
enum { nsend = sizeof(send_msgs) / sizeof(send_msgs[0]) };
enum { nrecv = sizeof(recv_msgs) / sizeof(recv_msgs[0]) };
// redist_single_array_base
Xt_redist redist =
xt_redist_single_array_base_new(nsend, nrecv, send_msgs, recv_msgs, comm);
// test number of send messages
if (nsend != xt_redist_get_num_send_msg(redist))
PUT_ERR("error in xt_redist_get_num_send_msg\n");
// test number of recv messages
if (nrecv != xt_redist_get_num_recv_msg(redist))
PUT_ERR("error in xt_redist_get_num_recv_msg\n");
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
static const double src_data[] = {0};
static const double ref_dst_data[] = {0};
static const double src_data[] = {-5};
static const double ref_dst_data[] = {-5};
enum { num_ref_values = sizeof(ref_dst_data) / sizeof(ref_dst_data[0]) };
double dst_data[num_ref_values];
check_redist(redist, src_data, num_ref_values, dst_data,
fill_array_double, NULL, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
check_redist(redist_copy, src_data, num_ref_values, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_copy);
test_redist_single_array_base(nsend, send_msgs, nrecv, recv_msgs,
src_data, num_ref_values, dst_data,
fill_array_double, NULL, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE, comm);
}
// reverse order of some doubles
{
// generate datatypes
MPI_Datatype send_type, recv_type;
int recv_displs[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
static const int recv_displs[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
enum { nelem = sizeof(recv_displs) / sizeof(recv_displs[0]) };
xt_mpi_call(MPI_Type_contiguous(nelem, MPI_DOUBLE, &send_type), comm);
xt_mpi_call(MPI_Type_contiguous(nelem, MPI_FLOAT, &send_type), comm);
xt_mpi_call(MPI_Type_create_indexed_block(
nelem, 1, recv_displs, MPI_DOUBLE, &recv_type), comm);
nelem, 1, (int *)recv_displs, MPI_FLOAT, &recv_type), comm);
xt_mpi_call(MPI_Type_commit(&send_type), comm);
xt_mpi_call(MPI_Type_commit(&recv_type), comm);
......@@ -129,38 +107,18 @@ int main(void) {
enum { nsend = sizeof(send_msgs) / sizeof(send_msgs[0]) };
enum { nrecv = sizeof(recv_msgs) / sizeof(recv_msgs[0]) };
// redist_single_array_base
Xt_redist redist =
xt_redist_single_array_base_new(nsend, nrecv, send_msgs, recv_msgs, comm);
xt_mpi_call(MPI_Type_free(&recv_type), comm);
xt_mpi_call(MPI_Type_free(&send_type), comm);
// test number of send messages
if (nsend != xt_redist_get_num_send_msg(redist))
PUT_ERR("error in xt_redist_get_num_send_msg\n");
// test number of recv messages
if (nrecv != xt_redist_get_num_recv_msg(redist))
PUT_ERR("error in xt_redist_get_num_recv_msg\n");
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
static const double src_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
static const double ref_dst_data[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
static const float src_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
static const float ref_dst_data[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
enum { num_ref_values = sizeof(ref_dst_data) / sizeof(ref_dst_data[0]) };
double dst_data[num_ref_values];
check_redist(redist, src_data, num_ref_values, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
check_redist(redist_copy, src_data, num_ref_values, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
float dst_data[num_ref_values];
test_redist_single_array_base(nsend, send_msgs, nrecv, recv_msgs,
src_data, num_ref_values, dst_data,
fill_array_float, NULL, ref_dst_data,
MPI_FLOAT, MPI_FLOAT, comm);
// clean up
xt_redist_delete(redist_copy);
xt_mpi_call(MPI_Type_free(&recv_type), comm);
xt_mpi_call(MPI_Type_free(&send_type), comm);
}
xt_finalize();
......
/**
* @file test_redist_single_array_base_common.c
*
* @copyright Copyright (C) 2020 Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
*
* @author Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
*/
/*
* Keywords:
* Maintainer: Jörg Behrens <behrens@dkrz.de>
* Moritz Hanke <hanke@dkrz.de>
* Thomas Jahns <jahns@dkrz.de>
* URL: https://doc.redmine.dkrz.de/yaxt/html/
*
* 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.
*/
#include "yaxt.h"
#include "tests.h"
#include "test_redist_common.h"
void
test_redist_single_array_base_(int nsend, const struct Xt_redist_msg *send_msgs,
int nrecv, const struct Xt_redist_msg *recv_msgs,
const void *src_data,
size_t num_dst,
void *dst_data,
prepare_dst dst_prep,
const void *dst_prep_info,
const void *ref_dst_data,
MPI_Datatype dst_data_dt,
MPI_Datatype ref_dst_data_dt,
MPI_Comm comm,
const char *file, int line)
{
Xt_redist redist =
xt_redist_single_array_base_new(nsend, nrecv, send_msgs, recv_msgs, comm);
// test number of send messages
if (nsend != xt_redist_get_num_send_msg(redist))
PUT_ERR("error in xt_redist_get_num_send_msg\n");
// test number of recv messages
if (nrecv != xt_redist_get_num_recv_msg(redist))
PUT_ERR("error in xt_redist_get_num_recv_msg\n");
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
check_redist_(redist, src_data, num_dst, dst_data,
dst_prep, dst_prep_info, ref_dst_data,
dst_data_dt, ref_dst_data_dt, file, line);
{
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
redist = redist_copy;
}
check_redist_(redist, src_data, num_dst, dst_data,
dst_prep, dst_prep_info, ref_dst_data,
dst_data_dt, ref_dst_data_dt, file, line);
xt_redist_delete(redist);
}
......@@ -83,21 +83,6 @@ int main(void) {
enum { nrecv = sizeof(recv_msgs) / sizeof(recv_msgs[0]) };
// redist_single_array_base
Xt_redist redist =
xt_redist_single_array_base_new(nsend, nrecv, send_msgs, recv_msgs, comm);
// test number of send messages
if (nsend != xt_redist_get_num_send_msg(redist))
PUT_ERR("error in xt_redist_get_num_send_msg\n");
// test number of recv messages
if (nrecv != xt_redist_get_num_recv_msg(redist))
PUT_ERR("error in xt_redist_get_num_recv_msg\n");
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
double src_data[1];
enum { num_dst_values = 1 };
......@@ -105,15 +90,10 @@ int main(void) {
double dst_data[num_dst_values];
src_data[0] = rank;
ref_dst_data[0] = (rank + size - 1)%size;
check_redist(redist, src_data, num_dst_values, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
check_redist(redist_copy, src_data, num_dst_values, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
// clean up
xt_redist_delete(redist_copy);
test_redist_single_array_base(nsend, send_msgs, nrecv, recv_msgs,
src_data, num_dst_values, dst_data,
fill_array_double, NULL, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE, comm);
}
// allgather
......@@ -138,34 +118,16 @@ int main(void) {
}
// redist_single_array_base
Xt_redist redist =
xt_redist_single_array_base_new(nsend, nrecv, send_msgs, recv_msgs, comm);
// test number of send messages
if (nsend != xt_redist_get_num_send_msg(redist))
PUT_ERR("error in xt_redist_get_num_send_msg\n");
// test number of recv messages
if (nrecv != xt_redist_get_num_recv_msg(redist))
PUT_ERR("error in xt_redist_get_num_recv_msg\n");
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
double src_data[1];
double *ref_dst_data = xmalloc((size_t)size * sizeof(*ref_dst_data));
double *dst_data = xmalloc((size_t)size * sizeof(*dst_data));
src_data[0] = rank;
for (int i = 0; i < size; ++i) ref_dst_data[i] = i;
check_redist(redist, src_data, (size_t)size, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
check_redist(redist_copy, src_data, (size_t)size, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
test_redist_single_array_base(nsend, send_msgs, nrecv, recv_msgs,
src_data, (size_t)size, dst_data,
fill_array_double, NULL, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE, comm);
// clean up
free(dst_data);
free(ref_dst_data);
......@@ -173,7 +135,6 @@ int main(void) {
xt_mpi_call(MPI_Type_free(&(recv_msgs[i].datatype)), comm);
free(recv_msgs);
free(send_msgs);
xt_redist_delete(redist_copy);
}
// scatter by rank 0
......@@ -194,22 +155,6 @@ int main(void) {
}
}
// redist_single_array_base
Xt_redist redist =
xt_redist_single_array_base_new(nsend, nrecv, send_msgs, recv_msgs, comm);
// test number of send messages
if (nsend != xt_redist_get_num_send_msg(redist))
PUT_ERR("error in xt_redist_get_num_send_msg\n");
// test number of recv messages
if (nrecv != xt_redist_get_num_recv_msg(redist))
PUT_ERR("error in xt_redist_get_num_recv_msg\n");
// test communicator of redist
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist), comm))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
double *src_data = xmalloc((size_t)nsend * sizeof(*src_data));
enum { num_dst_values = 1 };
......@@ -217,19 +162,18 @@ int main(void) {
double dst_data[num_dst_values];
if (rank == 0) for (int i = 0; i < size; ++i) src_data[i] = i;
ref_dst_data[0] = rank;
check_redist(redist, src_data, num_dst_values, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
Xt_redist redist_copy = xt_redist_copy(redist);
xt_redist_delete(redist);
check_redist(redist_copy, src_data, num_dst_values, dst_data,
fill_array_double, NULL, ref_dst_data, MPI_DOUBLE, MPI_DOUBLE);
test_redist_single_array_base(nsend, send_msgs, nrecv, recv_msgs,
src_data, num_dst_values, dst_data,
fill_array_double, NULL, ref_dst_data,
MPI_DOUBLE, MPI_DOUBLE, comm);
// clean up
free(src_data);
for (int i = 0; i < nsend; ++i)
xt_mpi_call(MPI_Type_free(&(send_msgs[i].datatype)), comm);
free(send_msgs);
xt_redist_delete(redist_copy);
}
xt_finalize();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment