@@ -525,7 +525,7 @@ def piter(
525525 indices and the values will be whatever is assigned to the *result*
526526 attribute on the storage during iteration.
527527 barrier : bool
528- Should a barier be placed at the end of iteration?
528+ Should a barrier be placed at the end of iteration?
529529 dynamic : bool
530530 This governs whether or not dynamic load balancing will be enabled.
531531 This requires one dedicated processor; if this is enabled with a set of
@@ -535,16 +535,28 @@ def piter(
535535 This specifies the reduction operation to be applied to the results
536536 from each processor.
537537 - None: no reduction will be applied and the storage object will
538- contain one result per chunk in the container.
538+ contain one result per chunk in the container.
539539 - concat: the storage object will contain a flattened list of
540- each results.
540+ each results.
541541 - cat_on_root: same as concat, but only the root processor will
542- contain anything.
542+ contain anything.
543543 - sum, min, max: the storage object will contain the result
544- of applying the operation until getting a single value.
544+ of applying the operation until getting a single value.
545+
546+ Important limitation
547+ --------------------
548+ When using `storage`, the result *must* be a dictionary. See the
549+ examples below.
545550
546551 Example
547552 -------
553+
554+ Here is an example of how to gather all data on root, reading in
555+ parallel. Other MPI tasks will have nothing in `my_storage`.
556+
557+ >>> import yt
558+ >>> ds = yt.load("output_00080")
559+ ... ad = ds.all_data()
548560 >>> my_storage = {}
549561 ... for sto, chunk in ad.piter(storage=my_storage, reduction="cat_on_root"):
550562 ... sto.result = {
@@ -557,18 +569,34 @@ def piter(
557569 ... # Contains *all* the gas temperatures
558570 ... my_storage["gas", "temperature"]
559571
572+ Here is an example of how to sum the total mass of all gas cells in
573+ the dataset, storing the result in `my_storage` on all processors.
574+
560575 >>> my_storage = {}
561576 ... for sto, chunk in ad.piter(storage=my_storage, reduction="sum"):
562577 ... sto.result = {
563578 ... "total_mass": chunk["gas", "cell_mass"].sum(),
564579 ... }
565580 ... print("Total mass: ", my_storage["total_mass"])
566581
567- Note
568- ----
569- `sto.result` has to be a dictionary.
582+ Here is an example of how to read all data in parallel and
583+ have the results available on all processors.
570584
585+ >>> my_storage = {}
586+ ... for sto, chunk in ad.piter(storage=my_storage, reduction="cat"):
587+ ... sto.result = {("gas", "density"): chunk["gas", "density"]}
588+ ... print(my_storage["gas", "density"])
589+
590+ This is equivalent (but faster, since reading is parallelized) to the
591+ following
592+
593+ >>> my_storage = {("gas", "density"): ad["gas", "density"]}
571594 """
595+ if reduction is not None and storage is None :
596+ raise ValueError (
597+ "If reduction is specified, you must pass in a storage dictionary."
598+ )
599+
572600 yield from parallel_objects (
573601 self .chunks ([], "io" ),
574602 njobs = njobs ,
0 commit comments