[cig-commits] r7703 - mc/3D/CitcomS/trunk/CitcomS/Coupler

hlin at geodynamics.org hlin at geodynamics.org
Wed Jul 18 16:06:35 PDT 2007


Author: hlin
Date: 2007-07-18 16:06:35 -0700 (Wed, 18 Jul 2007)
New Revision: 7703

Added:
   mc/3D/CitcomS/trunk/CitcomS/Coupler/MultiE_Coupler.py
Modified:
   mc/3D/CitcomS/trunk/CitcomS/Coupler/MultiC_Coupler.py
Log:
A    Coupler/MultiE_Coupler.py
M    Coupler/MultiC_Coupler.py

Fixed the synchronization part. Need to test on it. Now Embedded Couplers will wait until containing coupler make a decision.


Modified: mc/3D/CitcomS/trunk/CitcomS/Coupler/MultiC_Coupler.py
===================================================================
--- mc/3D/CitcomS/trunk/CitcomS/Coupler/MultiC_Coupler.py	2007-07-18 22:00:58 UTC (rev 7702)
+++ mc/3D/CitcomS/trunk/CitcomS/Coupler/MultiC_Coupler.py	2007-07-18 23:06:35 UTC (rev 7703)
@@ -34,7 +34,6 @@
         self.sourceList2 = range(self.remoteSize2)
         self.outletList2 = range(self.remoteSize2)
 
-        ###
         return
 
 
@@ -197,38 +196,45 @@
         KEEP_WAITING_SIGNAL = 0
         NEW_STEP_SIGNAL = 1
         END_SIMULATION_SIGNAL = 2
+        BIG_NEW_STEP_SIGNAL = 3
 
-        if done:
-            sent = END_SIMULATION_SIGNAL
-        elif self.synchronized:
-            sent = NEW_STEP_SIGNAL
-        else:
-            sent = KEEP_WAITING_SIGNAL
+        sent = NEW_STEP_SIGNAL
 
-        while 1:
+        KEEP_WAITING_FLAG = True
+       
+        while KEEP_WAITING_FLAG:
+
+            #receive signals
             recv = self.exchangeSignal(sent)
             recv2= self.exchangeSignal2(sent)
 
+            # determining what to send
             if done or (recv == END_SIMULATION_SIGNAL) or \
                (recv2 == END_SIMULATION_SIGNAL):
+                # end the simulation    
+                sent = END_SIMULATION_SIGNAL
                 done = True
-                break
+                KEEP_WAITING_FLAG = False
             elif (recv == KEEP_WAITING_SIGNAL) or \
                  (recv2 == KEEP_WAITING_SIGNAL):
-                pass
+                sent = NEW_STEP_SIGNAL
             elif (recv == NEW_STEP_SIGNAL) and \
                  (recv2 == NEW_STEP_SIGNAL):
-                sent = NEW_STEP_SIGNAL
-                if self.synchronized:
-                    #print self.name, 'exchanging timestep =', steps
-                    self.coupled_steps = self.exchangeSignal(steps)
-                    self.coupled_steps2 = self.exchangeSignal2(steps)
-                    #print self.name, 'exchanged timestep =', self.coupled_steps
-                break
+                # tell the embedded couplers to keep going
+                sent = BIG_NEW_STEP_SIGNAL
+                #print self.name, 'exchanging timestep =', steps
+                self.coupled_steps = self.exchangeSignal(steps)
+                self.coupled_steps2 = self.exchangeSignal2(steps)
+                #print self.name, 'exchanged timestep =', self.coupled_steps
+                KEEP_WAITING_FLAG = False
             else:
                 raise ValueError, \
                       "Unexpected signal value, singnal = %d" % recv
 
+            # send instructions to embedded couplers
+            recv = self.exchangeSignal(sent)
+            recv2= self.exchangeSignal2(sent)
+ 
         return done
 
 

Added: mc/3D/CitcomS/trunk/CitcomS/Coupler/MultiE_Coupler.py
===================================================================
--- mc/3D/CitcomS/trunk/CitcomS/Coupler/MultiE_Coupler.py	2007-07-18 22:00:58 UTC (rev 7702)
+++ mc/3D/CitcomS/trunk/CitcomS/Coupler/MultiE_Coupler.py	2007-07-18 23:06:35 UTC (rev 7703)
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+ 
+ 
+#
+#embedded coupler used in multi coupled application
+#
+#
+
+from EmbeddedCoupler import EmbeddedCoupler
+
+class MultiE_Coupler(EmbeddedCoupler):
+
+    def endTimestep(self, steps, done):
+        # exchange predefined signal btwn couplers
+        # the signal is used to sync the timesteps
+        KEEP_WAITING_SIGNAL = 0
+        NEW_STEP_SIGNAL = 1
+        END_SIMULATION_SIGNAL = 2
+        BIG_NEW_STEP_SIGNAL = 3
+        
+        if done:
+            sent = END_SIMULATION_SIGNAL
+        elif self.synchronized:
+            sent = NEW_STEP_SIGNAL
+        else:
+            sent = KEEP_WAITING_SIGNAL
+
+        while 1:
+            # send signal
+            recv = self.exchangeSignal(sent)
+            # receive instruction
+            recv = self.exchangeSignal(sent)
+
+            # determine what to do
+            if done or (recv == END_SIMULATION_SIGNAL):
+                done = True
+                break
+            elif recv == NEW_STEP_SIGNAL:
+                # keep going until synchronized
+                if self.synchronized:
+                    pass
+                else:
+                    break
+             elif recv == BIG_NEW_STEP_SIGNAL:
+                assert self.synchronized, \
+                       "embedded coupler not synchronized on a big step"
+                #print self.name, 'exchanging timestep =', steps
+                self.coupled_steps = self.exchangeSignal(steps)
+                #print self.name, 'exchanged timestep =', self.coupled_steps
+                break
+            else:
+                raise ValueError, \
+                      "Unexpected signal value, singnal = %d" % recv
+
+        return done
+



More information about the cig-commits mailing list