def __init__(self, max_processes, functions = {}):
     """
     Creates the scheduler.
     @param max_processes: Indeed is the total number of processes that will be used for the scheduling parallelization
     plus one (which is representing the current process).
     @param functions: @see SerialScheduler
     """
     SerialScheduler.__init__(self,functions)
     self.number_of_processes = max_processes - 1
     self.running = []
예제 #2
0
 def __init__(self, share_results_with_all_processes=False, functions={}):
     """
     Creates an instance of this scheduler.
     @param share_results_with_all_processes: If true, it will broadcast the final results
     array so that all the processes have a copy of it.
     @param functions: @see SerialScheduler
     """
     SerialScheduler.__init__(self, functions)
     self.comm = MPI.COMM_WORLD
     self.rank = self.comm.Get_rank()
     self.share_results_with_all_processes = share_results_with_all_processes
     self.number_of_processes = self.comm.Get_size()
     self.running = []
 def __init__(self, share_results_with_all_processes = False, functions = {}):
     """
     Creates an instance of this scheduler.
     @param share_results_with_all_processes: If true, it will broadcast the final results
     array so that all the processes have a copy of it.
     @param functions: @see SerialScheduler
     """
     SerialScheduler.__init__(self,functions)
     self.comm = MPI.COMM_WORLD
     self.rank = self.comm.Get_rank()
     self.share_results_with_all_processes = share_results_with_all_processes
     self.number_of_processes = self.comm.Get_size()
     self.running = []
예제 #4
0
파일: tools.py 프로젝트: ztypaker/pyProCT
def build_scheduler(scheduling_options, observer):
    """
    Factory function for scheduler building. Uses parameters to build up to 3 types of scheduler:
        - "Process/Parallel": A scheduler based on 'multiprocessing'. Can execute tasks in parallel.
        - "MPI/Parallel": This one uses MPI to execute tasks in parallel. Only usable with an MPI driver.
        - "Serial": A serial scheduler. Executes its tasks sequentially.

    @param scheduling_options: Parameters chunk containing the details of the scheduler to be created (mainly
    scheduler_type and number_of_processes).
    @param observer: The associated observer (can be None)

    @return: The scheduler instance.
    """

    # Define functions
    external_functions = {
        'task_started': {
            'function': send_message_to_observer,
            'kwargs': {
                'observer': observer,
                'tag': 'Task Started'
            }
        },
        'task_ended': {
            'function': send_message_to_observer,
            'kwargs': {
                'observer': observer,
                'tag': 'Task Ended'
            }
        },
        'scheduling_ended': {
            'function': send_message_to_observer,
            'kwargs': {
                'observer': observer,
                'tag': 'Scheduler Ended'
            }
        },
        'scheduling_started': {
            'function': send_message_to_observer,
            'kwargs': {
                'observer': observer,
                'tag': 'Scheduler Starts'
            }
        }
    }

    scheduler_type = scheduling_options['scheduler_type']
    if scheduler_type == "Process/Parallel":
        max_processes = scheduling_options[
            'number_of_processes'] if 'number_of_processes' in scheduling_options else multiprocessing.cpu_count(
            )
        return ProcessParallelScheduler(max_processes, external_functions)

    elif scheduler_type == "MPI/Parallel":
        from pyscheduler.MPIParallelScheduler import MPIParallelScheduler  # to avoid unneeded call to mpi_init
        return MPIParallelScheduler(share_results_with_all_processes=True,
                                    functions=external_functions)

    elif scheduler_type == "Serial":
        return SerialScheduler(external_functions)

    else:
        print "[ERROR][ClusteringExplorator::__init__] Not supported scheduler_type ( %s )" % (
            scheduler_type)
        exit()
 def testSerialScheduling(self):
     serial = SerialScheduler()
     add_tasks(serial, echo)
     self.assertItemsEqual([4, 2, 5, 6, 3, 1, 7, 9, 8], serial.run())