Skip to content

Conversation

@cphyc
Copy link
Member

@cphyc cphyc commented Nov 3, 2023

PR Summary

This allows parallel I/O for the RAMSES dataset. Reading a RAMSES dataset has three steps:

  • read in the AMR structure
  • read the hydro files
  • read the particle files

The strategy I have adopted is to parallelize on the first one, such that each MPI task is now in charge of a few domains and only reads those (incl. hydro + particles).

@cphyc cphyc force-pushed the parallelize-ramses-io branch 2 times, most recently from ce2aa15 to a8d7767 Compare November 3, 2023 11:30
roff = [off * dtr for off in offsets]
rsize = [siz * dtr for siz in sizes]
tmp_recv = recv.view(self.__tocast)
tmp_recv = recv.view(transport_dtype)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation for getting rid of the cast to CHAR is so that we do not hit the limit imposed by MPI of 2**31 elements when communicating arrays as quickly.

Comment on lines +1153 to +1156
self.comm.send(
(arr.dtype.str, arr.shape, transport_dtype) + unit_metadata,
dest=dest,
tag=tag,
)
self.comm.Send([arr, mpi_type], dest=dest, tag=tag)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a bug here? I think this should be

Suggested change
self.comm.send(
(arr.dtype.str, arr.shape, transport_dtype) + unit_metadata,
dest=dest,
tag=tag,
)
self.comm.Send([arr, mpi_type], dest=dest, tag=tag)
self.comm.send(
(arr.dtype.str, arr.shape, transport_dtype) + unit_metadata,
dest=dest,
tag=tag,
)
self.comm.Send([tmp, mpi_type], dest=dest, tag=tag)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be tmp, yeah, but since it has been working I think it's possible that mpi4py was fixing it implicitly.

@cphyc
Copy link
Member Author

cphyc commented Nov 3, 2023

@yt-fido test this please

@cphyc cphyc force-pushed the parallelize-ramses-io branch from c9fc44d to 3097fde Compare March 2, 2025 10:32
@jzuhone jzuhone marked this pull request as ready for review March 2, 2025 14:02
@cphyc
Copy link
Member Author

cphyc commented Jul 18, 2025

After discussion with @matthewturk and @chrishavlin, we're proposing to implement this:

import numpy as np
import yt

ds = yt.load(...)
yt.enable_parallelism()
ad = ds.all_data()

def expensive_function(chunk):
    import time
    time.sleep(np.random.rand() * 3600)
    return 42

sto = {}
for chunk in ad.piter(storage=sto, reduction="min/max/sum/cat/cat_on_root"):
    sto.result["gas", "density"]     = chunk["gas", "density"]
    sto.result["gas", "temperature"] = chunk["gas", "temperature"]
    sto.result["expensive_stuff"]    = expensive_function(chunk)

if yt.is_root():
    mean_expensive_stuff = np.mean(sto["expensive_stuff"])
    plt.hist2d(sto["gas", "density"], sto["gas", "temperature"], bins=...)
    plt.title(f"{mean_expennsive_stuff=}")
    plt.savefig("...")

@cphyc
Copy link
Member Author

cphyc commented Jul 18, 2025

Closing since #5218 is much better.

@cphyc cphyc closed this Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants