MCPcopy Create free account
hub / github.com/Kitware/VTK / ScanForProcessorDirs

Function ScanForProcessorDirs

IO/Parallel/vtkPOpenFOAMReader.cxx:169–346  ·  view source on GitHub ↗

Search and list processor subdirectories Detect collated and uncollated processor directories - "processor(\d+)" - "processors(\d+)" - "processors(\d+)_(\d+)-(\d+)" string parsing logic as per fileOperation / parseProcsNumRange from OpenFOAM-v2012 Return either collated or uncollated directories, never a mix. Use the number of components to distinguish

Source from the content-addressed store, hash-verified

167// Return either collated or uncollated directories, never a mix.
168// Use the number of components to distinguish
169vtkSmartPointer<vtkIntArray> ScanForProcessorDirs(vtkDirectory* dir)
170{
171 // Uncollated: save processor id
172 auto uncollated = vtkSmartPointer<vtkIntArray>::New();
173 uncollated->SetNumberOfComponents(1);
174
175 // Collated: save (processor count, first, size) tuple
176 auto collated = vtkSmartPointer<vtkIntArray>::New();
177 collated->SetNumberOfComponents(3);
178
179 // Sort keys for collated
180 vtkNew<vtkIntArray> collatedNums;
181 int procTuple[3] = { 0, 0, 0 };
182
183 const vtkIdType nFiles = dir->GetNumberOfFiles();
184 for (vtkIdType filei = 0; filei < nFiles; ++filei)
185 {
186 const char* subdir = dir->GetFile(filei);
187
188 if (strncmp(subdir, "processor", 9) != 0 || !dir->FileIsDirectory(subdir))
189 {
190 continue;
191 }
192
193 if (isdigit(subdir[9]))
194 {
195 // processor<digits>
196 const char* nptr = (subdir + 9);
197
198 errno = 0;
199 long parsed;
200 auto result = vtk::from_chars(nptr, parsed);
201 if (errno || nptr == result.ptr)
202 {
203 continue; // bad parse
204 }
205 const auto procId = static_cast<int>(parsed);
206
207 // Require end of string
208 if (*(result.ptr) == '\0')
209 {
210 uncollated->InsertNextValue(procId);
211 }
212 }
213 else if (subdir[9] == 's' && isdigit(subdir[10]))
214 {
215 // processors<digits> or processors<digits>_<digits>-<digits>
216 const char* nptr = (subdir + 10);
217
218 // 1. numProcs
219 errno = 0;
220 long parsed;
221 auto result = vtk::from_chars(nptr, parsed);
222 if (errno || nptr == result.ptr)
223 {
224 continue; // bad parse
225 }
226 const auto nProcs = static_cast<int>(parsed);

Callers 1

RequestInformationMethod · 0.85

Calls 13

from_charsFunction · 0.85
NewFunction · 0.50
SortFunction · 0.50
SetNumberOfComponentsMethod · 0.45
GetNumberOfFilesMethod · 0.45
GetFileMethod · 0.45
FileIsDirectoryMethod · 0.45
InsertNextValueMethod · 0.45
SqueezeMethod · 0.45
GetNumberOfTuplesMethod · 0.45
GetValueMethod · 0.45
GetTypedTupleMethod · 0.45

Tested by

no test coverage detected