def main(): # Initialize the MPI pool pool = MPIPool() # Make sure only we run map() on the master process if not pool.is_master(): pool.wait() sys.exit(0) # create some random input data x = np.random.uniform(size=10000) y = np.random.uniform(size=10000) tasks = np.vstack((x,y)).T vals = pool.map(worker, tasks) pool.close()
# create the pool pool = MPIPool() # only run map() on the master process, all other processes wait for their work if not pool.is_master(): pool.wait() # worker processes exit after they have done their work sys.exit(0) # the following code is executed by the master process only # create some random input data x = np.random.uniform(size=10) y = np.random.uniform(size=10) tasks = list(zip(x, y)) # crate a callback function def cb(x): print x # map the function worker to tasks # and execute them parallel by processes other than the master results = pool.map(worker, tasks, callback=cb) # close the pool pool.close() print 'results:', results
if multiprocess: stats_dict[stat] = manager.list([]) else: stats_dict[stat] = [] for fid in fiducials[int(comp[0])]: print("On fiducial {0} of {1}".format(fid, len(fiducials[int(comp[0])]))) print(str(datetime.now())) if multiprocess: iterat = ((fiducials[int(comp[0])][fid][i], fiducials[int(comp[-1])][fid][i], comp, stats_dict) for i in xrange(len(fiducials[int(comp[0])][fid]))) pool.map(runner, iterat) else: for i in range(len(fiducials[int(comp[0])][fid])): name1 = fiducials[int(comp[0])][fid][i] name2 = fiducials[int(comp[-1])][fid][i] print("On {0} {1}".format(name1, name2)) dataset1 = load_and_reduce(name1) dataset2 = load_and_reduce(name2) output = stats_wrapper(dataset1, dataset2, statistics=stats)[0] for stat in output: stats_dict[stat].append(output[stat], os.path.basename(name1), os.path.basename(name2))