Add file-based probes, horses2probes, and GPU compatibility fixes#86
Draft
mchavezmodena wants to merge 7 commits into
Draft
Add file-based probes, horses2probes, and GPU compatibility fixes#86mchavezmodena wants to merge 7 commits into
mchavezmodena wants to merge 7 commits into
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…k/horses3d-gpu into miguel_dev_probe_feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Probes from a file
This PR introduces a new file-based probe monitor that reads probe coordinates from a plain-text file and samples one or more flow variables at each location throughout the simulation.
The monitor extends the existing monitoring framework by allowing users to define an arbitrary number of probes through an external file rather than listing them individually in the input file. Multiple flow variables (e.g.
rho,u,v,w,p, ...) can be sampled simultaneously, with the variables selected directly from the monitor definition.A new input block,
has been added to the probes input file to define the probe set. During startup, the solver prints a summary of the loaded probes and the variables being monitored.
To reduce unnecessary I/O, a new
probe save timestepoption allows probe data to be written only after a user-defined physical-time interval has elapsed. This filtering is performed before entering the O(N) interpolation loop, avoiding unnecessary work when output is skipped.The monitor supports two output formats. The default ASCII backend generates one
.probefile per probe inside aprobes/directory and parallelizes file writing using OpenMP. Alternatively, when compiled withHAS_HDF5and usingoutput format = HDF5, all probes are stored in a single<solution>.probes.h5file using extendible datasets containing probe coordinates, time, iteration number, and one dataset for each sampled variable. The HDF5 backend is recommended for large probe sets.The implementation has also been optimized to support very large numbers of probes. The previous buffering strategy,
could require approximately 8 GB per MPI rank for one million probes. This has been replaced with a size-one write buffer that is flushed every timestep, reducing the memory footprint to roughly 8 MB per MPI rank, independently of the number of probes.
Communication during probe interpolation has also been optimized by replacing N individual
MPI_Bcastoperations with a singleMPI_Allreduce(SUM).Several robustness issues have also been addressed, including a segmentation fault with inactive probes, an OpenACC bypass for the file-probe interpolation loop, an unterminated
#ifdef FLOW, and a bug wherereadValueInRegioncould corrupt the probe file path.Finally, the new monitor has been integrated into the time-integration loop so that it follows the same execution model as the existing monitoring infrastructure.
Main modified files:
Solver/src/libs/monitors/Probe.f90Solver/src/libs/monitors/Monitors.f90Solver/src/libs/timeintegrator/TimeIntegrator.f90horses2probes
This PR also introduces
horses2probes, a standalone post-processing utility that converts the output generated by the new probe monitor into Tecplot-compatible files.The tool supports both the ASCII and HDF5 output formats produced by the solver, transparently handles multiple sampled variables, and is designed to efficiently process very large probe datasets. Since it is built independently from the solver, it can be compiled and executed on any machine containing the simulation outputs without requiring the full HORSES3D build.
The implementation is located under
and includes all source files together with an independent
Makefile.GPU fixes (
nvfortran -acc -fopenmp)The probe monitor relies on OpenMP for parallel ASCII output and MPI reductions. Enabling
-fopenmptogether with-accexposed several compilation and runtime issues innvfortran. Although most of them were unrelated to the new probe monitor itself, they prevented successful GPU builds and therefore have been fixed as part of this PR.Class A —
NVFORTRAN-S-0155("DO loop expected after OMP DO")Current versions of
nvfortranreject loops annotated simultaneously with!$omp doand!$acc parallel loop, even when the directives target different execution models. The solution was to guard the directives using compile-time preprocessor conditions so that only one of them is visible to the compiler depending on whether_OPENACCis enabled:This pattern has been applied to:
Solver/src/NavierStokesSolver/SpatialDiscretization.f90Solver/src/libs/mesh/HexMesh.f90Solver/src/libs/mesh/IBMClass.f90Solver/src/libs/discretization/EllipticBR1.f90Solver/src/libs/discretization/EllipticBR2.f90Solver/src/libs/discretization/EllipticIP.f90Solver/src/libs/discretization/DGSEMClass.f90Solver/src/libs/monitors/VolumeIntegrals.f90Solver/src/libs/monitors/SurfaceIntegrals.f90Class B —
NVFORTRAN-F-0000internal compiler error (mk_mem_ptr_shape)Another compiler bug was triggered by pointer association inside OpenACC kernels. Code of the form
caused an internal compiler error (
mk_mem_ptr_shape) when compiled with-acc.The affected routine was rewritten using an
associateconstruct instead of pointer association, which avoids the compiler bug while preserving the original behaviour.Modified file:
Solver/src/libs/discretization/SCsensorClass.f90Class C — LLVM IR undefined-value internal compiler error
A separate
nvfortraninternal compiler error occurred when polymorphic arguments (class(X)) were passed inside OpenMP parallel regions. The LLVM backend failed during code generation with an undefined-value error.The affected parallel region was restructured so that the polymorphic object is no longer passed into the OpenMP region, eliminating the compiler crash without changing the numerical behaviour.
Modified file:
Solver/src/libs/timeintegrator/AnalyticalJacobian.f90GPU correctness fix
While introducing the
_OPENACCguards described above, an additional runtime correctness issue was identified.Although the inner loops had been correctly separated into OpenMP and OpenACC versions, the outer
region in
ComputeTimeDerivativeremained active during GPU execution. Consequently, every OpenMP thread independently launched the same sequence of GPU kernels. Kernels containing operations such aswere therefore executed once per OpenMP thread, causing the residual to be accumulated multiple times. In practice, GPU runs diverged immediately, producing residuals on the order of
10^62at iteration zero.The solution was to wrap the outer OpenMP region with
so that, when compiling for GPU execution, a single CPU thread dispatches all GPU kernels while preserving the original OpenMP behaviour for CPU builds.
Modified file:
Solver/src/NavierStokesSolver/SpatialDiscretization.f90Documentation
The documentation has been updated to describe all the new functionality introduced in this PR.
The monitor documentation now includes the new
#define probe filesyntax, the available keywords, the probe input format, the ASCII and HDF5 output formats, and the HDF5 dataset layout.The PDF user manual has been updated with a new section describing the file-based probe monitor and the
horses2probesutility. The main manual has also been renamed fromUserManual.textoHORSES3D_UserManual.tex.Finally, the post-processing documentation has been extended to include the complete workflow for processing probe outputs using
horses2probes.Updated files:
doc/pages/user_manual/monitors.mddoc/HORSES3D_UserManual.texdoc/basicManualAndTutorial.texdoc/pages/user_manual/s-postprocessing.md