1

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()
4

1 に答える 1