← Back to team overview

yade-mpi team mailing list archive

Re: mpi interactivity

 

On Thu, 13 Jun 2019 at 11:13, Bruno Chareyre <bruno.chareyre@xxxxxxxxxxxxxxx>
wrote:

>  the idea of full interactivity combined with mpi execution is chimeric.
>

Maybe not.
The attached script spawn mpi runners on the fly and send scene to them, in
a very simple way.
Just run it with yade (compiled with mpi support), and you'll get qt
interface as usual.
Bruno
#!/bin/python

import numpy
import os
import sys
import time

#os.environ["OMPI_UNIVERSE_SIZE"]="4"
#os.environ["MPIEXEC_UNIVERSE_SIZE"]="4"
from  mpi4py  import  MPI

nWorkers=3

def  main ():
    comm = MPI.COMM_WORLD
    process_count = comm.Get_size()
    #interpreteur = sys.executable #returns 'python' even after launching yade
    interpreteur = prefix+"/bin/"+prog #'prog' and 'prefix' are defined by yade at startup
    script = os.path.basename(sys.argv [0])    
    process_count = comm.Get_size()
    
    if process_count < 2:
	    comm = MPI.COMM_SELF.Spawn(interpreteur, args=sys.argv,maxprocs=nWorkers-1).Merge()
    else:
	    comm = MPI.Comm.Get_parent().Merge()
    
    rank = comm.Get_rank ()
    print("I am worker "+str(rank)+" running with executable "+str(interpreteur)+" and argv="+str(sys.argv))
    
    if rank==0:
	    print("sending scene")
	    for w in range (1,nWorkers):
		    comm.send(O.sceneToString(),dest=w)
    else:
	    print("worker "+str(rank)+" getting scene")
	    s=comm.recv(source=0)
	    O.stringToScene(s)
	    print("worker "+str(rank)+" received scene")
    
    

            
if  __name__  == "__main__":
    main()

Follow ups

References