Source

yt.inline-intercomm / user_script.py

from yt.mods import *
from mpi4py import MPI

if 1:
    my_info = MPI.Info()
    port = MPI.Open_port(my_info)
    MPI.Publish_name("enzo_server", my_info, port)
    comm = MPI.COMM_WORLD.Accept(port, my_info, 0)

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