Author: varioustoxins Date: Mon Mar 19 11:57:19 2007 New Revision: 3235 URL: http://svn.gna.org/viewcvs/relax?rev=3235&view=rev Log: consoles and scripts now exit cleanly (override sys.exit) interactive console works! Modified: branches/multi_processor/multi/mpi4py_processor.py Modified: branches/multi_processor/multi/mpi4py_processor.py URL: http://svn.gna.org/viewcvs/relax/branches/multi_processor/multi/mpi4py_processor.py?rev=3235&r1=3234&r2=3235&view=diff ============================================================================== --- branches/multi_processor/multi/mpi4py_processor.py (original) +++ branches/multi_processor/multi/mpi4py_processor.py Mon Mar 19 11:57:19 2007 @@ -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 +