From ff373afdccf6fbfc49f0614a55982ef56c033bc0 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Thu, 15 Aug 2013 15:31:15 +0100
Subject: [PATCH] BUG: codeStream: make sure scatter result is consumed before
 starting again

---
 .../functionEntries/codeStream/codeStream.C   | 56 +++++++++++++++++--
 1 file changed, 50 insertions(+), 6 deletions(-)

diff --git a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
index 8a12740cb6c..66065c4528a 100644
--- a/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
+++ b/src/OpenFOAM/db/dictionary/functionEntries/codeStream/codeStream.C
@@ -206,14 +206,26 @@ Foam::functionEntries::codeStream::getFunction
             off_t masterSize = mySize;
             Pstream::scatter(masterSize);
 
+            if (debug)
+            {
+                Pout<< endl<< "on processor " << Pstream::myProcNo()
+                    << " have masterSize:" << masterSize
+                    << " and localSize:" << mySize
+                    << endl;
+            }
+
+
             if (mySize < masterSize)
             {
-                Pout<< "Local file " << libPath
-                    << " not of same size (" << mySize
-                    << ") as master ("
-                    << masterSize << "). Waiting for "
-                    << regIOobject::fileModificationSkew
-                    << " seconds." << endl;
+                if (debug)
+                {
+                    Pout<< "Local file " << libPath
+                        << " not of same size (" << mySize
+                        << ") as master ("
+                        << masterSize << "). Waiting for "
+                        << regIOobject::fileModificationSkew
+                        << " seconds." << endl;
+                }
                 Foam::sleep(regIOobject::fileModificationSkew);
 
                 // Recheck local size
@@ -237,6 +249,14 @@ Foam::functionEntries::codeStream::getFunction
                         << exit(FatalIOError);
                 }
             }
+
+            if (debug)
+            {
+                Pout<< endl<< "on processor " << Pstream::myProcNo()
+                    << " after waiting: have masterSize:" << masterSize
+                    << " and localSize:" << mySize
+                    << endl;
+            }
         }
 
         if (isA<IOdictionary>(topDict(parentDict)))
@@ -244,6 +264,12 @@ Foam::functionEntries::codeStream::getFunction
             // Cached access to dl libs. Guarantees clean up upon destruction
             // of Time.
             dlLibraryTable& dlLibs = libs(parentDict);
+
+            if (debug)
+            {
+                Pout<< "Opening cached dictionary:" << libPath << endl;
+            }
+
             if (!dlLibs.open(libPath, false))
             {
                 FatalIOErrorIn
@@ -261,10 +287,28 @@ Foam::functionEntries::codeStream::getFunction
         else
         {
             // Uncached opening of libPath
+            if (debug)
+            {
+                Pout<< "Opening uncached dictionary:" << libPath << endl;
+            }
             lib = dlOpen(libPath, true);
         }
     }
 
+    bool haveLib = lib;
+    reduce(haveLib, andOp<bool>());
+
+    if (!haveLib)
+    {
+        FatalIOErrorIn
+        (
+            "functionEntries::codeStream::execute(..)",
+            parentDict
+        )   << "Failed loading library " << libPath
+            << " on some processors."
+            << exit(FatalIOError);
+    }
+
 
     // Find the function handle in the library
     streamingFunctionType function =
-- 
GitLab