From f9121e359e7d9461d6ece5a3cf8077200fbd02bc Mon Sep 17 00:00:00 2001 From: Hui Zhou Date: Tue, 16 Feb 2021 21:26:11 -0600 Subject: [PATCH] test: add basic large API tests --- test/mpi/coll/Makefile.am | 1 + test/mpi/coll/coll_large.c | 67 +++++++++++++++++ test/mpi/coll/testlist.in | 2 + test/mpi/datatype/Makefile.am | 1 + test/mpi/datatype/testlist.in | 1 + test/mpi/datatype/type_large.c | 130 +++++++++++++++++++++++++++++++++ test/mpi/pt2pt/Makefile.am | 1 + test/mpi/pt2pt/pt2pt_large.c | 71 ++++++++++++++++++ test/mpi/pt2pt/testlist.in | 1 + 9 files changed, 275 insertions(+) create mode 100644 test/mpi/coll/coll_large.c create mode 100644 test/mpi/datatype/type_large.c create mode 100644 test/mpi/pt2pt/pt2pt_large.c diff --git a/test/mpi/coll/Makefile.am b/test/mpi/coll/Makefile.am index e311d8a9387..9d05ad4e0df 100644 --- a/test/mpi/coll/Makefile.am +++ b/test/mpi/coll/Makefile.am @@ -126,6 +126,7 @@ noinst_PROGRAMS = \ neighb_alltoallw \ bcast \ bcast_comm_world_only \ + coll_large \ ring_neighbor_alltoall allgatherv4_LDADD = $(LDADD) -lm diff --git a/test/mpi/coll/coll_large.c b/test/mpi/coll/coll_large.c new file mode 100644 index 00000000000..56b9a4baea3 --- /dev/null +++ b/test/mpi/coll/coll_large.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) by Argonne National Laboratory + * See COPYRIGHT in top-level directory + */ + +#include "mpi.h" +#include "mpitest.h" +#include +#include +#include + +/* + Basic test for collective large APIs. + It is only intended to test the API interface rather than stress testing the internals. + */ + +#define MAX_SIZE 1024 +#define MAX_PROC 20 + +MPI_Comm comm; +int rank, nprocs; +int errs; +int sendbuf[MAX_SIZE]; +int recvbuf[MAX_SIZE]; + +static void init_buf(void) +{ + for (int i = 0; i < MAX_SIZE; i++) { + sendbuf[i] = i; + } + for (int i = 0; i < MAX_SIZE; i++) { + recvbuf[i] = -1; + } +} + +static void test_alltoallv(void) +{ + MPI_Count counts[MAX_PROC]; + MPI_Count displs[MAX_PROC]; + for (int i = 0; i < nprocs; i++) { + counts[i] = 1; + } + for (int i = 0; i < nprocs; i++) { + displs[i] = i * 3; + } + init_buf(); + MPI_Alltoallv_c(sendbuf, counts, displs, MPI_INT, recvbuf, counts, displs, MPI_INT, comm); + /* check results */ + for (int i = 0; i < nprocs, i++) { + if (recvbuf[displs[i]] != rank * 3) { + errs++; + } + } +} + +int main(int argc, char **argv) +{ + MTest_Init(&argc, &argv); + comm = MPI_COMM_WORLD; + MPI_Comm_size(comm, &nprocs); + MPI_Comm_rank(comm, &rank); + + test_alltoallv(); + + MTest_Finalize(errs); + return MTestReturnValue(errs); +} diff --git a/test/mpi/coll/testlist.in b/test/mpi/coll/testlist.in index 13b87dc896b..1719c393d55 100644 --- a/test/mpi/coll/testlist.in +++ b/test/mpi/coll/testlist.in @@ -174,3 +174,5 @@ ring_neighbor_alltoall 1 # Tests for persistent collectives p_bcast 4 strict=false p_bcast2 8 strict=false + +coll_large 8 diff --git a/test/mpi/datatype/Makefile.am b/test/mpi/datatype/Makefile.am index b2756b753c9..90d0a7db343 100644 --- a/test/mpi/datatype/Makefile.am +++ b/test/mpi/datatype/Makefile.am @@ -35,6 +35,7 @@ noinst_PROGRAMS = \ large_type \ large_type_sendrec \ large_vec \ + type_large \ lbub \ lbub_oldapi \ localpack \ diff --git a/test/mpi/datatype/testlist.in b/test/mpi/datatype/testlist.in index 2de54a6f59c..6ff5142d1ae 100644 --- a/test/mpi/datatype/testlist.in +++ b/test/mpi/datatype/testlist.in @@ -61,6 +61,7 @@ vecblklen 1 hvecblklen 1 longdouble 1 dataalign 2 +type_large 1 @largetest@large_count 1 cxx_types 1 @largetest@large_type 1 diff --git a/test/mpi/datatype/type_large.c b/test/mpi/datatype/type_large.c new file mode 100644 index 00000000000..9106479a33d --- /dev/null +++ b/test/mpi/datatype/type_large.c @@ -0,0 +1,130 @@ +/* + * Copyright (C) by Argonne National Laboratory + * See COPYRIGHT in top-level directory + */ + +#include +#include +#include +#include "mpitest.h" + +/* Basic test to test MPI 4.0 large API */ + +static MPI_Datatype make_large_contig(MPI_Count nbytes) +{ + MPI_Datatype newtype; + MPI_Type_contiguous_c(nbytes, MPI_CHAR, &newtype); + MPI_Type_commit(&newtype); + return newtype; +} + +static MPI_Datatype make_largexfer_type_indexed_block(MPI_Count nbytes) +{ + MPI_Datatype newtype; + +#undef NBLK +#define NBLK 256 + MPI_Count num_blks = NBLK; + MPI_Count blklen = nbytes / num_blks / sizeof(int); + MPI_Count displs[NBLK]; + + if (num_blks * blklen * sizeof(int) != nbytes) { + return MPI_DATATYPE_NULL; + } + + for (int i = 0; i < NBLK; i++) { + displs[i] = i * blklen; + } + + MPI_Type_create_indexed_block_c(NBLK, blklen, displs, MPI_INT, &newtype); + MPI_Type_commit(&newtype); + + return newtype; +} + +static MPI_Datatype make_largexfer_type_hindexed(MPI_Count nbytes) +{ + MPI_Datatype newtype; + +#undef NBLK +#define NBLK 4 + MPI_Count blkls[NBLK]; + MPI_Count displs[NBLK]; + + MPI_Count pos = 0; + for (int i = 0; i < NBLK - 1; i++) { + blkls[i] = i; + displs[i] = pos; + pos += blkls[i]; + } + blkls[NBLK - 1] = nbytes - pos; + displs[NBLK - 1] = pos; + + MPI_Type_create_hindexed_c(NBLK, blkls, displs, MPI_CHAR, &newtype); + MPI_Type_commit(&newtype); + + return newtype; +} + + +int testtype(MPI_Datatype type, MPI_Count expected) +{ + MPI_Count size, lb, extent; + int errs = 0; + MPI_Type_size_c(type, &size); + + if (size < 0) { + printf("ERROR: type size apparently overflowed integer\n"); + errs++; + } + + if (size != expected) { + printf("reported type size %lld does not match expected %lld\n", size, expected); + errs++; + } + + MPI_Type_get_true_extent_c(type, &lb, &extent); + if (lb != 0) { + printf("ERROR: type should have lb of 0, reported %lld\n", lb); + errs++; + } + + if (extent != size) { + printf("ERROR: extent should match size, not %lld\n", extent); + errs++; + } + return errs; +} + + +int main(int argc, char **argv) +{ + + int errs = 0, i; + int rank, size; + MTest_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + +#define NR_TYPES 3 + MPI_Offset expected_sizes[NR_TYPES] = { 1024UL * 1024UL * 2400UL * 2, + 2346319872 * 3, + 2346319872 * 4 + }; + MPI_Datatype types[NR_TYPES]; + + types[0] = make_largexfer_type_contig(expected_sizes[0]); + types[1] = make_largexfer_type_indexed_block(expected_sizes[1]); + types[2] = make_largexfer_type_hindexed(expected_sizes[2]); + + for (i = 0; i < NR_TYPES; i++) { + if (types[i] != MPI_DATATYPE_NULL) { + errs += testtype(types[i], expected_sizes[i]); + MPI_Type_free(&(types[i])); + } + } + + MTest_Finalize(errs); + + return MTestReturnValue(errs); +} diff --git a/test/mpi/pt2pt/Makefile.am b/test/mpi/pt2pt/Makefile.am index 0fd80ce2b76..aa16c3e34ca 100644 --- a/test/mpi/pt2pt/Makefile.am +++ b/test/mpi/pt2pt/Makefile.am @@ -67,6 +67,7 @@ noinst_PROGRAMS = \ pingping_barrier \ sendrecv1 \ sendself \ + pt2pt_large \ precv_anysrc \ precv_anysrc_exp diff --git a/test/mpi/pt2pt/pt2pt_large.c b/test/mpi/pt2pt/pt2pt_large.c new file mode 100644 index 00000000000..2b3a7c4c0da --- /dev/null +++ b/test/mpi/pt2pt/pt2pt_large.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) by Argonne National Laboratory + * See COPYRIGHT in top-level directory + */ + +#include "mpi.h" +#include +#include +#include "mpitest.h" + +/* Basic tests for large pt2pt APIs. It does not actually send large data */ + +#define SIZE 1024 + +int rank, nproc; +int errs; +int sendbuf[SIZE]; +int recvbuf[SIZE]; + +static void init_buf(void) +{ + if (rank == 0) { + for (int i = 0; i < SIZE; i++) { + sendbuf[i] = i; + } + } else if (rank == 1) { + for (int i = 0; i < SIZE; i++) { + recvbuf[i] = -1; + } + } +} + +static void check_buf(void) +{ + if (rank == 1) { + for (int i = 0; i < SIZE; i++) { + if (recvbuf[i] != i) { + errs++; + } + } + } +} + + +int main(int argc, char *argv[]) +{ + MPI_Comm comm; + MPI_Count count = SIZE; + int tag = 0; + + MTest_Init(&argc, &argv); + + comm = MPI_COMM_WORLD; + MPI_Comm_rank(comm, &rank); + MPI_Comm_size(comm, &nproc); + if (nproc != 2) { + printf("Run test with 2 procs!\n"); + return 1; + } + + init_buf(); + if (rank == 0) { + MPI_Send_c(sendbuf, count, MPI_INT, 1, tag, comm); + } else if (rank == 1) { + MPI_Recv_c(recvbuf, count, MPI_INT, 0, tag, comm); + } + check_buf(); + + MTest_Finalize(errs); + return MTestReturnValue(errs); +} diff --git a/test/mpi/pt2pt/testlist.in b/test/mpi/pt2pt/testlist.in index a202643a0df..3f406709804 100644 --- a/test/mpi/pt2pt/testlist.in +++ b/test/mpi/pt2pt/testlist.in @@ -63,3 +63,4 @@ large_tag 2 precv_anysrc 2 timeLimit=60 precv_anysrc 2 timeLimit=60 env=MPIR_CVAR_CH4_OFI_AM_LONG_FORCE_PIPELINE=true precv_anysrc_exp 2 timeLimit=60 +pt2pt_large 2