我想在 fortran 程序(作为主机)和 python 程序(作为从机)之间与 MPI 通信。我编写了以下测试,但无法从从站获取父通信器。
# Master(fortran)
> my_id : 0
> num_procs : 1
# Slave(python)
MPI initialiation : True
Has Parent : False
对此的任何帮助将不胜感激!
Fortran(主端)
program main
include 'mpif.h'
integer ierr, num_procs, my_id, INTERCOMM
call MPI_INIT (ierr)
!find out MY process ID, and how many processes were started.
call MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr)
call MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr)
write(*,*) "# Master(fortran) "
write(*,*) " > my_id : ", my_id
write(*,*) " > num_procs : ",num_procs
if (ierr /= 0) then
print*,"Erreur d'initialisation de MPI"
stop
endif
if (my_id==0) then
call MPI_COMM_SPAWN("python", "python_slave.py", 1, MPI_INFO_NULL, my_id, MPI_COMM_WORLD, &
& INTERCOMM, MPI_ERRCODES_IGNORE,ierr)
!--
!Send input to the slave
!Receive results from the slave
!--
endif
call MPI_FINALIZE ( ierr )
print *, ">> End of program"
end program main
Python(从站)
from mpi4py import MPI
print " # Slave(python) "
print " MPI initialiation : ", MPI.Is_initialized()
print " Has Parent : ", not(MPI.Comm.Get_parent() == MPI.COMM_NULL)
#--
#Receive some input from the master
#Do some work
#Send some results to the master
#--
#status = MPI.Status()
#print " > Status source : ", status.Get_source() # ANY_SOURCE = -2
#print " > Status tag : ", status.Get_tag() # ANY_TAG = -1
#print " > Status count : ", status.Get_count()
#
#pyworld = MPI.COMM_WORLD
#
#print " Slave "
#print " > rank : ", pyworld.Get_rank()
#print " > size : ", pyworld.Get_size()