Skip to content

Commit

Permalink
Add hybrid SHMEM/MPI tests in spec-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
davidozog committed Mar 24, 2022
1 parent 9570453 commit 7544378
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/spec-example/hybrid_mpi_mapping_id.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This test program is derived from an example program in the
* OpenSHMEM specification.
*/

#include <mpi.h>
#include <shmem.h>
#include <stdio.h>

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;
}
28 changes: 28 additions & 0 deletions test/spec-example/hybrid_mpi_mapping_id_shmem_comm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This test program is derived from an example program in the
* OpenSHMEM specification.
*/

#include <mpi.h>
#include <shmem.h>
#include <stdio.h>

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;
}

0 comments on commit 7544378

Please sign in to comment.