예제 #1
0
def runMPI(runFunction, arguments):
    """
        Small overhead-function to handle multi-processing using MPI

        :param runFunction: The function to run in parallel, accepting ``arguments``
        :param arguments:   The arguments to passed distributedly to ``runFunction``
        :return:            List of any results produced by ``runFunction``
    """
    results = []
    num_parallel = Config.MPI_num_total_threads

    for args in chunkListByLength(arguments, num_parallel):
        res = None  # Required pre-initialization of the variable that will receive the data from comm.gather()

        comm = MPI.COMM_SELF.Spawn(sys.executable,
                                   args=['MPI_slave.py'],
                                   maxprocs=len(args))  # Initialize
        comm.bcast(runFunction, root=MPI.ROOT)  # Equal for all processes
        comm.scatter(args, root=MPI.ROOT)  # Different for each process
        comm.Barrier()  # Wait for everything to finish...
        res = comm.gather(res, root=MPI.ROOT)  # And gather everything up
        comm.Disconnect()

        results.extend(res)

    return results
예제 #2
0
 def test_non_elitist(self):
     pairwise_filtered = [
         min(pair, key=getFitness)
         for pair in chunkListByLength(self.npop, length=2)
     ]
     result = sorted(pairwise_filtered, key=getFitness)[:self.param.mu_int]
     self.assertListEqual(pairwise(self.pop, self.npop, self.param), result)
예제 #3
0
 def test_chunk_ragged_list(self):
     self.assertListEqual(list(chunkListByLength(range(7), 3)),
                          [[0, 1, 2], [3, 4, 5], [6]])
예제 #4
0
 def test_chunk_square_list(self):
     self.assertListEqual(list(chunkListByLength(range(6), 3)),
                          [[0, 1, 2], [3, 4, 5]])
예제 #5
0
 def test_chunk_empty_list(self):
     self.assertListEqual(list(chunkListByLength([], 3)), [])