BUG: vtk write of uniform field in parallel (fixes #2349)

- used low-level MPI gather, but the wrapping routine contains an
  additional safety check for is_contiguous which is not defined for
  various std::pair<..> combination.

  So std::pair<label,vector> (which is actually contiguous, but not
  declared as is_contiguous) would falsely trip the check.

  Avoid by simply gathering unbundled values instead.
This commit is contained in:
Mark Olesen 2022-02-01 15:17:51 +01:00
parent 7a6891905e
commit ddcc04dadc
3 changed files with 38 additions and 11 deletions

View File

@ -104,6 +104,8 @@ int main(int argc, char *argv[])
printInfo<FixedList<word, 2>>();
printInfo<Pair<word>>();
printInfo<std::pair<int, vector>>();
printInfo<FixedList<FixedList<int, 2>, 2>>();
printInfo<segment>();

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -180,6 +180,36 @@ int main(int argc, char *argv[])
}
}
// This will likely fail - not declared as is_contiguous
// Cannot even catch since it triggers an abort()
#if 0
{
std::pair<label,vector> sendData(Pstream::myProcNo(), vector::one);
const bool oldThrowingError = FatalError.throwing(true);
try
{
List<std::pair<label,vector>> countValues
(
UPstream::listGatherValues<std::pair<label, vector>>
(
sendData
)
);
Pout<< "listGather: " << flatOutput(countValues) << nl;
}
catch (const Foam::error& err)
{
Info<< err.message().c_str() << nl;
}
FatalError.throwing(oldThrowingError);
}
#endif
Info<< "\nEnd\n" << endl;
return 0;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -140,20 +140,15 @@ void Foam::vtk::writeValueParallel
}
// Gather [count, value] tuples, including from master
const List<std::pair<label, Type>> countValues
(
UPstream::listGatherValues<std::pair<label, Type>>
(
std::pair<label, Type>(count, val)
)
);
const List<label> counts(UPstream::listGatherValues(count));
const List<Type> values(UPstream::listGatherValues(val));
if (Pstream::master())
{
for (const auto& countVal : countValues)
forAll(counts, i)
{
// Write [count, value] tuple
vtk::write(fmt, countVal.first, countVal.second);
vtk::write(fmt, counts[i], values[i]);
}
}
}