From 4f50e60556602861685e1c92d81828753f7e2835 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 17 Dec 2020 11:02:35 +0100
Subject: [PATCH] WIP: short-circuit on direct detect of UNCOLLOCATED (#1946)

---
 .../fileOperation/fileOperation.C             | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
index 73e6adf28e4..d4260d2fd64 100644
--- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
+++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
@@ -270,6 +270,19 @@ Foam::fileOperation::lookupAndCacheProcessorsPath
         DynamicList<dirIndex> procDirs;
         fileNameList dirEntries;
 
+        // Fast path for UNCOLLATED
+        if
+        (
+            !syncPar
+         && numProcs == -1
+         && procPath.type(true) == fileName::Type::DIRECTORY
+        )
+        {
+            // Found "processorDDD"
+            dirEntries.resize(1);
+            dirEntries.first() = pDir;
+        }
+
         // Read all directories to see any beginning with processor
         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -287,7 +300,11 @@ Foam::fileOperation::lookupAndCacheProcessorsPath
         // from using read/send, but that doesn't matter since that is what
         // its own internals for readDir() do anyhow.
 
-        if (readDirMasterOnly && Pstream::parRun() /* && !distributed() */)
+        if (!dirEntries.empty())
+        {
+            // Fast-path invoked, skip readDir
+        }
+        else if (readDirMasterOnly && Pstream::parRun() /* && !distributed() */)
         {
             // Non-distributed.
             // Read on master only and send to subProcs
-- 
GitLab