Author: varioustoxins Date: Fri Mar 16 15:22:49 2007 New Revision: 3210 URL: http://svn.gna.org/viewcvs/relax?rev=3210&view=rev Log: updates to get first mpi initialization working Added: branches/multi_processor/multi/ branches/multi_processor/multi/__init__.py branches/multi_processor/multi/mpi4py_processor.py (with props) branches/multi_processor/multi/uni_processor.py (with props) Modified: branches/multi_processor/relax Added: branches/multi_processor/multi/__init__.py URL: http://svn.gna.org/viewcvs/relax/branches/multi_processor/multi/__init__.py?rev=3210&view=auto ============================================================================== (empty) Added: branches/multi_processor/multi/mpi4py_processor.py URL: http://svn.gna.org/viewcvs/relax/branches/multi_processor/multi/mpi4py_processor.py?rev=3210&view=auto ============================================================================== --- branches/multi_processor/multi/mpi4py_processor.py (added) +++ branches/multi_processor/multi/mpi4py_processor.py Fri Mar 16 15:22:49 2007 @@ -1,0 +1,29 @@ +#!/usr/bin/env python + +import sys + +try: + from mpi4py import MPI +except ImportError: + sys.stderr.write("The dependency 'mpi4py' has not been installed.\n") + sys.exit() + +class Mpi4py_processor: + def __init__(self,relax_instance): + self.relax_instance= relax_instance + + def run(self): + + if MPI.rank == 0: + self.relax_instance.multi_mode='multi_master' + else: + self.relax_instance.multi_mode='multi_slave' + + self.relax_instance.run() + + + +if __name__ == '__main__': + test = Mpi4py_processor(None) + print test + print MPI.rank Propchange: branches/multi_processor/multi/mpi4py_processor.py ------------------------------------------------------------------------------ svn:executable = * Added: branches/multi_processor/multi/uni_processor.py URL: http://svn.gna.org/viewcvs/relax/branches/multi_processor/multi/uni_processor.py?rev=3210&view=auto ============================================================================== --- branches/multi_processor/multi/uni_processor.py (added) +++ branches/multi_processor/multi/uni_processor.py Fri Mar 16 15:22:49 2007 @@ -1,0 +1,14 @@ +#!/usr/bin/env python + + +class Uni_processor(object): + def __init__(self,relax_instance): + self.relax_instance= relax_instance + + def run(self): + self.relax_instance.run() + + +if __name__ == '__main__': + test =Uni_processor(None) + print test Propchange: branches/multi_processor/multi/uni_processor.py ------------------------------------------------------------------------------ svn:executable = * Modified: branches/multi_processor/relax URL: http://svn.gna.org/viewcvs/relax/branches/multi_processor/relax?rev=3210&r1=3209&r2=3210&view=diff ============================================================================== --- branches/multi_processor/relax (original) +++ branches/multi_processor/relax Fri Mar 16 15:22:49 2007 @@ -145,7 +145,11 @@ RelaxWarnings() __builtin__.warn = warn - def run(self, mode): + def run(self): + + #FIXME use self.mode all over + mode = self.mode + # Show the version number and exit. if mode == 'version': print 'relax ' + self.version @@ -368,19 +372,7 @@ # Set the mode. mode = 'licence' - # multi processor - elif options.multiprocessor != 'uni': - - # Exclusive modes. - if options.test_suite or options.unit_test: - parser.error("the relax multi processor mode and executing the test suite are mutually exclusive") - elif options.licence: - parser.error("the relax multi processor multi processor and licence are mutually exclusive") - - self.multiprocessor_type = options.multiprocessor - self.n_processors = options.n_processors - - mode='multi' + # Script mode. elif self.script_file: @@ -398,7 +390,27 @@ mode = 'prompt' # Return. - return mode + + # multi processor + + if options.multiprocessor == 'uni': + self.multi_mode = 'uni' + else: + # Exclusive modes. + if options.test_suite or options.unit_test: + parser.error("the relax multi processor mode and executing the test suite are mutually exclusive") + elif options.licence: + parser.error("the relax multi processor multi processor and licence are mutually exclusive") + + self.multiprocessor_type = options.multiprocessor + self.n_processors = options.n_processors + + #note will be changed to multi_master or multi_slave when multi_processor initialises + self.multi_mode='multi' + + #FIXME: use self.mode throughout + self.mode=mode + def licence(self): @@ -517,13 +529,14 @@ try: module = __import__(module_path,globals(), locals(), []) - print 'loaded module %s' % module_path + if verbose: + print 'loaded module %s' % module_path except Exception, e: if verbose: print 'failed to load module_path %s' % module_path print 'exception:',e - + #FIXME: needs more failure checking if module != None: result = [module] components = module_path.split('.') @@ -533,16 +546,20 @@ return result #FIXME: mode not required should be an instance variable of relax? -def load_multiprocessor(mode,relax_instance): +def load_multiprocessor(relax_instance): processor_name = relax_instance.multiprocessor_type + '_processor' class_name= processor_name[0].upper() + processor_name[1:] module_path = '.'.join(('multi',processor_name)) - modules = import_module(module_path) - clazz = getattr(modules[-1], class_name) - object = clazz(mode,relax_instance) + modules = import_module(module_path,verbose=True) + print modules + if hasattr(modules[-1],class_name): + clazz = getattr(modules[-1], class_name) + else: + raise RelaxError("can't load class %s from module %s" % (class_name,module_path)) + object = clazz(relax_instance) return object if __name__ == "__main__": @@ -556,7 +573,7 @@ if not profile_flag: relax_instance = Relax() mode=relax_instance.arguments(sys.argv[1:]) - multi_processor = load_multiprocessor(mode,relax_instance) + multi_processor = load_multiprocessor(relax_instance) multi_processor.run() else: