Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.
2221 Discussions

How to initiate MPI in the Fortran subroutine?

dingjun_chencmgl_ca
680 Views

Hi, All,

I am using Intel MPI and OpenMP. My application is a hybrid MPI and OpenMP Fortran-code application. Currently it is tested on a multicore computers. My question for you is as follows:

Can I initiate MPI processes and  run all MPI subroutines  within a Fortran subroutine?

The details are given as follows:

program xsamg2014

implicit none

..........................

/* Before calling xsamg, all codes are only OpenMP codes */ 

/*OpenMP Fortran codes  */

.....................................

/* call xsamg to initial MPI processes

call xsamg (.........)   // all MPI processes are with this subroutine xsamg(.....)

/* After finish calling XSAMG, then all others codes are OpenMP codes ***/

/*OpenMP Fortran codes*/

end program xsamg2014

 

subroutine xsamg(......, ....,.....)

implicit none

call  MPI_INIT() 

call MPI_COMM_SIZE(MPI_COMM_WORLD, count)

call MPI_COMM_RANK(MPI_COMM_WORLD, myid) 

........................................................

/* doing  some computation work with MPI technology */

......................................................

call MPI_FINALIZE()

return

end subroutine

in terms of manual of MPI, the following is the instruction on how to use MPI:

The functions MPI_INIT and MPI_FINALIZE are used to   initiate and shut down an MPI computation, respectively. MPI_INIT must be called before any other MPI function and must be called exactly once per process. No further MPI functions can be called after MPI_FINALIZE.

But when I enter the following commands to run my application:

mpiexec -n 4 myapplication.exe

All codes before ''call xsamg(....)',  are running on 4 MPI processes, although the MPI_init is not called. I guess the command mpiexec.exe  caused such a result.

My question for you is that:  Can I run all the codes before and after "call xsamg (....)" like  pure OpenMp codes as usual without 4 MPI processes? These 4 MPI processes are only applied to the MPI routines in the routine xsamg(......).

I look forward to hearing from you. Thanks in advance.   

 

 

 

 

 

 

 

 

 

0 Kudos
0 Replies
Reply