Commit 34b48b15 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Factor out communicator congruency test.

parent 1fef3fe6
......@@ -59,10 +59,6 @@
static void
test_repeated_redist(int cache_size);
static int
test_communicator(MPI_Comm comm1, MPI_Comm comm2);
static void
test_displacement_variations(void);
......@@ -91,7 +87,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist_coll), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......@@ -158,7 +155,8 @@ test_repeated_redist(int cache_size)
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist_coll), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......@@ -225,15 +223,6 @@ test_repeated_redist(int cache_size)
xt_redist_delete(redist_coll);
}
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2) {
int result;
xt_mpi_call(MPI_Comm_compare(comm1, comm2, &result), MPI_COMM_WORLD);
return ((result == MPI_IDENT) || (result == MPI_CONGRUENT));
}
enum { num_redists = 3 };
enum { nvalues = 5, nselect = nvalues/2+(nvalues&1) };
......@@ -297,7 +286,8 @@ test_displacement_variations(void)
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist_coll), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......
......@@ -57,8 +57,7 @@
#include "tests.h"
#include "test_idxlist_utils.h"
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2);
#include "test_redist_common.h"
static void
exchange_4redist(Xt_redist redist, MPI_Comm comm,
......@@ -170,7 +169,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
......@@ -227,7 +227,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redists[0]), xt_redist_delete(redists[1]);
......@@ -249,16 +250,6 @@ int main(void) {
return TEST_EXIT_CODE;
}
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2) {
int result;
xt_mpi_call(MPI_Comm_compare(comm1, comm2, &result), MPI_COMM_WORLD);
return ((result == MPI_IDENT) || (result == MPI_CONGRUENT));
}
static void
check_4redist_result(int size, void *results[4],
const Xt_int *index_vector_a,
......
......@@ -53,8 +53,6 @@
#include "tests.h"
#include "test_redist_common.h"
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2);
int main(void) {
// init mpi
......@@ -84,7 +82,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist_coll), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......@@ -127,7 +126,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist_coll), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_coll),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......@@ -164,12 +164,3 @@ int main(void) {
return TEST_EXIT_CODE;
}
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2) {
int result;
xt_mpi_call(MPI_Comm_compare(comm1, comm2, &result), MPI_COMM_WORLD);
return ((result == MPI_IDENT) || (result == MPI_CONGRUENT));
}
......@@ -57,8 +57,8 @@
#include <yaxt.h>
#include "tests.h"
#include "test_redist_common.h"
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2);
static void
test_transpose_gather(Xt_redist redist,
Xt_int *dst, const Xt_int *src,
......@@ -181,7 +181,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
for (size_t i = 0; i < 4; ++i)
......@@ -243,7 +244,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redists[0]), xt_redist_delete(redists[1]);
......@@ -271,15 +273,6 @@ int main(void) {
return TEST_EXIT_CODE;
}
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2) {
int result;
xt_mpi_call(MPI_Comm_compare(comm1, comm2, &result), MPI_COMM_WORLD);
return ((result == MPI_IDENT) || (result == MPI_CONGRUENT));
}
static void
test_transpose_gather(Xt_redist redist,
Xt_int *dst, const Xt_int *src,
......
......@@ -81,6 +81,17 @@ build_odd_selection_xmap(int src_num_indices)
return xmap;
}
int communicators_are_congruent(MPI_Comm comm1, MPI_Comm comm2) {
int result;
xt_mpi_call(MPI_Comm_compare(comm1, comm2, &result), MPI_COMM_WORLD);
return ((result == MPI_IDENT) || (result == MPI_CONGRUENT));
}
void
check_redist(Xt_redist redist, const void *src,
size_t dst_size, void *dst, const void *ref_dst_data)
......
......@@ -55,6 +55,8 @@
Xt_xmap
build_odd_selection_xmap(int src_num_indices);
int communicators_are_congruent(MPI_Comm comm1, MPI_Comm comm2);
void
check_redist(Xt_redist redist, const void *src,
size_t dst_size, void *dst, const void *ref_dst_data);
......
......@@ -58,7 +58,7 @@ MODULE test_redist_common
MODULE PROCEDURE check_redist_dp2
MODULE PROCEDURE check_redist_dp2_2d
END INTERFACE check_redist
PUBLIC :: build_odd_selection_xmap, check_redist
PUBLIC :: build_odd_selection_xmap, check_redist, communicators_are_congruent
CONTAINS
! build xmap for destination list containing all odd elements of
! source list dimensioned 1 to src_slice_len
......@@ -89,6 +89,16 @@ CONTAINS
CALL xt_idxlist_delete(dst_idxlist)
END FUNCTION build_odd_selection_xmap
FUNCTION communicators_are_congruent(comm1, comm2) RESULT(congruent)
INTEGER, INTENT(in) :: comm1, comm2
LOGICAL :: congruent
INTEGER :: ierror, rcode
CALL mpi_comm_compare(comm1, comm2, rcode, ierror)
congruent = ((rcode == mpi_ident) .OR. (rcode == mpi_congruent))
END FUNCTION communicators_are_congruent
SUBROUTINE check_redist_dp(redist, src, dst_size, dst, ref_dst)
TYPE(xt_redist), INTENT(in) :: redist
INTEGER, INTENT(in) :: dst_size
......
......@@ -57,8 +57,8 @@
#include <yaxt.h>
#include "tests.h"
#include "test_redist_common.h"
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2);
static void
run_redist_test(Xt_redist redist, const void *src_data, size_t elem_size,
size_t num_values, const void *restrict ref_values);
......@@ -96,7 +96,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
......@@ -150,7 +151,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
......@@ -203,7 +205,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
......@@ -250,16 +253,6 @@ run_redist_test(Xt_redist redist, const void *src_data, size_t elem_size,
free(dst_data);
}
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2) {
int result;
xt_mpi_call(MPI_Comm_compare(comm1, comm2, &result), MPI_COMM_WORLD);
return ((result == MPI_IDENT) || (result == MPI_CONGRUENT));
}
/*
* Local Variables:
* c-basic-offset: 2
......
......@@ -54,7 +54,7 @@ PROGRAM test_redist_p2p_f
xt_redist_copy, xt_redist_delete, xt_redist_get_mpi_comm, &
xt_xmap_all2all_new, xt_xmap_delete
USE ftest_common, ONLY: init_mpi, finish_mpi, test_abort
USE test_redist_common, ONLY: check_redist
USE test_redist_common, ONLY: check_redist, communicators_are_congruent
USE test_idxlist_utils, ONLY: test_err_count
IMPLICIT NONE
......@@ -124,7 +124,7 @@ CONTAINS
redist = xt_redist_p2p_new(xmap, mpi_double_precision)
! test communicator of redist
IF (.NOT. test_communicator(xt_redist_get_mpi_comm(redist), &
IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(redist), &
mpi_comm_world)) &
CALL test_abort("error in xt_redist_get_MPI_Comm", &
__FILE__, &
......@@ -212,7 +212,7 @@ CONTAINS
redist = xt_redist_p2p_off_new(xmap, src_pos, dst_pos, mpi_double_precision)
! test communicator of redist
IF (.NOT. test_communicator(xt_redist_get_mpi_comm(redist), &
IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(redist), &
mpi_comm_world)) &
CALL test_abort("error in xt_redist_get_MPI_Comm", &
__FILE__, &
......@@ -267,7 +267,7 @@ CONTAINS
redist = xt_redist_p2p_ext_new(xmap, &
src_pos, dst_pos, xt_int_mpidt)
! test communicator of redist
IF (.NOT. test_communicator(xt_redist_get_MPI_Comm(redist), &
IF (.NOT. communicators_are_congruent(xt_redist_get_MPI_Comm(redist), &
mpi_comm_world)) &
CALL test_abort("error in xt_redist_get_MPI_Comm", &
__FILE__, &
......@@ -308,15 +308,6 @@ CONTAINS
__LINE__)
END SUBROUTINE offset_extents_exchange_check
FUNCTION test_communicator(comm1, comm2) RESULT(congruent)
INTEGER, INTENT(in) :: comm1, comm2
LOGICAL :: congruent
INTEGER :: ierror, rcode
CALL mpi_comm_compare(comm1, comm2, rcode, ierror)
congruent = ((rcode == mpi_ident) .OR. (rcode == mpi_congruent))
END FUNCTION test_communicator
END PROGRAM test_redist_p2p_f
!
! Local Variables:
......
......@@ -55,8 +55,7 @@
#include <yaxt.h>
#include "tests.h"
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2);
#include "test_redist_common.h"
int main(void) {
......@@ -100,7 +99,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
......@@ -168,7 +168,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
......@@ -257,7 +258,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
int a_surfdata[nwin];
......@@ -350,7 +352,8 @@ int main(void) {
MPI_INT);
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(block_redist), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(block_redist),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_s_exchange1(block_redist, a_voldata, b_voldata);
......@@ -369,7 +372,8 @@ int main(void) {
MPI_INT);
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(block_redist2), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(block_redist2),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
for (int i = 0; i < gvol_size; i++) {
......@@ -398,12 +402,3 @@ int main(void) {
return TEST_EXIT_CODE;
}
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2) {
int result;
xt_mpi_call(MPI_Comm_compare(comm1, comm2, &result), MPI_COMM_WORLD);
return ((result == MPI_IDENT) || (result == MPI_CONGRUENT));
}
......@@ -55,6 +55,7 @@ PROGRAM test_redist_p2p_parallel
xt_redist_s_exchange1, xt_redist_delete, &
xt_redist_p2p_blocks_off_new, xt_redist_p2p_blocks_new
USE test_idxlist_utils, ONLY: test_err_count
USE test_redist_common, ONLY: communicators_are_congruent
IMPLICIT NONE
INTEGER :: rank, size, ierror
......@@ -117,7 +118,7 @@ CONTAINS
redist = xt_redist_p2p_new(xmap, mpi_double_precision)
! test communicator of redist
IF (.NOT. test_communicator(xt_redist_get_mpi_comm(redist), &
IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(redist), &
mpi_comm_world)) &
CALL test_abort("error in xt_redist_get_mpi_comm", &
__FILE__, &
......@@ -177,7 +178,7 @@ CONTAINS
redist = xt_redist_p2p_new(xmap, mpi_double_precision)
! test communicator of redist
IF (.NOT. test_communicator(xt_redist_get_mpi_comm(redist), &
IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(redist), &
mpi_comm_world)) &
CALL test_abort("error in xt_redist_get_mpi_comm", &
__FILE__, &
......@@ -273,7 +274,7 @@ CONTAINS
redist = xt_redist_p2p_new(xmap, mpi_integer)
! test communicator of redist
IF (.NOT. test_communicator(xt_redist_get_mpi_comm(redist), &
IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(redist), &
mpi_comm_world)) &
CALL test_abort("error in xt_redist_get_mpi_comm", &
__FILE__, &
......@@ -354,7 +355,7 @@ CONTAINS
src_block_offsets, src_block_sizes, nwin, &
dst_block_offsets, dst_block_sizes, nwin, mpi_integer)
! test communicator of redist
IF (.NOT. test_communicator(xt_redist_get_mpi_comm(block_redist), &
IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(block_redist), &
mpi_comm_world)) &
CALL test_abort("error in xt_redist_get_mpi_comm", &
__FILE__, &
......@@ -373,7 +374,7 @@ CONTAINS
src_block_sizes, nwin, dst_block_sizes, nwin, mpi_integer)
! test communicator of redist
IF (.NOT. test_communicator(xt_redist_get_mpi_comm(block_redist2), &
IF (.NOT. communicators_are_congruent(xt_redist_get_mpi_comm(block_redist2), &
mpi_comm_world)) &
CALL test_abort("error in xt_redist_get_mpi_comm", &
__FILE__, &
......@@ -397,16 +398,4 @@ CONTAINS
CALL xt_idxlist_delete(idxlist_b)
END SUBROUTINE block_redist_test
FUNCTION test_communicator(comm1, comm2) RESULT(p)
INTEGER, INTENT(in) :: comm1, comm2
LOGICAL :: p
INTEGER :: cmpres, ierror
CALL mpi_comm_compare(comm1, comm2, cmpres, ierror)
IF (ierror /= mpi_success) &
CALL test_abort("MPI error!", &
__FILE__, &
__LINE__)
p = ((cmpres == MPI_IDENT) .OR. (cmpres == MPI_CONGRUENT))
END FUNCTION test_communicator
END PROGRAM test_redist_p2p_parallel
......@@ -56,8 +56,6 @@
#include "tests.h"
#include "test_redist_common.h"
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2);
int main(void) {
......@@ -88,7 +86,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist_repeat), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......@@ -129,7 +128,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist_repeat), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......@@ -176,7 +176,8 @@ int main(void) {
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist_repeat), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist);
......@@ -238,7 +239,8 @@ int main(void) {
= xt_redist_repeat_new(redist, src_extent, dst_extent, 2, displacements);
// test communicator of redist
if (!test_communicator(xt_redist_get_MPI_Comm(redist_repeat), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
// test exchange
......@@ -257,15 +259,6 @@ int main(void) {
return TEST_EXIT_CODE;
}
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2) {
int result;
xt_mpi_call(MPI_Comm_compare(comm1, comm2, &result), MPI_COMM_WORLD);
return ((result == MPI_IDENT) || (result == MPI_CONGRUENT));
}
/*
* Local Variables:
* c-basic-offset: 2
......
......@@ -52,8 +52,7 @@
#include <yaxt.h>
#include "tests.h"
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2);
#include "test_redist_common.h"
int main(void) {
......@@ -138,9 +137,11 @@ int main(void) {
// test communicator of redist_repeat
if (!test_communicator(xt_redist_get_MPI_Comm(redist_repeat), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
if (!test_communicator(xt_redist_get_MPI_Comm(redist_repeat_2), MPI_COMM_WORLD))
if (!communicators_are_congruent(xt_redist_get_MPI_Comm(redist_repeat_2),
MPI_COMM_WORLD))
PUT_ERR("error in xt_redist_get_MPI_Comm\n");
xt_redist_delete(redist_p2p);
......@@ -172,12 +173,3 @@ int main(void) {
return TEST_EXIT_CODE;
}
static int test_communicator(MPI_Comm comm1, MPI_Comm comm2) {
int result;
xt_mpi_call(MPI_Comm_compare(comm1, comm2, &result), MPI_COMM_WORLD);
return ((result == MPI_IDENT) || (result == MPI_CONGRUENT));
}
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