From 810e4a11e1613eb24042ee6a0d5d9fdcc5c116c9 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 8 Oct 2020 18:23:54 +0200
Subject: [PATCH] BUG: parallel foamToEnsight fails depending on lagrangian
 order (fixes #1873)

- the problem arises when output fields are missing on some
  processors.

  When the information is combined, the resulting HashTables can have
  different insertion orders. This poses an issue when there are hash
  key collisions and thus different chaining.

- Use sorted order.
---
 .../dataConversion/foamToEnsight/convertLagrangian.H   | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H
index b0478d844c4..5b087931b48 100644
--- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H
+++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/convertLagrangian.H
@@ -73,10 +73,10 @@ if (doLagrangian)
             }
         }
 
-        forAllConstIters(theseCloudFields, fieldIter)
+        // Field order may differ on individual processors, so sort by name
+        for (const word& fieldName : theseCloudFields.sortedToc())
         {
-            const word& fieldName = fieldIter.key();
-            const word& fieldType = fieldIter.val();
+            const word& fieldType = theseCloudFields[fieldName];
 
             IOobject fieldObject
             (
@@ -94,9 +94,13 @@ if (doLagrangian)
                 // but that combination does not work.
                 // So check the header and sync globally
 
+                const bool parRun = Pstream::parRun();
+                Pstream::parRun() = false;
+
                 fieldExists =
                     fieldObject.typeHeaderOk<IOField<scalar>>(false);
 
+                Pstream::parRun() = parRun;
                 reduce(fieldExists, orOp<bool>());
             }
 
-- 
GitLab