Write separate track files for multiple MPI ranks

This commit is contained in:
Paul Romano 2022-05-18 09:33:57 -04:00
parent b741516279
commit b786ad4c9f
3 changed files with 60 additions and 1 deletions

View file

@ -114,6 +114,17 @@ tallies. The path to the statepoint file can be provided as an optional arugment
.. _scripts_track:
------------------------
``openmc-track-combine``
------------------------
This script combines multiple HDF5 :ref:`particle track files
<usersguide_track>` into a single HDF5 particle track file. The filenames of the
particle track files should be given as posititional arguments. The output
filename can also be changed with the ``-o`` flag:
-o OUT, --out OUT Output HDF5 particle track file
-----------------------
``openmc-track-to-vtk``
-----------------------

37
scripts/openmc-track-combine Executable file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""Combine multiple HDF5 particle track files.
"""
import argparse
import h5py
def main():
# Parse command-line arguments
parser = argparse.ArgumentParser(
description='Combine particle track files into a single .h5 file.')
parser.add_argument('input', metavar='IN', nargs='+',
help='Input HDF5 particle track filename(s).')
parser.add_argument('-o', '--out', metavar='OUT', default='tracks.h5',
help='Output HDF5 particle track file.')
args = parser.parse_args()
with h5py.File(args.out, 'w') as h5_out:
for i, fname in enumerate(args.input):
with h5py.File(fname, 'r') as h5_in:
# Copy file attributes for first file
if i == 0:
h5_out.attrs['filetype'] = h5_in.attrs['filetype']
h5_out.attrs['version'] = h5_in.attrs['version']
# Copy each 'track_*' dataset from input file
for dset in h5_in:
h5_in.copy(dset, h5_out)
if __name__ == '__main__':
main()

View file

@ -2,6 +2,7 @@
#include "openmc/constants.h"
#include "openmc/hdf5_interface.h"
#include "openmc/message_passing.h"
#include "openmc/position.h"
#include "openmc/settings.h"
#include "openmc/simulation.h"
@ -40,8 +41,18 @@ void write_particle_track(Particle& p)
void open_track_file()
{
// Open file and write filetype/version
// Open file and write filetype/version -- when MPI is enabled and there is
// more than one rank, each rank writes its own file
#ifdef OPENMC_MPI
std::string filename;
if (mpi::n_procs > 1) {
filename = fmt::format("{}tracks_p{}.h5", settings::path_output, mpi::rank);
} else {
filename = fmt::format("{}tracks.h5", settings::path_output);
}
#else
std::string filename = fmt::format("{}tracks.h5", settings::path_output);
#endif
track_file = file_open(filename, 'w');
write_attribute(track_file, "filetype", "track");
write_attribute(track_file, "version", VERSION_TRACK);