Commits

Matthew Turk committed 2b0c2a8

Demo now kind of works.

Comments (0)

Files changed (1)

 from functools import wraps
-import pyro
 import inspect
+from yt.mods import *
+from mpi4py import MPI
+import time
 
 def requires_pf(func):
     @wraps(func)
 
 def broadcasted_action(func):
     @wraps(func)
-    def sender(self, *args, **kwargs):
+    def sender(*args, **kwargs):
+        self = args[0]
+        if self.comm.rank != 0:
+            return func(*args, **kwargs)
         argspec = inspect.getcallargs(func, *args, **kwargs)
-        msg = dict(type = func.func_name,
-                   args = argspec)
+        argspec.pop("self")
+        msg = dict(type = func.func_name, args = argspec)
         self.send(msg)
-        func(self, *args, **kwargs)
+        mylog.debug("Sending message: %s, %s", msg['type'], msg['args'])
+        func(*args, **kwargs)
     return sender
 
 class LockstepProxy(object):
-    name = None
     _run = True
-    def __init__(self, name, comm = None):
-        self.name = name
+    def __init__(self, comm = None):
         if comm is None:
-            raise RuntimeError
+            from yt.utilities.parallel_tools.parallel_analysis_interface \
+                import communication_system
+            comm = communication_system.communicators[-1]
         self.comm = comm
 
     def send(self, msg):
         self.comm.mpi_bcast_pickled(msg)
 
     def receive(self, msg):
+        mylog.debug("Received message: %s, %s", msg['type'], msg['args'])
         func = getattr(self, msg['type'])
         func(**msg['args'])
         
 
 class VolumeRenderingHandler(LockstepProxy):
     pf = None
-    name = None
 
+    @broadcasted_action
     def load(self, fn, resolution = 1024):
         self.pf = load(fn)
         if self.pf is None: raise IOError(fn)
         c = (self.pf.domain_right_edge + self.pf.domain_left_edge)/2.0
-        self.cam = self.pf.camera(c, [1.0, 1.0, 1.0],
-                      1.0/pf['unitary'], resolution, None)
+        self.cam = self.pf.h.camera(c, [1.0, 1.0, 1.0],
+                      1.0/self.pf['unitary'], resolution, None)
 
     @broadcasted_action
-    @requires_pf
     def switch_view(self, normal_vector, width, center, north_vectors):
         self.cam.switch_view(normal_vector, width, center, north_vectors)
 
     @broadcasted_action
-    @requires_pf
     def render(self):
         # In here is where we broadcast to all the other processors (if we have
         # them running!) what the view is, before we snapshot.
         return sn
 
     @broadcasted_action
-    @requires_pf
     def isocontours(self, limits, nlayers, width):
         self.cam.transfer_function = ColorTransferFunction(limits)
         self.cam.transfer_function.add_layers(nlayers, w=width)
 
 if __name__ == "__main__":
-    pass
+    VRH = VolumeRenderingHandler()
+    if MPI.COMM_WORLD.rank == 0:
+        #insert_ipython()
+        VRH.load("JHK-DD0030/galaxy0030")
+        print 1
+        snap = VRH.render()
+        print 2
+        snap = VRH.render()
+        print 3
+        snap = VRH.render()
+        print 4
+        snap = VRH.render()
+        print 5
+        snap = VRH.render()
+        time.sleep(10)
+    else:
+        VRH.runwait()