Assuming an over-simplified FORTRAN code compiled with mpif90 as:
program main
!
use mpi
implicit none
integer:: j, numtasks, taskid, ierr
integer:: master = 0
!
call mpi_init(ierr)
call mpi_comm_rank(mpi_comm_world, taskid, ierr)
!
if (taskid .eq. master) then
j = 5
call child (j)
! do stuff
end if
call mpi_finalize(ierr)
!
end program main
subroutine child(j)
!
implicit none
integer, intent(in):: j
! do some stuff with j
end subroutine child
By default, the master CPU from the main waits until the child is done with its calculations. However, I want it to continue its tasks after calling the child, while the child is also doing its tasks. I would like the child to be a subroutine for the main since I need to pass some data from the main to the child (but not vice versa). I was wondering to know if this is possible in FORTRAN (maybe by using some kind of non-blocking subroutine call or multi-threading such as mpi_comm_spawn).