From 7544378692dca076682997e053d870d3ec7f91f0 Mon Sep 17 00:00:00 2001 From: David Ozog Date: Thu, 24 Mar 2022 13:54:19 -0400 Subject: [PATCH] Add hybrid SHMEM/MPI tests in spec-examples --- test/spec-example/hybrid_mpi_mapping_id.c | 33 +++++++++++++++++++ .../hybrid_mpi_mapping_id_shmem_comm.c | 28 ++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/spec-example/hybrid_mpi_mapping_id.c create mode 100644 test/spec-example/hybrid_mpi_mapping_id_shmem_comm.c diff --git a/test/spec-example/hybrid_mpi_mapping_id.c b/test/spec-example/hybrid_mpi_mapping_id.c new file mode 100644 index 0000000..ca0d8bb --- /dev/null +++ b/test/spec-example/hybrid_mpi_mapping_id.c @@ -0,0 +1,33 @@ +/* + * This test program is derived from an example program in the + * OpenSHMEM specification. + */ + +#include +#include +#include + +int main(int argc, char *argv[]) { + MPI_Init(&argc, &argv); + shmem_init(); + + int mype = shmem_team_my_pe(SHMEM_TEAM_WORLD); + int npes = shmem_team_n_pes(SHMEM_TEAM_WORLD); + + static int myrank; + MPI_Comm_rank(MPI_COMM_WORLD, &myrank); + + int *mpi_ranks = shmem_calloc(npes, sizeof(int)); + + shmem_int_collect(SHMEM_TEAM_WORLD, mpi_ranks, &myrank, 1); + if (mype == 0) + for (int i = 0; i < npes; i++) + printf("PE %d’s MPI rank is %d\n", i, mpi_ranks[i]); + + shmem_free(mpi_ranks); + + shmem_finalize(); + MPI_Finalize(); + + return 0; +} diff --git a/test/spec-example/hybrid_mpi_mapping_id_shmem_comm.c b/test/spec-example/hybrid_mpi_mapping_id_shmem_comm.c new file mode 100644 index 0000000..718dfc8 --- /dev/null +++ b/test/spec-example/hybrid_mpi_mapping_id_shmem_comm.c @@ -0,0 +1,28 @@ +/* + * This test program is derived from an example program in the + * OpenSHMEM specification. + */ + +#include +#include +#include + +int main(int argc, char *argv[]) { + MPI_Init(&argc, &argv); + shmem_init(); + + int mype = shmem_my_pe(); + + MPI_Comm shmem_comm; + MPI_Comm_split(MPI_COMM_WORLD, 0, mype, &shmem_comm); + + int myrank; + MPI_Comm_rank(shmem_comm, &myrank); + printf("PE %d’s MPI rank is %d\n", mype, myrank); + + MPI_Comm_free(&shmem_comm); + shmem_finalize(); + MPI_Finalize(); + + return 0; +}