Repository navigation
Conversation
- Stop with an error when an MPI or POSIX output write, view change or close fails, and check the final file size at close (some MPI backends report success after a short write). - Stop with an error before node IDs or int MPI counts of the output sorters and writers overflow. - Count bytes written by one rank once, time the whole write from open to close with a wall-clock timer, and use the largest time over the ranks for the bandwidth. - Use the passive MPI wrapper for passive data also in forward AD builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@copilot resolve the merge conflicts in this pull request |
# Conflicts: # SU2_CFD/src/output/filewriter/CParallelFileWriter.cpp Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
| /*--- Check the final extent: some MPI backends report success even after a short write. ---*/ | ||
| MPI_Offset expectedEnd = 0, actualEnd = 0; | ||
| CBaseMPIWrapper::Allreduce(&disp, &expectedEnd, 1, MPI_OFFSET, MPI_MAX, SU2_MPI::GetComm()); | ||
| if (MPI_File_get_size(fhw, &actualEnd) != MPI_SUCCESS || actualEnd != expectedEnd) |
There was a problem hiding this comment.
Important: CloseMPIFile can stop a run that wrote a complete file. Each rank calls MPI_File_get_size straight after its own writes, with no MPI_File_sync between them. In MPI-IO's default nonatomic mode, a rank may not yet see the file growth from writes made by other ranks. For example, a header written by the master with WriteMPIBinaryData/WriteMPIString (MPI_File_write_at, which is not collective), or the tail of a write_all on Lustre/GPFS with client caching. That rank sees actualEnd < expectedEnd and calls SU2_MPI::Error.
Fix: call MPI_File_sync(fhw) and a barrier (sync-barrier-sync) before MPI_File_get_size, or have only rank 0 query the size after the sync and broadcast the result.
| #if MPI_VERSION >= 3 | ||
| MPI_Count written = 0; | ||
| if (MPI_Get_elements_x(&status, MPI_BYTE, &written) != MPI_SUCCESS || | ||
| written < 0 || static_cast<unsigned long>(written) != expected) |
There was a problem hiding this comment.
Important: Every write now stops the run unless the MPI_Status reports exactly expected bytes. That status is filled from a write_all of a derived datatype (WriteMPIBinaryDataAll) or from an MPI_CHAR write (WriteMPIString), but the code queries it with MPI_BYTE. The MPI standard requires the datatype passed to MPI_Get_elements[_x] to match the one used in the operation. Some MPI-IO layers also leave the status incomplete for collective writes, for example on a rank that contributes 0 bytes. A successful write then aborts with "MPI output write failed or was incomplete". Before this change these writes only returned a bool.
Fix: query the status with the datatype that was written (datatype for the collective write, MPI_CHAR for strings). Otherwise, rely only on ierr plus the extent check at close.
| void CSurfaceFVMDataSorter::SortConnectivity(CConfig *config, CGeometry *geometry, const vector<string> &markerList) { | ||
| unsigned long boundaryElements = 0; | ||
| for (unsigned short marker = 0; marker < geometry->GetnMarker(); ++marker) { | ||
| CheckIntCount(geometry->GetnElem_Bound(marker), N_POINTS_QUADRILATERAL); |
There was a problem hiding this comment.
Nit (optional): The surface sorter checks the boundary elements of every marker in the geometry, not only the ones in markerList that are actually sorted. It also uses the quadrilateral node count for every element. A case that plots one small marker on a mesh with a huge unplotted boundary (more than about 536M local boundary elements) stops with "Output exceeds the supported 32-bit ... range", even though the surface output would fit.
Fix: sum only the markers whose tag is in markerList.
| /*--- The largest counts that fit, larger ones stop the run. ---*/ | ||
| CParallelDataSorter::CheckIntCount(INT_MAX); | ||
| CParallelDataSorter::CheckIntCount(INT_MAX / 8, 8); | ||
| CParallelDataSorter::CheckIntCount(0, 0); |
There was a problem hiding this comment.
Nit (optional): The test is meant to check that counts above the limit stop the run, but it only exercises values that pass. An off-by-one or an inverted condition in CheckIntCount, such as >= or a dropped / entries, would still pass as long as the boundary values do not trip. The comment also says "larger ones stop the run", which the test never checks.
Fix: add a check that INT_MAX + 1ul and INT_MAX / 8 + 1, 8 exceed the limit. Because SU2_MPI::Error aborts, this needs a pure predicate that the test can call.
|
|
||
| TEST_CASE("File writer accounting", "[Output]") { | ||
| const int rank = SU2_MPI::GetRank(), size = SU2_MPI::GetSize(); | ||
| const std::string fileName = "file_writer_accounting"; |
There was a problem hiding this comment.
Nit (optional): The test writes to a fixed file name, file_writer_accounting.bin, in the current directory. When the serial and MPI unit-test binaries run at the same time from the same build directory (for example meson test in parallel), one run can delete the other's file, or hit the MPI_MODE_EXCL delete/recreate path. The size or extent checks then fail at random.
Fix: make the name unique per run, for example by appending the PID and the communicator size.
|
|
||
| nElemGlobal = std::accumulate(nElemPerTypeGlobal.begin(), nElemPerTypeGlobal.end(), 0ul); | ||
| nElem = std::accumulate(nElemPerType.begin(), nElemPerType.end(), 0ul); | ||
| CheckIntCount(nElemGlobal); |
There was a problem hiding this comment.
Large meshes are rejected although the global element count is never stored as an int.
CheckIntCount(nElemGlobal) limits the global element count to INT_MAX, but nElemGlobal is unsigned long, and the Paraview XML writer already switches to int64 connectivity and offsets (connInt64). Only node IDs and per-rank counts are int.
Example: a tet mesh with 2.3e9 elements and ~4e8 nodes fits everywhere it matters, but this check aborts the run at its first output.
Suggestion: drop the global element check, and check only the per-rank element/connectivity counts and the global node count.
| usedTime += stopTime - startTime; | ||
|
|
||
| return (bytesWritten == sizeInBytes); | ||
| if (bytesWritten != sizeInBytes) SU2_MPI::Error("Output write failed", CURRENT_FUNCTION); |
There was a problem hiding this comment.
Every write failure now aborts the solver, and the bool return value is dead.
WriteMPIBinaryDataAll, WriteMPIBinaryData, WriteMPIString and CloseMPIFile call SU2_MPI::Error instead of returning false (here and at lines 208 and 258). Before this PR, a disk-quota failure while writing e.g. a surface CSV left a short file and the solver kept running. Now MPI_Abort kills the run, and everything since the last restart is lost.
If the abort is intended, it would be good to say so and remove the return true / bool API. Otherwise, return false and let callers decide.
There was a problem hiding this comment.
So here the question is: when su2 fails to write a file, do we stop or do we continue the run?
I am inclined to say we stop and this is the intended behavior.
| stopTime = SU2_MPI::Wtime(); | ||
| stopTime = WallTime(); | ||
|
|
||
| usedTime += stopTime - startTime; |
There was a problem hiding this comment.
The usedTime accumulation is dead code.
CloseMPIFile overwrites usedTime via UpdateBandwidth(elapsed since open), so the per-write usedTime += stopTime - startTime here (and at lines 157, 189, 206, 240 and 256) never reaches the reported value. The startTime/stopTime updates in these functions can go too.
| * \brief Set the write time to the largest one over all ranks and compute the bandwidth with the file size. | ||
| * \param[in] elapsed - Write time of this rank. | ||
| */ | ||
| void UpdateBandwidth(passivedouble elapsed); |
There was a problem hiding this comment.
Pre-existing, but this PR now feeds the result into the bandwidth report.
DetermineFilesize (line 86) returns -1 cast to unsigned long when stat fails. That value now reaches UpdateBandwidth. For example, a build without TecIO that asks for TECPLOT_BINARY writes no file, so the file size becomes ~1.8e19 and the reported bandwidth is absurd.
Suggestion: return 0 (or report the error) when stat fails.
| public: | ||
| /*! | ||
| * \brief Stop with an error if count * entries does not fit in an int (node IDs and MPI counts are int). | ||
| * \param[in] count - Number of items. |
There was a problem hiding this comment.
Minor: \param[in] count - Number of items. only restates the parameter name. Either drop the line or say what is counted (elements, nodes, ...).
Problem
Fix
Tests
CFileWriter_tests.cppchecks the file size, write time and bandwidth.Notes
/dev/full) and a file size limit.Related
PR Checklist
pre-commit run --allto format old commits.🤖 Generated with Claude Code