Dear Britton,
I tried something like that, but clearly I'm not doing it correctly. I'm noticing two errors, 1) everything is reporting running on the root proc (with a "Yo I'm root!") and 2) I'm getting four copies of my_storage back. Here's the code:
#########################################################################
from matplotlib import rc
import matplotlib.pyplot as plt
import yt
from yt import derived_field
import numpy as np
import yt.units as u
import glob
# Use YT in parallel.
yt.enable_parallelism()
# Number of procs on the machine
num_procs=4
@derived_field(name = "total_KE", units = "erg")
def _KE(field, data):
return np.sum(data["kinetic_energy"].in_mks()*data["cell_volume"].in_cgs())
@derived_field(name = "total_PE", units = "erg")
def _PE(field, data):
return 0.5*np.sum(data["gpot"].in_mks()*data["cell_mass"].in_cgs())
@derived_field(name = "total_Eint", units = "erg")
def _Eint(field, data):
return np.sum(data["eint"]*data["cell_mass"]).in_cgs()
@derived_field(name = "total_energy", units = "erg")
def _Etotal(field, data):
return data["total_Eint"] + data["total_PE"] + data["total_KE"]
@derived_field(name = "total_px", units = "g*cm/s")
def _px(field, data):
return np.sum(data["cell_mass"]*data["velx"]).in_cgs()
# Use glob to gather up the data files. Note here we use plt
# and particle files because they are much smaller than
# checkpoint files.
plot = glob.glob("./SinkMomTest/*plt_cnt_000?")
plot.sort()
part = glob.glob("./SinkMomTest/*part_000?")
part.sort()
# Make a list of variables you are collecting to plot/store as
# dictionaries.
my_storage = {}
# Now the parallel loop.
i = 0
for sto,p in yt.parallel_objects(plot, num_procs, storage = my_storage):
ds = yt.load(plot[i], particle_filename=part[i])
dd = ds.all_data()
if (yt.is_root()):
print "Yo I'm root!"
else:
print "Not root!"
energy = dd["total_energy"]
mom = dd["total_px"]
sto.result_id = p[-4:]
sto.result = [energy, mom]
i=i+1
print "Done!"
print my_storage
#########################################################################
Is this what you mean?