ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
getImageCountMPI.F90
Go to the documentation of this file.
1
48 use mpi !mpi_f08, only : mpi_initialized, mpi_comm_world, mpi_comm_size, mpi_init
49 implicit none
50 logical :: isinit
51 integer :: ierrMPI
52 integer :: imageRank = -1
53 integer :: imageCount = 0
54 imageCountMPI_block: block
55 call mpi_initialized(isinit, ierrMPI)
56 if (ierrMPI /= 0) exit imageCountMPI_block
57 if (.not. isinit) then
58 call mpi_init(ierrMPI)
59 if (ierrMPI /= 0) exit imageCountMPI_block
60 end if
61 call mpi_comm_size(mpi_comm_world, imageCount, ierrMPI)
62 if (ierrMPI /= 0) imageCount = 0
63 call mpi_comm_rank(mpi_comm_world, imageRank, ierrMPI)
64 if (ierrMPI /= 0) imageRank = -1
65 imageRank = imageRank + 1
66 end block imageCountMPI_block
67 ! All images report their rank and the MPI image count.
68 ! The current bash process is responsible for capturing it.
69 write(*, "(*(g0))") "imageCount=", imageCount, ". imageRank=", imageRank, "."
70 call mpi_finalize(ierrMPI)
71end program xgetImageCountMPI
program xgetImageCountMPI
This program contains instructions to determine the number of MPI-parallel processes and MPI image ra...