'MPI_Init_thread function was called before MPI_Init was invoked
I need an MPI_Init_Thread call example in fortran.
I tried it without MPI_Init before it and got the message:"MPI_Init_thread function was called before MPI_Init was invoked".
I called after MPI_init and got the message "Calling MPI_Init or MPI_Init_Thread twpce is erreneous." altough I had each called once.
I am confused.
Also are there three or 4 arguments? and what are they? I believe it is three and the second one I want is MPI_THREAD_MULTIPLE but program aborts.
It would be best if someone uses it with fortran could post an example call please.
For completeness I am posting a simple code I am tring to run in hybrid (MPI + OPENMP) mode. My purpose is to run this job on two nodes , each with 32 threads by making use of openmp within each node.
program hello
Use mpi
integer ierr,np,pid,inull1,inul2,hug
call MPI_Init(ierr)
inull2=3
! call MPI_Init_thread(inull1,inull2,ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, pid,ierr)
call MPI_Comm_size(MPI_COMM_WORLD, np, ierr)
write(6,*) 'inull2,MPI_THREAD_MULTIPLE',MPI_THREAD_MULTIPLE
hug=huge(inull1)
!$OMP PARALLEL SHARED(inull1,inull2,hug,MPI_THREAD_MULTIPLE,np) &
!$OMP PRIVATE(pid)
!$OMP DO SCEDULE (STATIC)
do i=1,hug
write(6,*) 'program hello_world i,np,pid,inull2,mtm',i,np,pid,inull2,MPI_THREAD_MULTIPLE
enddo
!$OMP END DO
!$OMP END PARALLEL
call MPI_Finalize(ierr)
end program hello
I compile it with
mpif90 -o hello_world_openmp.exe hello_world_openmp.f90
and run it with the following command (for now)
mpirun -hostfile hostfile -pernode -bind-to none hello_world_openmp.exe
Changing the code as
integer ierr,np,pid,inull1,inul2,hug
! call MPI_Init(ierr)
call MPI_Init_thread(MPI_THREAD_FUNNELLED,inull2,ierr)
also gives the following error: *** The MPI_Init_thread() function was called before MPI_INIT was invoked. *** This is disallowed by the MPI standard. *** Your MPI job will now abort.
Solution 1:[1]
The error message you quite is strange. But it has been reported before (https://www.mail-archive.com/[email protected]/msg19978.html https://github.com/TRIQS/cthyb/issues/122)
It points to some incompatibility somewhere. In your case it points to an incorrect call to MPI_Init_thread. The main point is:
Always use IMPLICIT NONE
!
This cannot be over-stressed. Even in a very short code you must use it. You declared inul2
instead of inull2
and you used MPI_THREAD_FUNNELLED
instead of MPI_THREAD_FUNNELED
. After correcting that, your codes runs correctly for me.
One calls MPI_Init_thread
instead of MPI_Init
, not after.
You call it like
call MPI_Init_thread(required, provided, ie)
where all arguments are integers, required
is an input argument saying which threading level you need and provided
is an output argument and says which threading level you got.
Be aware that for many MPI implementations MPI_THREAD_MULTIPLE
is either not supported at all or is very slow. I suggest designing your programs without the need for MPI_THREAD_MULTIPLE
.
The usage can be something like
integer :: ie
integer :: required, provided
required = MPI_THREAD_SERIALIZED
call MPI_Init_thread(required, provided, ie)
if (ie/=0) ... error
if (provided<required) then
... different error
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |