Communication between spawned process and master process

12 views
Skip to first unread message

dund...@gmail.com

unread,
Jun 29, 2020, 12:28:17 PM6/29/20
to mpi4py
Hi,
I am trying to implement a parent/child configuration in mpi4py.
My goal is 

parent : will run on 1 core

child : will run on N cores 

I am trying to send data from parent to child's rank=0.

tried this:

master:

from mpi4py import MPI
import sys
def main():
    datafileopls
='MEDIUM2_opls.lmp'
    lammpscomm
= MPI.COMM_SELF.Spawn(sys.executable,
                             args
=['/storage/home/duy42/Developer/MLReax/Src3/lammps_driver.py'              
                           
],maxprocs=9)
    lammpscomm
.send(datafileopls,0,0)
    current_step
= lammpscomm.recv(None,0,0)
   
print(current_step)
    lammpscomm
.Disconnect()
if __name__ =='__main__':
    main
()


Child:
def main():
    parent
= MPI.Comm.Get_parent()
    comm
= MPI.COMM_WORLD
    
assert parent != MPI.COMM_NULL
   
try:
        status
= MPI.Status()
        any_src
, any_tag = MPI.ANY_SOURCE, MPI.ANY_TAG
       
print(parent.Get_rank(),comm.Get_rank(),status.source)
        if comm.Get_rank() == 0:
           
print('LAMMPS DRIVER CONNECTED')
            datafileopls
= parent.recv(None,any_src, any_tag, status)
            current_step = 123
            
parent.send(current_step,status.source,0)
   
finally:
       
parent.Disconnect()
       
print('All done')
   
    return
    
if __name__ == "__main__":
    main()

the code hangs before sending data to parent.
What I am missing here?

Thanks in advance.

Lisandro Dalcin

unread,
Jun 29, 2020, 1:08:52 PM6/29/20
to mpi...@googlegroups.com
How do you execute the master code? Does your example work on a laptop/workstation using plain `mpiexec -n 1 master.py` ?

--
You received this message because you are subscribed to the Google Groups "mpi4py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpi4py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mpi4py/cbbd49eb-b14e-40ff-a87a-b6b2cf53e4a9o%40googlegroups.com.


--
Lisandro Dalcin
============
Research Scientist
Extreme Computing Research Center (ECRC)
King Abdullah University of Science and Technology (KAUST)
http://ecrc.kaust.edu.sa/

Dundar Yilmaz

unread,
Jun 29, 2020, 1:10:08 PM6/29/20
to mpi...@googlegroups.com
Hi 
I am using a redhat based cluster with infiniband, intel mpi.
mpiexec -n 1 -usize python master.py

dundar

Dundar Yilmaz, Ph. D.
Research Associate Professor 
Department of Mechanical and Nuclear Engineering 
138 Research East Building 
Penn State University 
University Park, PA 16802

You received this message because you are subscribed to a topic in the Google Groups "mpi4py" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mpi4py/RR3R9JmJw6M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mpi4py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mpi4py/CAEcYPwCCPUu0KpY1eoE6d6K7pq1s1f89b9sGkPBpP0nJFhi3%3Dw%40mail.gmail.com.

Lisandro Dalcin

unread,
Jun 30, 2020, 3:35:03 AM6/30/20
to mpi...@googlegroups.com
On Mon, 29 Jun 2020 at 20:10, Dundar Yilmaz <dund...@gmail.com> wrote:
Hi 
I am using a redhat based cluster with infiniband, intel mpi.
mpiexec -n 1 -usize python master.py


Don't you have to pass an integer value for the -usize option? If I do not, my mpiexec invocation fails.
BTW, If you pass the universe size to mpiexec, then maybe you should get back the value use maxprocs=usize-1
usize = MPI.COMM_WORLD.Get_attr(MPI.UNIVERSE_SIZE)

You copied&pasted your code rather than attaching it, so maybe this is not in your script, but anyway... 
You are missing the `from mpi4py import MPI` stanza in the child code.

After fixing the two issues above, your code runs just fine in my workstation.

Reply all
Reply to author
Forward
0 new messages