Author: bugman Date: Thu Oct 16 16:48:02 2008 New Revision: 7754 URL: http://svn.gna.org/viewcvs/relax?rev=7754&view=rev Log: Big clean up of the relax module. This was quite messy, and should be good enough for merging once all the FIXMEs are eliminated. Modified: branches/multi_processor_merge/relax Modified: branches/multi_processor_merge/relax URL: http://svn.gna.org/viewcvs/relax/branches/multi_processor_merge/relax?rev=7754&r1=7753&r2=7754&view=diff ============================================================================== --- branches/multi_processor_merge/relax (original) +++ branches/multi_processor_merge/relax Thu Oct 16 16:48:02 2008 @@ -1,5 +1,4 @@ #! /usr/bin/env python -from numpy.f2py.cfuncs import callbacks ############################################################################### # # @@ -41,16 +40,17 @@ # Python modules. from optparse import Option, OptionParser from os import F_OK, access, getpid, putenv +from numpy.f2py.cfuncs import callbacks import platform import profile import pstats from re import match from string import split, strip import sys -from multi.processor import Application_callback,Processor # relax modules. import generic_fns +from multi.processor import Application_callback, Processor from prompt.gpl import gpl from prompt import interpreter import relax_errors @@ -89,7 +89,7 @@ # Setup the object containing the generic functions. self.generic = generic_fns - # FIXME removed + # FIXME removed. # Process the command line arguments and determine the relax mode. #mode, log_file, tee_file = self.arguments() @@ -105,9 +105,11 @@ relax_errors.relax = self relax_warnings.relax = self + def run(self): - - #FIXME use self.mode all over + """Execute relax.""" + + #FIXME use self.mode all over. mode = self.mode print mode @@ -116,7 +118,6 @@ print 'relax ' + self.version sys.exit() - # FIXME threading # Logging. if self.log_file: log(self.log_file) @@ -134,12 +135,6 @@ self.interpreter = interpreter.Interpreter(self, intro_string) self.interpreter.run(self.script_file) - # FIXME no more threading -# elif mode == 'slave': -# self.interpreter = Interpreter(self) -# self.dummy_mode=1 -# self.interpreter.run() - # Execute the relax test suite elif mode == 'test suite': # Load the interpreter and turn intros on. @@ -175,8 +170,8 @@ self.licence() - def arguments(self,args): - """Function for processing the command line arguments.""" + def arguments(self, args): + """Process the command line arguments.""" # Parser object. parser = RelaxParser(self, usage="usage: %prog [options] [script_file]") @@ -195,12 +190,8 @@ parser.add_option('-m', '--multi', action='store', type='string', dest='multiprocessor', default='uni', help='set multi processor method') parser.add_option('-n', '--processors', action='store', type='int', dest='n_processors', default=-1, help='set number of processors (may be ignored)') - - - # Parse the options. (options, args) = parser.parse_args(args) - # Debugging flag. if options.debug: @@ -246,19 +237,18 @@ parser.error("the script file " + `self.script_file` + " does not exist") - - - # Determine the relax mode and test for mutually exclusive modes. ################################################################# -# TODO: this should be a task + + # TODO: this should be a task. + # Show the version number. if options.version: mode = 'version' # Run the relax tests. elif options.test_suite or options.system_tests or options.unit_tests: -#FIXME: multiprocessor options should be mostly resolved independant of the run mode + #FIXME: multiprocessor options should be mostly resolved independent of the run mode. self.multiprocessor_type = options.multiprocessor self.n_processors = options.n_processors # Make sure no script is supplied. if self.script_file: @@ -278,7 +268,6 @@ elif options.unit_tests: mode = 'unit tests' - # Test mode. elif options.test: # Make sure no script is supplied. @@ -309,27 +298,21 @@ # Set the mode. mode = 'licence' - - # Script mode. elif self.script_file: - #FIXME check for uniprocessor and n_processors + #FIXME check for uniprocessor and n_processors. self.multiprocessor_type = options.multiprocessor self.n_processors = options.n_processors mode = 'script' - # Prompt mode (default). else: - #FIXME check for uniprocessor and n_processors + #FIXME check for uniprocessor and n_processors. self.multiprocessor_type = options.multiprocessor self.n_processors = options.n_processors mode = 'prompt' - # Return. - # multi processor - if options.multiprocessor == 'uni': self.multi_mode = 'uni' else: @@ -343,10 +326,10 @@ self.n_processors = options.n_processors #note will be changed to multi_master or multi_slave when multi_processor initialises - self.multi_mode='multi' + self.multi_mode = 'multi' #FIXME: use self.mode throughout - self.mode=mode + self.mode = mode def get_intro_string(self): @@ -398,6 +381,7 @@ if not dep_check.C_module_exp_fn: intro_string = intro_string + "\n" + dep_check.C_module_exp_fn_mesg + "\n" + # Multi processor string component. self.intro_string = self.intro_string + '\nprocessor = ' + self.processor.get_intro_string() + '\n' # Return the string. @@ -456,32 +440,33 @@ # Exit. sys.exit() + # FIXME: code shared with unit testing framework not changed from unit tests version # replace unit test version with this - if __name__ == "__main__": #import multi.uni_processor - for elem in sys.modules: + for elem in sys.modules: if elem == 'multi.uni_processor': - print 'found',elem + print 'found', elem + # Change this flag to 1 for code profiling. profile_flag = 0 + # No profiling. if not profile_flag: relax_instance = Relax() relax_instance.arguments(sys.argv[1:]) - callbacks = Application_callback(master=relax_instance) - multi_processor = Processor.load_multiprocessor(relax_instance.multiprocessor_type, - callbacks, processor_size=relax_instance.n_processors) - relax_instance.processor = multi_processor + callbacks = Application_callback(master=relax_instance) + multi_processor = Processor.load_multiprocessor(relax_instance.multiprocessor_type, callbacks, processor_size=relax_instance.n_processors) + relax_instance.processor = multi_processor multi_processor.run() + # Profiling activated. else: def print_stats(stats, status=0): pstats.Stats(stats).sort_stats('time', 'name').print_stats() + #FIXME: profiling won't work with multi processors. profile.Profile.print_stats = print_stats profile.run('Relax()') - -