Author: bugman Date: Wed Oct 15 21:51:39 2008 New Revision: 7712 URL: http://svn.gna.org/viewcvs/relax?rev=7712&view=rev Log: Manually merge r3235 from the multi_processor branch. The command used was: svn merge -r3234:3235 svn+ssh://bugman@xxxxxxxxxxx/svn/relax/branches/multi_processor . ..... r3235 | varioustoxins | 2007-03-19 11:57:19 +0100 (Mon, 19 Mar 2007) | 4 lines Changed paths: M /branches/multi_processor/multi/mpi4py_processor.py consoles and scripts now exit cleanly (override sys.exit) interactive console works! ..... Modified: branches/multi_processor_merge/multi/mpi4py_processor.py Modified: branches/multi_processor_merge/multi/mpi4py_processor.py URL: http://svn.gna.org/viewcvs/relax/branches/multi_processor_merge/multi/mpi4py_processor.py?rev=7712&r1=7711&r2=7712&view=diff ============================================================================== --- branches/multi_processor_merge/multi/mpi4py_processor.py (original) +++ branches/multi_processor_merge/multi/mpi4py_processor.py Wed Oct 15 21:51:39 2008 @@ -2,15 +2,45 @@ import sys + + +# load mpi try: from mpi4py import MPI except ImportError: sys.stderr.write("The dependency 'mpi4py' has not been installed.\n") sys.exit() +# save original sys.exit to call after wrapper +if MPI.rank == 0: + _sys_exit = sys.exit + +# wrapper sys.exit function +def exit(status=None): + + exit_mpi() + _sys_exit(status) + +def exit_mpi(): + if MPI.Is_initialized() and not MPI.Is_finalized() and MPI.rank == 0: + sendbuf = ['close'] + for i in range(MPI.size): + if i != 0: + MPI.COMM_WORLD.Send(buf=sendbuf,dest=i) + + + + class Mpi4py_processor: + + + def __init__(self,relax_instance): self.relax_instance= relax_instance + + # wrap sys.exit to close down mpi before exiting + sys.exit= exit + self.do_quit=False def run(self): @@ -19,7 +49,15 @@ else: self.relax_instance.multi_mode='multi_slave' - self.relax_instance.run() + if MPI.rank ==0: + self.relax_instance.run() + sys.exit() + else: + data = MPI.COMM_WORLD.Recv(source=0) + if data=='close': + exit_mpi() + return +