Commit f5499dc9 authored by Bruce Cowan's avatar Bruce Cowan

New MPI example and readme

From 'Introduction to Programming with Fortran'
by Chivers and Sleightholme
parent d01f7271
Pipeline #2123 canceled with stage
in 40 seconds
# MPI
* Have to run ```module load mpi/openmpi-x86_64``` first.
## Running
* ```mpirun -n N ./mpi/hello``` for example, where N is the number of processes to run.
......@@ -18,7 +18,7 @@ if add_languages('c', required: false)
endif
if mpi_dep.found()
subdir('openmpi')
subdir('mpi')
endif
if openmp_dep.found()
......
program hello_comms
use mpi
implicit none
integer :: error_number
integer :: this_process_number
integer :: number_of_processes
integer :: i
integer, dimension(mpi_status_size) :: status
call mpi_init(error_number)
call mpi_comm_size(mpi_comm_world, number_of_processes, error_number)
call mpi_comm_rank(mpi_comm_world, this_process_number, error_number)
if (this_process_number == 0) then
print '(a,i0,a,i0,a)', " Hello from process ", this_process_number, &
" of ", number_of_processes, " processes."
do i = 1, number_of_processes - 1
call mpi_recv(this_process_number, 1, mpi_integer, i, 1, &
mpi_comm_world, status, error_number)
print '(a,i0,a,i0,a)', " Hello from process ", &
this_process_number, " of ", number_of_processes, " processes."
end do
else
call mpi_send(this_process_number, 1, mpi_integer, 0, 1, &
mpi_comm_world, error_number)
end if
call mpi_finalize(error_number)
end program hello_comms
program hello_comms
use mpi
implicit none
integer :: error_number
integer :: this_process_number
integer :: number_of_processes
call mpi_init(error_number)
call mpi_comm_size(mpi_comm_world, number_of_processes, error_number)
call mpi_comm_rank(mpi_comm_world, this_process_number, error_number)
print '(a,i0,a,i0,a)', " Hello from process ", this_process_number, &
" of ", number_of_processes, " processes"
call mpi_finalize(error_number)
end program hello_comms
executable('hello', 'hello.f90', dependencies: mpi_dep)
executable('hello-comms', 'hello-comms.f90', dependencies: mpi_dep)
program mpitest
implicit none
include 'mpif.h'
logical :: flag
integer :: ier
call MPI_Init(ier)
if (ier /= 0) then
print *, 'Unable to initialize MPI: ', ier
stop 1
endif
call MPI_Initialized(flag, ier)
if (ier /= 0) then
print *, 'Unable to check MPI initialization state: ', ier
stop 1
endif
call MPI_Finalize(ier)
if (ier /= 0) then
print *, 'Unable to finalize MPI: ', ier
stop 1
endif
end program mpitest
executable('hello', 'hello.f90', dependencies: mpi_dep, override_options: ['b_asneeded=false'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment