:param kwargs: :return: """ print("[%d] " % rank, end="") print(*a, **kwargs) ####################################################################################################################### ## ## Time to get to business! ## ####################################################################################################################### # Now, go through and do Phase I for each period individually based on the process's rank for theta_index, theta_val in enumerate(args.theta): if theta_index % nproc == rank: runner = Runner(vid_color, periods, args, is_mpi=True, custom_print_fn=rprint, theta=theta_val) for period_index, period in enumerate(args.periods): rprint("Running for theta=%.2f (index %d), period=%d" % (theta_val, theta_index, period)) runner.DO_PHASE_I(period_index) rprint("Finished theta=%.2f (index %d). Freeing memory" % (theta_val, theta_index)) rprint("process exiting")
# Set up the variables we'll use # TODO: should this be `[None] * len(periods)` so that we don't eat up a bunch of extra memory in each process just to # store this empty numpy array? Also at the very least shouldn't it be empty, not zeros? labels_ph1 = [np.zeros((M * N), dtype="int32")] * len(periods) # Now, go through and do Phase I for each period individually based on the process's rank for index, period in enumerate(periods): if index % nproc == rank: rprint("Running for period=%d (index %d)" % (period, index)) runner = Runner(vid_color, periods, args, is_mpi=True, custom_print_fn=rprint, theta=theta) labels = runner.DO_PHASE_I(index) labels_ph1[index] = labels rprint("Finished period=%d (index %d). Freeing memory" % (period, index)) runner = None # free up the memory # Now, combine all those results on the root node for index, period in enumerate(periods): owner = index % nproc if rank == 0: # ROOT process receives if owner != 0: comm.Recv(labels_ph1[index], source=owner) elif owner == rank: # Other processes send only their computations comm.Send(labels_ph1[index], dest=0)
from prelude import * from runner import Runner r = Runner(vid_color, periods, args, theta=theta) for index, period in enumerate(periods): print("-" * 15, "Starting period", period, "-" * 15) r.DO_PHASE_I(index) if len(periods) > 1: r.DO_PHASE_II() else: print("Skipping Phase II since there was only 1 period")