mailr14439 - /1.3/multi/mpi4py_processor.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on August 25, 2011 - 12:19:
Author: bugman
Date: Thu Aug 25 12:19:59 2011
New Revision: 14439

URL: http://svn.gna.org/viewcvs/relax?rev=14439&view=rev
Log:
Reverted r14438 as the code actually was used.

The command used was:
svn merge -r14438:14437 .


Modified:
    1.3/multi/mpi4py_processor.py

Modified: 1.3/multi/mpi4py_processor.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/multi/mpi4py_processor.py?rev=14439&r1=14438&r2=14439&view=diff
==============================================================================
--- 1.3/multi/mpi4py_processor.py (original)
+++ 1.3/multi/mpi4py_processor.py Thu Aug 25 12:19:59 2011
@@ -1,7 +1,7 @@
 
###############################################################################
 #                                                                            
 #
 # Copyright (C) 2007 Gary S Thompson (https://gna.org/users/varioustoxins)   
 #
-# Copyright (C) 2010-2011 Edward d'Auvergne                                  
 #
+# Copyright (C) 2010 Edward d'Auvergne                                       
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -21,6 +21,9 @@
 #                                                                            
 #
 
###############################################################################
 
+# TODO: clone communicators & resize
+# TODO: check exceptions on master
+
 # Dependency check module.
 import dep_check
 
@@ -34,6 +37,52 @@
 # relax module imports.
 from multi.commands import Exit_command
 from multi.multi_processor_base import Multi_processor, 
Too_few_slaves_exception
+
+
+in_main_loop = False
+
+
+def broadcast_command(command):
+    for i in range(1, MPI.COMM_WORLD.size):
+        if i != 0:
+            MPI.COMM_WORLD.send(obj=command, dest=i)
+
+
+def ditch_all_results():
+    for i in range(1, MPI.COMM_WORLD.size):
+        if i != 0:
+            while True:
+                result = MPI.COMM_WORLD.recv(source=i)
+                if result.completed:
+                    break
+
+
+# wrapper sys.exit function
+# CHECKME is status ok
+def exit(status=None):
+    if MPI.COMM_WORLD.rank != 0:
+        if in_main_loop:
+            raise Exception('sys.exit unexpectedley called on slave!')
+        else:
+            sys.__stderr__.write('\n')
+            
sys.__stderr__.write('***********************************************\n')
+            sys.__stderr__.write('\n')
+            sys.__stderr__.write('warning sys.exit called before mpi4py main 
loop\n')
+            sys.__stderr__.write('\n')
+            
sys.__stderr__.write('***********************************************\n')
+            sys.__stderr__.write('\n')
+            MPI.COMM_WORLD.Abort()
+    else:
+        #print 'here'
+        exit_mpi()
+        #MPI.COMM_WORLD.Abort(1)
+        sys.exit(status)
+
+
+def exit_mpi():
+    if MPI.Is_initialized() and not MPI.Is_finalized() and 
MPI.COMM_WORLD.rank == 0:
+        broadcast_command(Exit_command())
+        ditch_all_results()
 
 
 class Mpi4py_processor(Multi_processor):
@@ -106,5 +155,12 @@
         MPI.COMM_WORLD.send(obj=result_object, dest=0)
 
 
+    def run(self):
+        global in_main_loop
+        in_main_loop = True
+        super(Mpi4py_processor, self).run()
+        in_main_loop = False
+
+
     def slave_recieve_commands(self):
         return MPI.COMM_WORLD.recv(source=0)




Related Messages


Powered by MHonArc, Updated Thu Aug 25 12:40:02 2011