Source

yt.inline-intercomm / user_script.py

Full commit
from yt.mods import *
from mpi4py import MPI

if 1:
    my_info = MPI.Info()
    port = MPI.Open_port(my_info)
    print "OPENING PORT"
    if MPI.COMM_WORLD.rank == 0:
        print "PUBLISHING NAME"
        MPI.Publish_name("enzo_server", my_info, port)
    print "WAITING FOR A CONNECTION"
    comm = MPI.COMM_WORLD.Accept(port, my_info, 0)
    print "ACCEPTED A CONNECTION"

def main():
    pf = EnzoStaticOutputInMemory()
    proj = pf.h.proj(0, "Density")
    frb = FixedResolutionBuffer(proj, (0.0, 1.0, 0.0, 1.0), (1024, 1024))
    print "SENDING PIXEL BUFFER", frb["Density"].min(), frb["Density"].max()
    write_image(na.log10(frb["Density"]), "temp.png")
    #return
    if MPI.COMM_WORLD.rank == 0:
        st = MPI.Status()
        waiting = comm.Iprobe(MPI.ANY_SOURCE, 104, status=st)
        if not waiting: 
            print "NO FOUND WAITING"
            return
        print "GETTING NEW OUTPUT"
        comm.send(na.log10(frb["Density"]), dest = 0)