Hello world example code for debugging and testing.
MPI hello world:
program hello_world
use mpi
integer :: rank, comm_size, ierr, tag, status(MPI_STATUS_SIZE)
call mpi_init(ierr)
call mpi_comm_size(mpi_comm_world, comm_size, ierr)
call mpi_comm_rank(mpi_comm_world, rank, ierr)
print*, 'Hello from rank ', rank, ' of ', comm_size
call mpi_finalize(ierr)
end program
MPI hello world to test f77 vs f08 mpi bindings (this is a problem for DART with mpich 4 https://github.com/NCAR/DART/issues/261).
The issue has a mpi_f08 version.
Run with 2 processors:
program hello_world
use mpi
implicit none
integer :: rank, nprocs, ierr
integer :: tag, count
integer :: status(MPI_STATUS_SIZE)
real :: a, b
integer :: a_int, b_int
count = 1
tag = 1
a = 10.13
b = 4.34
a_int = 77
b_int = 3
call mpi_init(ierr)
call mpi_comm_size(MPI_COMM_WORLD, nprocs, ierr)
call mpi_comm_rank(MPI_COMM_WORLD, rank, ierr)
if (rank .eq. 0) then
call mpi_send(a, count, MPI_REAL, 1, tag, MPI_COMM_WORLD, ierr)
else
call mpi_recv(b, count, MPI_REAL, 0, tag, MPI_COMM_WORLD, status, ierr)
endif
if (rank .eq. 0) then
call mpi_send(a_int, count, MPI_INTEGER, 1, tag, MPI_COMM_WORLD, ierr)
else
call mpi_recv(b_int, count, MPI_INTEGER, 0, tag, MPI_COMM_WORLD, status, ierr)
endif
print*, 'Hello world from process: ', rank, 'of', nprocs
call mpi_finalize(ierr)
end program
1 Comment
Nancy Collins
there are also simple test programs distributed with dart in the developer_tests/mpi_utilities/tests directory. (there is probably a better location for these.) they test compiling plain f90, f90 with netcdf, f90 with mpi, and f90 with netcdf and mpi. also a c program, and c with mpi.