Skip to content

Commit

Permalink
Use std::stable_sort in ADIOS2 destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 19, 2022
1 parent 6d08b14 commit 8c0d2a2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,17 @@ ADIOS2IOHandlerImpl::~ADIOS2IOHandlerImpl()
sorted.push_back(std::move(pair.second));
}
m_fileData.clear();
std::sort(
/*
* Technically, std::sort() is sufficient here, since file names are unique.
* Use std::stable_sort() for two reasons:
* 1) On some systems (clang 13.0.1, libc++ 13.0.1), std::sort() leads to
* weird inconsisten segfaults here.
* 2) Robustness against future changes. stable_sort() might become needed
* in future, and debugging this can be hard.
* 3) It does not really matter, this is just the destructor, so we can take
* the extra time.
*/
std::stable_sort(
sorted.begin(), sorted.end(), [](auto const &left, auto const &right) {
return left->m_file <= right->m_file;
});
Expand Down

0 comments on commit 8c0d2a2

Please sign in to comment.