From 777919eabc0add61d461c886c434ae6ca1ba4d34 Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Fri, 17 Nov 2023 22:33:36 +0100 Subject: [PATCH] add tests for isendrecv and isendrecv_replace --- .../smpi/mpich3-test/pt2pt/CMakeLists.txt | 4 +- teshsuite/smpi/mpich3-test/pt2pt/isendrecv.c | 69 ++++++++++++++++++ .../mpich3-test/pt2pt/isendrecv_replace.c | 70 +++++++++++++++++++ teshsuite/smpi/mpich3-test/pt2pt/testlist | 2 + 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 teshsuite/smpi/mpich3-test/pt2pt/isendrecv.c create mode 100644 teshsuite/smpi/mpich3-test/pt2pt/isendrecv_replace.c diff --git a/teshsuite/smpi/mpich3-test/pt2pt/CMakeLists.txt b/teshsuite/smpi/mpich3-test/pt2pt/CMakeLists.txt index d275f2ca0d..1c20021fea 100644 --- a/teshsuite/smpi/mpich3-test/pt2pt/CMakeLists.txt +++ b/teshsuite/smpi/mpich3-test/pt2pt/CMakeLists.txt @@ -5,7 +5,7 @@ if(enable_smpi AND enable_testsuite_smpi_MPICH3) include_directories(BEFORE "${CMAKE_HOME_DIRECTORY}/include/smpi") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../include/") - foreach(file anyall bottom eagerdt huge_anysrc huge_dupcomm huge_ssend huge_underflow inactivereq isendself isendirecv isendselfprobe issendselfcancel large_tag multi_psend_derived cancelanysrc pingping probenull + foreach(file anyall bottom eagerdt huge_anysrc huge_dupcomm huge_ssend huge_underflow inactivereq isendself isendrecv isendrecv_replace isendirecv isendselfprobe issendselfcancel large_tag multi_psend_derived cancelanysrc pingping probenull dtype_send greq1 probe-unexp rqstatus sendall sendflood sendrecv1 sendrecv2 sendrecv3 waitany-null waittestnull many_isend manylmt recv_any sendself scancel scancel2 rcancel bsend1 bsend2 bsend3 bsend4 bsend5 bsendalign bsendfrag bsendpending rqfreeb) # not compiled files: big_count_status mprobe # cancelrecv icsend large_message pscancel scancel_unmatch @@ -27,7 +27,7 @@ if(enable_smpi AND enable_testsuite_smpi_MPICH3) unset(name) endif() -foreach(file anyall bottom eagerdt huge_anysrc huge_dupcomm huge_ssend huge_underflow inactivereq +foreach(file anyall bottom eagerdt huge_anysrc huge_dupcomm huge_ssend huge_underflow inactivereq isendrecv isendrecv_replace isendself isendirecv isendselfprobe issendselfcancel large_tag multi_psend_derived pingping probenull probe-unexp sendall sendflood sendrecv1 sendrecv2 sendrecv3 waitany-null waittestnull big_count_status bsend1 bsend2 bsend3 bsend4 bsend5 bsendalign bsendfrag bsendpending diff --git a/teshsuite/smpi/mpich3-test/pt2pt/isendrecv.c b/teshsuite/smpi/mpich3-test/pt2pt/isendrecv.c new file mode 100644 index 0000000000..63512e662d --- /dev/null +++ b/teshsuite/smpi/mpich3-test/pt2pt/isendrecv.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) by Argonne National Laboratory + * See COPYRIGHT in top-level directory + */ + +#include "mpi.h" +#include +#include +#include "mpitest.h" + +/* Similar test as isendirecv.c, but use MPI_Isendrecv */ + +int errs = 0; +int elems = 20; +int rank, nproc, dest; +MPI_Comm comm; +float *in_buf, *out_buf; +MPI_Request *reqs; + +/* sendrecv may use the same or different source and destination, + * offset defines the offset between them */ +static void test_sendrecv(int offset) +{ + for (int i = 0; i < nproc; i++) { + for (int j = 0; j < elems; j++) { + in_buf[i * elems + j] = -1.0; + out_buf[i * elems + j] = rank * 10000.0 + i * 100.0 + j; + } + } + + for (int i = 0; i < nproc; i++) { + int j = (i + offset) % nproc; + MPI_Isendrecv(&out_buf[elems * i], elems, MPI_FLOAT, i, 0, + &in_buf[elems * j], elems, MPI_FLOAT, j, 0, comm, &reqs[i]); + } + + MPI_Waitall(nproc, reqs, MPI_STATUSES_IGNORE); + + for (int i = 0; i < nproc; i++) { + for (int j = 0; j < elems; j++) { + if (in_buf[i * elems + j] != i * 10000.0 + rank * 100.0 + j) { + errs++; + } + } + } +} + +int main(int argc, char *argv[]) +{ + MTest_Init(&argc, &argv); + + comm = MPI_COMM_WORLD; + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &nproc); + + reqs = malloc(nproc * sizeof(MPI_Request)); + in_buf = malloc(elems * nproc * sizeof(float)); + out_buf = malloc(elems * nproc * sizeof(float)); + + for (int offset = 0; offset < nproc - 1; offset++) { + test_sendrecv(offset); + } + + free(reqs); + free(in_buf); + free(out_buf); + MTest_Finalize(errs); + return MTestReturnValue(errs); +} diff --git a/teshsuite/smpi/mpich3-test/pt2pt/isendrecv_replace.c b/teshsuite/smpi/mpich3-test/pt2pt/isendrecv_replace.c new file mode 100644 index 0000000000..f0174c91cf --- /dev/null +++ b/teshsuite/smpi/mpich3-test/pt2pt/isendrecv_replace.c @@ -0,0 +1,70 @@ +/* + * Copyright (C) by Argonne National Laboratory + * See COPYRIGHT in top-level directory + */ + +#include "mpi.h" +#include +#include +#include "mpitest.h" + +/* Similar test as isendirecv.c, but use MPI_Isendrecv_replace */ + +int errs = 0; +int elems = 20; +int rank, nproc, dest; +float *buf; +MPI_Comm comm; +MPI_Request *reqs; + +static void test_sendrecv(int offset) +{ + for (int i = 0; i < nproc; i++) { + for (int j = 0; j < elems; j++) { + buf[i * elems + j] = rank * 100.0 + j; + } + } + + for (int i = 0; i < nproc; i++) { + int j = (i + offset) % nproc; + MPI_Isendrecv_replace(&buf[elems * j], elems, MPI_FLOAT, i, 0, j, 0, comm, &reqs[i]); + } + + MPI_Waitall(nproc, reqs, MPI_STATUSES_IGNORE); + + for (int i = 0; i < nproc; i++) { + for (int j = 0; j < elems; j++) { + if (buf[i * elems + j] != i * 100.0 + j) { + if (errs < 10) { + fprintf(stderr, "buf(%d, %d) mismatch, got %f, expect %f\n", i, j, + buf[i * elems + j], (float) (i * 100.0 + j)); + } + errs++; + } + } + } +} + +/* sendrecv may use the same or different source and destination, + * offset defines the offset between them */ + +int main(int argc, char *argv[]) +{ + MTest_Init(&argc, &argv); + + comm = MPI_COMM_WORLD; + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &nproc); + + reqs = malloc(nproc * sizeof(MPI_Request)); + buf = malloc(elems * nproc * sizeof(float)); + + for (int offset = 0; offset < nproc - 1; offset++) { + test_sendrecv(offset); + } + + free(reqs); + free(buf); + MTest_Finalize(errs); + return MTestReturnValue(errs); +} diff --git a/teshsuite/smpi/mpich3-test/pt2pt/testlist b/teshsuite/smpi/mpich3-test/pt2pt/testlist index 1e70308f97..0b79f5ef69 100644 --- a/teshsuite/smpi/mpich3-test/pt2pt/testlist +++ b/teshsuite/smpi/mpich3-test/pt2pt/testlist @@ -17,6 +17,8 @@ bsend4 1 bsendalign 2 bsendpending 2 isendself 1 +isendrecv 4 +isendrecv_replace 4 #issendselfcancel 1 isendirecv 10 bsendfrag 2 -- 2.20.1