1. Matthew Turk
  2. yt.rife

Commits

Matthew Turk  committed 1eaab80

Adding in some MPI proxy object functions, and a trivial messaging protocol.

  • Participants
  • Parent commits 3ee81b7
  • Branches default

Comments (0)

Files changed (1)

File main_engine.py

View file
 from functools import wraps
 import pyro
+import inspect
 
 def requires_pf(func):
     @wraps(func)
         return func(self, *args, **kwargs)
     return wrap
 
-class VolumeRenderingHandler(object):
+def broadcasted_action(func):
+    @wraps(func)
+    def sender(self, *args, **kwargs):
+        argspec = inspect.getcallargs(func, *args, **kwargs)
+        msg = dict(type = func.func_name,
+                   args = argspec)
+        self.send(msg)
+        func(self, *args, **kwargs)
+    return sender
+
+class LockstepProxy(object):
+    name = None
+    _run = True
+    def __init__(self, name, comm = None):
+        self.name = name
+        if comm is None:
+            raise RuntimeError
+        self.comm = comm
+
+    def send(self, msg):
+        self.comm.mpi_bcast_pickled(msg)
+
+    def receive(self, msg):
+        func = getattr(self, msg['type'])
+        func(**msg['args'])
+        
+    def runwait(self):
+        while self._run:
+            msg = self.comm.mpi_bcast_pickled(None)
+            if msg is not None: self.receive(msg)
+
+class VolumeRenderingHandler(LockstepProxy):
     pf = None
+    name = None
 
     def load(self, fn, resolution = 1024):
         self.pf = load(fn)
         self.cam = self.pf.camera(c, [1.0, 1.0, 1.0],
                       1.0/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.
+        # We can get this from cam.normal_vector, cam.width, cam.center cam.north_vector
         if self.cam.transfer_function is None:
             raise RuntimeError
         sn = self.cam.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