diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index e47fb46342..68a67b2c09 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -1690,15 +1690,26 @@ void Foam::argList::parse ) { label nProcDirs = 0; - while - ( - isDir + { + const bool oldParRun(UPstream::parRun(false)); + // Don't cache processor directories (probably not + // needed since master-only + const int oldCacheLevel(fileOperation::cacheLevel(0)); + // Accept any processorsXXX + const int oldFilter(fileOperation::nProcsFilter(0)); + + nProcDirs = fileHandler().nProcs ( - rootPath_/globalCase_ - / ("processor" + Foam::name(++nProcDirs)) - ) - ) - {} + rootPath_/globalCase_, + "", + dictNProcs // expected nProcs + ); + + fileOperation::nProcsFilter(oldFilter); + fileOperation::cacheLevel(oldCacheLevel); + UPstream::parRun(oldParRun); + } + if (nProcDirs != Pstream::nProcs()) { diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C index e10ea04e44..8addedf1d5 100644 --- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C +++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C @@ -1290,7 +1290,8 @@ Foam::fileNameList Foam::fileOperation::readObjects Foam::label Foam::fileOperation::nProcs ( const fileName& dir, - const fileName& local + const fileName& local, + const label wanted // expected nProcs. 0 if not supplied ) const { label nProcs = 0; @@ -1298,6 +1299,25 @@ Foam::label Foam::fileOperation::nProcs { fileNameList dirNames(Foam::readDir(dir, fileName::Type::DIRECTORY)); + // E.g. (maybe left over) + // processor0 + // processor1 + // processors5 + // processor90 // gap! + // processors10 + // + //- if wanted is 2 then processor0,1 is enough + //- if wanted is not set then return highest valid range + // (processors10 in above case) + //- if wanted cannot be matched (e.g. 37) return 0 + + // For marking off contiguous ranges + bitSet foundDirs; + if (wanted > 0) + { + foundDirs.resize(wanted); + } + // Detect any processorsDDD or processorDDD label maxProc = -1; for (const fileName& dirN : dirNames) @@ -1310,15 +1330,38 @@ Foam::label Foam::fileOperation::nProcs splitProcessorPath(dirN, rp, rd, rl, group, rNum); maxProc = max(maxProc, readProci); - if (rNum != -1) + + if (rNum > 0) // processorsDDD where DDD>0 { - // Direct detection of processorsDDD - maxProc = rNum-1; - break; + // Use processors number + maxProc = max(maxProc, rNum-1); + // Mark in cache. TBD separate handling for groups? + foundDirs.set(labelRange(0, rNum)); + + if (wanted == rNum) + { + // Exact match of processorsDDD. Direct exit. + maxProc = rNum-1; + foundDirs.resize(rNum); + break; + } + } + else if (readProci >= 0) + { + // Mark in cache + foundDirs.set(readProci); } } nProcs = maxProc+1; + // Override with any gaps in processorDDD numbering (can never happen + // with collated) + const label gapIndex = foundDirs.find_first_not(); + if (gapIndex > 0) + { + nProcs = gapIndex-1; + } + if (nProcs == 0 && Foam::isDir(dir/processorsBaseDir)) { WarningInFunction diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H index 5de0a2a149..8053d6dfa8 100644 --- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H +++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H @@ -862,7 +862,9 @@ public: virtual label nProcs ( const fileName& dir, - const fileName& local = "" + const fileName& local = "", + //! >0 if we know in advance what we're looking for + const label wantedNProcs = 0 ) const; //- Get sorted list of times diff --git a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C index c505683363..182b526706 100644 --- a/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C +++ b/src/OpenFOAM/global/fileOperations/masterUncollatedFileOperation/masterUncollatedFileOperation.C @@ -1983,7 +1983,7 @@ bool Foam::fileOperations::masterUncollatedFileOperation::readHeader { Pout<< "masterUncollatedFileOperation::readHeader :" << " ok:" << ok << " class:" << io.headerClassName() - << " for file:" << fName << endl;; + << " for file:" << fName << endl; } return ok; } diff --git a/tutorials/mesh/parallel/cavity/Allrun b/tutorials/mesh/parallel/cavity/Allrun index 75a0ebc376..49e9aa72a3 100755 --- a/tutorials/mesh/parallel/cavity/Allrun +++ b/tutorials/mesh/parallel/cavity/Allrun @@ -8,18 +8,19 @@ restore0Dir runApplication blockMesh decompDict5="-decomposeParDict system/decomposeParDict.5" +fileHandler="-fileHandler uncollated" # redistributePar to do decomposition -runParallel -s decompose redistributePar -decompose +runParallel -s decompose redistributePar -decompose $fileHandler # Bit of renumbering and running -runParallel -s CuthillMcKee renumberMesh -overwrite -runParallel -s CuthillMcKee icoFoam +runParallel -s CuthillMcKee renumberMesh -overwrite $fileHandler +runParallel -s CuthillMcKee icoFoam $fileHandler # Bit of bad renumbering and running runParallel -s random renumberMesh \ - -overwrite -dict system/renumberMeshDict-random -runParallel -s random icoFoam + -overwrite -dict system/renumberMeshDict-random $fileHandler +runParallel -s random icoFoam $fileHandler # Pick up last result cp system/controlDict-latestTime system/controlDict @@ -27,13 +28,13 @@ cp system/controlDict-latestTime system/controlDict # Redistribute to 5 processors. Note that new processors only get written # a mesh to the current time (0.505). Use -overwrite instead to write the # mesh to constant. -runParallel -s 5 $decompDict5 redistributePar -cellDist +runParallel -s 5 $decompDict5 redistributePar -cellDist $fileHandler # Run a bit more -runParallel -s 5 $decompDict5 icoFoam +runParallel -s 5 $decompDict5 icoFoam $fileHandler # Reconstruct mesh and results. Note the time argument to make sure we # only pick up the new decomposition -runParallel -s reconstruct -np 5 redistributePar -reconstruct -time 0.505: +runParallel -s reconstruct -np 5 redistributePar -reconstruct -time 0.505: $fileHandler #------------------------------------------------------------------------------