【发布时间】:2014-11-08 20:05:59
【问题描述】:
假设使用 mpif90 编译的过度简化的 FORTRAN 代码为:
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
默认情况下,主 CPU 会等待子 CPU 完成计算。但是,我希望它在调用孩子后继续其任务,而孩子也在执行其任务。我希望孩子成为主程序的子程序,因为我需要将一些数据从主程序传递给子程序(反之亦然)。我想知道这在 FORTRAN 中是否可行(可能是通过使用某种非阻塞子例程调用或多线程,例如 mpi_comm_spawn)。
【问题讨论】:
标签: multithreading fortran blocking