OpenMPI Sample Applications

Sample MPI applications provided both as a trivial primer to MPI as well as simple tests to ensure that your OpenMPI installation is working properly.


There are two MPI examples, each using one of six different MPI interfaces:

Hello world

Send a trivial message around in a ring

Additionally, there's one further example application, but this one only uses the MPI C bindings:

Test the connectivity between all processes

Build Examples

Download examples.

The Makefile in this directory will build the examples for the supported languages (e.g., if you do not have the Fortran "use mpi" bindings compiled as part of OpenMPI, those examples will be skipped).

The Makefile assumes that the wrapper compilers mpicc, mpic++, and mpifort are in your path.

Although the Makefile is tailored for OpenMPI (e.g., it checks the mpi_info command to see if you have support for C++, mpif.h, use mpi, and use mpi_f08 F90), all of the example programs are pure MPI, and therefore not specific to OpenMPI. Hence, you can use a different MPI implementation to compile and run these programs if you wish.

[login@cn204.anselm ]$ tar xvf ompi.tar.gz
[login@cn204.anselm ]$ ml OpenMPI/2.1.1-GCC-6.3.0-2.27
[login@cn204.anselm ]$ make
mpicc -g  hello_c.c  -o hello_c
mpicc -g  ring_c.c  -o ring_c
mpicc -g  connectivity_c.c  -o connectivity_c
mpicc -g  spc_example.c  -o spc_example
mpic++ -g  -o hello_cxx
mpic++ -g  -o ring_cxx
mpifort -g  hello_mpifh.f  -o hello_mpifh
mpifort -g  ring_mpifh.f  -o ring_mpifh
mpifort -g  hello_usempi.f90  -o hello_usempi
mpifort -g  ring_usempi.f90  -o ring_usempi
mpifort -g  hello_usempif08.f90  -o hello_usempif08
mpifort -g  ring_usempif08.f90  -o ring_usempif08
shmemcc -g  hello_oshmem_c.c  -o hello_oshmem
shmemc++ -g  -o hello_oshmemcxx
shmemcc -g  ring_oshmem_c.c  -o ring_oshmem
shmemcc -g  oshmem_shmalloc.c  -o oshmem_shmalloc
shmemcc -g  oshmem_circular_shift.c  -o oshmem_circular_shift
shmemcc -g  oshmem_max_reduction.c  -o oshmem_max_reduction
shmemcc -g  oshmem_strided_puts.c  -o oshmem_strided_puts
shmemcc -g  oshmem_strided_puts.c  -o oshmem_strided_puts
shmemcc -g  oshmem_symmetric_data.c  -o oshmem_symmetric_data
shmemfort -g  hello_oshmemfh.f90  -o hello_oshmemfh
shmemfort -g  ring_oshmemfh.f90  -o ring_oshmemfh
[login@cn204.anselm ]$ find . -executable -type f