def start(mode=None, profile_flag=False): """Execute relax. @keyword mode: Force a relax mode, overriding the command line. @type mode: str @keyword profile_flag: Change this flag to True for code profiling. @type profile_flag: bool """ # Normal relax operation. relax = Relax() # Override normal operation. if mode: # Override the mode. relax.mode = mode # Some defaults. relax.script_file = None relax.log_file = None relax.tee_file = None relax.multiprocessor_type = 'uni' relax.n_processors = 1 # Process the command line arguments. else: relax.arguments() # Store some start up info in the status object. status.relax_mode = relax.mode # Set up the multi-processor elements. callbacks = Application_callback(master=relax) verbosity = 0 if status.debug: verbosity = 1 processor = load_multiprocessor(relax.multiprocessor_type, callbacks, processor_size=relax.n_processors, verbosity=verbosity) # Place the processor fabric intro string into the info box. info = Info_box() info.multi_processor_string = processor.get_intro_string() # Normal relax operation. if not profile_flag: # Execute relax in multi-processor mode (this includes the uni-processor for normal operation). processor.run() # relax in profiling mode. else: def print_stats(stats, status=0): pstats.Stats(stats).sort_stats('time', 'name').print_stats() # No profile module. if not dep_check.profile_module: sys.stderr.write("The profile module is not available, please install the Python development packages for profiling.\n\n") sys.exit() # Run relax in profiling mode. profile.Profile.print_stats = print_stats profile.runctx('processor.run()', globals(), locals())
# Randomise the matrices. for j in range(3): for k in range(3): self.A[j, k] = uniform(0, 1) self.B[j, k] = uniform(0, 1) # Perform some linear algebra. dot(self.A, self.B) # Keep track of the number of calculations. num_calcs += 1 # Process the results on the master. processor.return_object(Test_result_command(processor, memo_id=self.memo_id, num=num_calcs)) # Set up the processor. processor = load_multiprocessor(FABRIC, Application_callback(master=Main()), processor_size=PROCESSOR_NUM, verbosity=1) # Run without profiling. if not PROFILE: processor.run() # Run with profiling. else: # Replace the default profiling printout function. profile.Profile.print_stats = print_stats # Execute with profiling. profile.runctx("processor.run()", globals(), locals())
R_random_hypersphere(self.R) # Rotate the vector. new_vect = dot(self.R, vect) # The length sum. self.length += norm(new_vect) # Keep track of the number of calculations. num_calcs += 1 # Process the results on the master. processor.return_object(Test_result_command(processor, memo_id=self.memo_id, num=num_calcs, length=self.length)) # Set up the processor. processor = load_multiprocessor(FABRIC, Application_callback(master=Main()), processor_size=PROCESSOR_NUM, verbosity=1) # Run without profiling. if not PROFILE: processor.run() # Run with profiling. else: # Replace the default profiling printout function. profile.Profile.print_stats = print_stats # Execute with profiling. profile.runctx('processor.run()', globals(), locals())
def start(mode=None, profile_flag=False): """Execute relax. @keyword mode: Force a relax mode, overriding the command line. @type mode: str @keyword profile_flag: Change this flag to True for code profiling. @type profile_flag: bool """ # Normal relax operation. relax = Relax() # Override normal operation. if mode: # Override the mode. relax.mode = mode # Some defaults. relax.script_file = None relax.log_file = None relax.tee_file = None relax.multiprocessor_type = 'uni' relax.n_processors = 1 # Process the command line arguments. else: relax.arguments() # Store some start up info in the status object. status.relax_mode = relax.mode # Set up the multi-processor elements. callbacks = Application_callback(master=relax) verbosity = 0 if status.debug: verbosity = 1 processor = load_multiprocessor(relax.multiprocessor_type, callbacks, processor_size=relax.n_processors, verbosity=verbosity) # Place the processor fabric intro string into the info box. info = Info_box() info.multi_processor_string = processor.get_intro_string() # Normal relax operation. if not profile_flag: # Execute relax in multi-processor mode (this includes the uni-processor for normal operation). processor.run() # relax in profiling mode. else: def print_stats(stats, status=0): pstats.Stats(stats).sort_stats('time', 'name').print_stats() # No profile module. if not dep_check.profile_module: sys.stderr.write( "The profile module is not available, please install the Python development packages for profiling.\n\n" ) sys.exit() # Run relax in profiling mode. profile.Profile.print_stats = print_stats profile.runctx('processor.run()', globals(), locals())