masterUncollatedFileOperation.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017-2018 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "Pstream.H"
32 #include "Time.H"
33 #include "instant.H"
34 #include "IFstream.H"
35 #include "masterOFstream.H"
36 #include "decomposedBlockData.H"
37 #include "registerSwitch.H"
38 #include "dummyISstream.H"
39 #include "SubList.H"
40 #include "unthreadedInitialise.H"
41 #include "bitSet.H"
42 #include "IListStream.H"
43 
44 /* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
45 
46 namespace Foam
47 {
48 namespace fileOperations
49 {
50  defineTypeNameAndDebug(masterUncollatedFileOperation, 0);
52  (
53  fileOperation,
54  masterUncollatedFileOperation,
55  word
56  );
57 
59  (
60  Foam::debug::floatOptimisationSwitch("maxMasterFileBufferSize", 1e9)
61  );
63  (
64  "maxMasterFileBufferSize",
65  float,
67  );
68 
69  // Mark as not needing threaded mpi
71  (
73  masterUncollatedFileOperationInitialise,
74  word,
75  masterUncollated
76  );
77 }
78 }
79 
80 
81 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
82 
84 (
85  const label n
86 )
87 {
88  string ioRanksString(getEnv("FOAM_IORANKS"));
89  if (ioRanksString.empty())
90  {
91  return identity(n);
92  }
93  else
94  {
95  DynamicList<label> subRanks(n);
96 
97  IStringStream is(ioRanksString);
98  labelList ioRanks(is);
99 
100  if (!ioRanks.found(0))
101  {
103  << "Rank 0 (master) should be in the IO ranks. Currently "
104  << ioRanks << exit(FatalError);
105  }
106 
107  // The lowest numbered rank is the IO rank
108  const bitSet isIOrank(n, ioRanks);
109 
110  for (label proci = Pstream::myProcNo(); proci >= 0; --proci)
111  {
112  if (isIOrank[proci])
113  {
114  // Found my master. Collect all processors with same master
115  subRanks.append(proci);
116  for
117  (
118  label rank = proci+1;
119  rank < n && !isIOrank[rank];
120  ++rank
121  )
122  {
123  subRanks.append(rank);
124  }
125  break;
126  }
127  }
128  return subRanks;
129  }
130 }
131 
132 
135 (
136  const instantList& timeDirs,
137  const instant& t
138 )
139 {
140  // Note:
141  // - times will include constant (with value 0) as first element.
142  // For backwards compatibility make sure to find 0 in preference
143  // to constant.
144  // - list is sorted so could use binary search
145 
146  forAllReverse(timeDirs, i)
147  {
148  if (t.equal(timeDirs[i].value()))
149  {
150  return timeDirs[i].name();
151  }
152  }
153 
154  return word::null;
155 }
156 
157 
160 (
161  const bool checkGlobal,
162  const bool isFile,
163  const IOobject& io,
164  const bool search,
165  pathType& searchType,
166  word& procsDir,
167  word& newInstancePath
168 ) const
169 {
170  procsDir = word::null;
171  newInstancePath = word::null;
172 
173  if (io.instance().isAbsolute())
174  {
175  fileName objPath = io.instance()/io.name();
176 
177  if (isFileOrDir(isFile, objPath))
178  {
179  searchType = fileOperation::ABSOLUTE;
180  return objPath;
181  }
182  else
183  {
184  searchType = fileOperation::NOTFOUND;
185  return fileName::null;
186  }
187  }
188  else
189  {
190  // 1. Check the writing fileName
191  fileName writePath(objectPath(io, io.headerClassName()));
192 
193  if (isFileOrDir(isFile, writePath))
194  {
195  searchType = fileOperation::WRITEOBJECT;
196  return writePath;
197  }
198 
199  // 2. Check processors/
200  if (io.time().processorCase())
201  {
202  refPtr<dirIndexList> pDirs(lookupProcessorsPath(io.objectPath()));
203 
204  for (const dirIndex& dirIdx : pDirs())
205  {
206  const fileName& pDir = dirIdx.first();
207  fileName objPath =
208  processorsPath(io, io.instance(), pDir)
209  /io.name();
210  if (objPath != writePath && isFileOrDir(isFile, objPath))
211  {
212  searchType = dirIdx.second().first();
213  procsDir = pDir;
214  return objPath;
215  }
216  }
217  }
218  {
219  // 3. Check local
220  fileName localPath = io.objectPath();
221 
222  if
223  (
224  localPath != writePath
225  && isFileOrDir(isFile, localPath)
226  )
227  {
228  searchType = fileOperation::OBJECT;
229  return localPath;
230  }
231  }
232 
233 
234 
235  // Any global checks
236  if
237  (
238  checkGlobal
239  && io.time().processorCase()
240  && (
241  io.instance() == io.time().system()
242  || io.instance() == io.time().constant()
243  )
244  )
245  {
246  fileName parentPath =
247  io.rootPath()/io.time().globalCaseName()
248  /io.instance()/io.db().dbDir()/io.local()/io.name();
249 
250  if (isFileOrDir(isFile, parentPath))
251  {
252  searchType = fileOperation::PARENTOBJECT;
253  return parentPath;
254  }
255  }
256 
257  // Check for approximately same time. E.g. if time = 1e-2 and
258  // directory is 0.01 (due to different time formats)
259  const auto pathFnd = times_.cfind(io.time().path());
260 
261  if (search && pathFnd.found())
262  {
263  newInstancePath = findInstancePath
264  (
265  *pathFnd(),
266  instant(io.instance())
267  );
268 
269  if (newInstancePath.size() && newInstancePath != io.instance())
270  {
271  // 1. Try processors equivalent
273  (
274  lookupProcessorsPath(io.objectPath())
275  );
276 
277  for (const dirIndex& dirIdx : pDirs())
278  {
279  const fileName& pDir = dirIdx.first();
280 
281  fileName fName
282  (
283  processorsPath(io, newInstancePath, pDir)
284  /io.name()
285  );
286  if (isFileOrDir(isFile, fName))
287  {
288  switch (dirIdx.second().first())
289  {
290  case fileOperation::PROCUNCOLLATED:
291  {
292  searchType =
293  fileOperation::PROCUNCOLLATEDINSTANCE;
294  }
295  break;
296  case fileOperation::PROCBASEOBJECT:
297  {
298  searchType = fileOperation::PROCBASEINSTANCE;
299  }
300  break;
301  case fileOperation::PROCOBJECT:
302  {
303  searchType = fileOperation::PROCINSTANCE;
304  }
305  break;
306  default:
307  break;
308  }
309  procsDir = pDir;
310  return fName;
311  }
312  }
313 
314 
315  // 2. Check local
316  fileName fName
317  (
318  io.rootPath()/io.caseName()
319  /newInstancePath/io.db().dbDir()/io.local()/io.name()
320  );
321  if (isFileOrDir(isFile, fName))
322  {
323  searchType = fileOperation::FINDINSTANCE;
324  return fName;
325  }
326  }
327  }
328 
329  searchType = fileOperation::NOTFOUND;
330  return fileName::null;
331  }
332 }
333 
334 
337 (
338  const IOobject& io,
339  const pathType& searchType,
340  const word& procDir,
341  const word& instancePath
342 ) const
343 {
344  // Replacement for IOobject::objectPath()
345 
346  switch (searchType)
347  {
348  case fileOperation::ABSOLUTE:
349  {
350  return io.instance()/io.name();
351  }
352  break;
353 
354  case fileOperation::OBJECT:
355  {
356  return io.path()/io.name();
357  }
358  break;
359 
360  case fileOperation::WRITEOBJECT:
361  {
362  return objectPath(io, io.headerClassName());
363  }
364  break;
365 
366  case fileOperation::PROCUNCOLLATED:
367  {
368  // Uncollated type, e.g. processor1
369  const word procName
370  (
371  "processor" + Foam::name(Pstream::myProcNo(Pstream::worldComm))
372  );
373  return
374  processorsPath
375  (
376  io,
377  io.instance(),
378  (
379  Pstream::parRun()
380  ? procName
381  : procDir
382  )
383  )
384  /io.name();
385  }
386  break;
387 
388  case fileOperation::PROCBASEOBJECT:
389  {
390  // Collated, e.g. processors4
391  return
392  processorsPath(io, io.instance(), procDir)
393  /io.name();
394  }
395  break;
396 
397  case fileOperation::PROCOBJECT:
398  {
399  // Processors directory locally provided by the fileHandler itself
400  return
401  processorsPath(io, io.instance(), processorsDir(io))
402  /io.name();
403  }
404  break;
405 
406  case fileOperation::PARENTOBJECT:
407  {
408  return
409  io.rootPath()/io.time().globalCaseName()
410  /io.instance()/io.db().dbDir()/io.local()/io.name();
411  }
412  break;
413 
414  case fileOperation::FINDINSTANCE:
415  {
416  return
417  io.rootPath()/io.caseName()
418  /instancePath/io.db().dbDir()/io.local()/io.name();
419  }
420  break;
421 
422  case fileOperation::PROCUNCOLLATEDINSTANCE:
423  {
424  // Uncollated type, e.g. processor1
425  const word procName
426  (
427  "processor"
428  +Foam::name(Pstream::myProcNo(Pstream::worldComm))
429  );
430  return
431  processorsPath
432  (
433  io,
434  instancePath,
435  (
436  Pstream::parRun()
437  ? procName
438  : procDir
439  )
440  )
441  /io.name();
442  }
443  break;
444 
445  case fileOperation::PROCBASEINSTANCE:
446  {
447  // Collated, e.g. processors4
448  return
449  processorsPath(io, instancePath, procDir)
450  /io.name();
451  }
452  break;
453 
454  case fileOperation::PROCINSTANCE:
455  {
456  // Processors directory locally provided by the fileHandler itself
457  return
458  processorsPath(io, instancePath, processorsDir(io))
459  /io.name();
460  }
461  break;
462 
463  case fileOperation::NOTFOUND:
464  {
465  return fileName::null;
466  }
467  break;
468 
469  default:
470  {
472  return fileName::null;
473  }
474  }
475 }
476 
477 
479 (
480  const fileNameList& filePaths
481 )
482 {
483  const fileName& object0 = filePaths[0];
484 
485  for (label i = 1; i < filePaths.size(); i++)
486  {
487  if (filePaths[i] != object0)
488  {
489  return false;
490  }
491  }
492  return true;
493 }
494 
495 
497 (
498  const fileName& filePath,
499  const labelUList& procs,
500  PstreamBuffers& pBufs
501 )
502 {
503  IFstream ifs(filePath, IOstream::streamFormat::BINARY);
504 
505  if (!ifs.good())
506  {
507  FatalIOErrorInFunction(filePath)
508  << "Cannot open file " << filePath
509  << exit(FatalIOError);
510  }
511 
512  if (debug)
513  {
514  Pout<< "masterUncollatedFileOperation::readAndSend :"
515  << " compressed:" << bool(ifs.compression()) << " "
516  << filePath << endl;
517  }
518 
519  if (ifs.compression() == IOstream::compressionType::COMPRESSED)
520  {
521  // Could use Foam::fileSize, estimate uncompressed size (eg, 2x)
522  // and then string reserve followed by string assign...
523 
524  // Uncompress and read file contents into a character buffer
525  const std::string buf
526  (
527  std::istreambuf_iterator<char>(ifs.stdStream()),
528  std::istreambuf_iterator<char>()
529  );
530 
531  for (const label proci : procs)
532  {
533  UOPstream os(proci, pBufs);
534  os.write(buf.data(), buf.length());
535  }
536 
537  if (debug)
538  {
539  Pout<< "masterUncollatedFileOperation::readStream :"
540  << " From " << filePath << " sent " << buf.size()
541  << " bytes" << endl;
542  }
543  }
544  else
545  {
546  const off_t count(Foam::fileSize(filePath));
547 
548  // Read file contents into a character buffer
549  List<char> buf(static_cast<label>(count));
550  ifs.stdStream().read(buf.data(), count);
551 
552  for (const label proci : procs)
553  {
554  UOPstream os(proci, pBufs);
555  os.write(buf.cdata(), count);
556  }
557 
558  if (debug)
559  {
560  Pout<< "masterUncollatedFileOperation::readStream :"
561  << " From " << filePath << " sent " << buf.size()
562  << " bytes" << endl;
563  }
564  }
565 }
566 
567 
570 (
571  IOobject& io,
572  const label comm,
573  const bool uniform, // on comms master only
574  const fileNameList& filePaths, // on comms master only
575  const boolList& procValid // on comms master only
576 )
577 {
578  autoPtr<ISstream> isPtr;
579 
580  // const bool uniform = uniformFile(filePaths);
581 
582  PstreamBuffers pBufs
583  (
584  Pstream::commsTypes::nonBlocking,
585  Pstream::msgType(),
586  comm
587  );
588 
589  if (Pstream::master(comm))
590  {
591  if (uniform)
592  {
593  if (procValid[0])
594  {
595  if (filePaths[0].empty())
596  {
597  FatalIOErrorInFunction(filePaths[0])
598  << "cannot find file " << io.objectPath()
599  << exit(FatalIOError);
600  }
601 
602  DynamicList<label> validProcs(Pstream::nProcs(comm));
603  for (const int proci : Pstream::allProcs(comm))
604  {
605  if (procValid[proci])
606  {
607  validProcs.append(proci);
608  }
609  }
610 
611  // Read on master and send to all processors (including
612  // master for simplicity)
613  if (debug)
614  {
615  Pout<< "masterUncollatedFileOperation::readStream :"
616  << " For uniform file " << filePaths[0]
617  << " sending to " << validProcs
618  << " in comm:" << comm << endl;
619  }
620  readAndSend(filePaths[0], validProcs, pBufs);
621  }
622  }
623  else
624  {
625  if (procValid[0])
626  {
627  if (filePaths[0].empty())
628  {
629  FatalIOErrorInFunction(filePaths[0])
630  << "cannot find file " << io.objectPath()
631  << exit(FatalIOError);
632  }
633 
634  // Open master
635  isPtr.reset(new IFstream(filePaths[0]));
636 
637  // Read header
638  if (!io.readHeader(*isPtr))
639  {
640  FatalIOErrorInFunction(*isPtr)
641  << "problem while reading header for object "
642  << io.name() << exit(FatalIOError);
643  }
644  }
645 
646  // Read slave files
647  for (const int proci : Pstream::subProcs(comm))
648  {
649  if (debug)
650  {
651  Pout<< "masterUncollatedFileOperation::readStream :"
652  << " For processor " << proci
653  << " opening " << filePaths[proci] << endl;
654  }
655 
656  const fileName& fPath = filePaths[proci];
657 
658  if (procValid[proci] && !fPath.empty())
659  {
660  // Note: handle compression ourselves since size cannot
661  // be determined without actually uncompressing
662  readAndSend(fPath, labelList(one{}, proci), pBufs);
663  }
664  }
665  }
666  }
667 
668  labelList recvSizes;
669  pBufs.finishedSends(recvSizes);
670 
671  // isPtr will be valid on master and will be the unbuffered
672  // IFstream. Else the information is in the PstreamBuffers (and
673  // the special case of a uniform file)
674 
675  if (procValid[Pstream::myProcNo(comm)])
676  {
677  // This processor needs to return something
678 
679  if (!isPtr)
680  {
681  UIPstream is(Pstream::masterNo(), pBufs);
682 
683  List<char> buf(recvSizes[Pstream::masterNo()]);
684  if (recvSizes[Pstream::masterNo()] > 0)
685  {
686  is.read(buf.data(), recvSizes[Pstream::masterNo()]);
687  }
688 
689  if (debug)
690  {
691  Pout<< "masterUncollatedFileOperation::readStream :"
692  << " Done reading " << buf.size() << " bytes" << endl;
693  }
694 
695  // A local character buffer copy of the Pstream contents.
696  // Construct with same parameters (ASCII, current version)
697  // as the IFstream so that it has the same characteristics.
698 
699  isPtr.reset(new IListStream(std::move(buf)));
700 
701  // With the proper file name
702  isPtr->name() = filePaths[Pstream::myProcNo(comm)];
703 
704  if (!io.readHeader(*isPtr))
705  {
706  FatalIOErrorInFunction(*isPtr)
707  << "problem while reading header for object "
708  << io.name() << exit(FatalIOError);
709  }
710  }
711  }
712  else
713  {
714  isPtr.reset(new dummyISstream());
715  }
716 
717  return isPtr;
718 }
719 
720 
721 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
722 
725 (
726  bool verbose
727 )
728 :
730  (
731  UPstream::allocateCommunicator
732  (
733  UPstream::worldComm,
734  subRanks(Pstream::nProcs())
735  )
736  ),
737  myComm_(comm_)
738 {
739  verbose = (verbose && Foam::infoDetailLevel > 0);
740 
741  if (verbose)
742  {
743  DetailInfo
744  << "I/O : " << typeName
745  << " (maxMasterFileBufferSize " << maxMasterFileBufferSize << ')'
746  << endl;
747  }
748 
749  if (regIOobject::fileModificationChecking == regIOobject::timeStampMaster)
750  {
751  if (verbose)
752  {
754  << "Resetting fileModificationChecking to timeStamp" << endl;
755  }
756  regIOobject::fileModificationChecking = regIOobject::timeStamp;
757  }
758  else if
759  (
760  regIOobject::fileModificationChecking
761  == regIOobject::inotifyMaster
762  )
763  {
764  if (verbose)
765  {
767  << "Resetting fileModificationChecking to inotify"
768  << endl;
769  }
770  regIOobject::fileModificationChecking = regIOobject::inotify;
771  }
772 }
773 
774 
777 (
778  const label comm,
779  bool verbose
780 )
781 :
782  fileOperation(comm),
783  myComm_(-1)
784 {
785  verbose = (verbose && Foam::infoDetailLevel > 0);
786 
787  if (verbose)
788  {
789  DetailInfo
790  << "I/O : " << typeName
791  << " (maxMasterFileBufferSize " << maxMasterFileBufferSize << ')'
792  << endl;
793  }
794 
795  if (regIOobject::fileModificationChecking == regIOobject::timeStampMaster)
796  {
797  if (verbose)
798  {
800  << "Resetting fileModificationChecking to timeStamp" << endl;
801  }
802  regIOobject::fileModificationChecking = regIOobject::timeStamp;
803  }
804  else if
805  (
806  regIOobject::fileModificationChecking
807  == regIOobject::inotifyMaster
808  )
809  {
810  if (verbose)
811  {
813  << "Resetting fileModificationChecking to inotify"
814  << endl;
815  }
816  regIOobject::fileModificationChecking = regIOobject::inotify;
817  }
818 }
819 
820 
823 :
824  unthreadedInitialise(argc, argv)
825 {
826  // Filter out any of my arguments
827  const string s("-ioRanks");
828 
829  int index = -1;
830  for (int i=1; i<argc-1; i++)
831  {
832  if (argv[i] == s)
833  {
834  index = i;
835  setEnv("FOAM_IORANKS", argv[i+1], true);
836  break;
837  }
838  }
839 
840  if (index != -1)
841  {
842  for (int i=index+2; i<argc; i++)
843  {
844  argv[i-2] = argv[i];
845  }
846  argc -= 2;
847  }
848 }
849 
850 
851 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
852 
855 {
856  if (myComm_ != -1 && myComm_ != UPstream::worldComm)
857  {
859  }
860 }
861 
862 
863 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
864 
866 (
867  const fileName& dir,
868  mode_t mode
869 ) const
870 {
871  return masterOp<mode_t, mkDirOp>
872  (
873  dir,
874  mkDirOp(mode),
876  comm_
877  );
878 }
879 
880 
882 (
883  const fileName& fName,
884  mode_t mode
885 ) const
886 {
887  return masterOp<mode_t, chModOp>
888  (
889  fName,
890  chModOp(mode),
892  comm_
893  );
894 }
895 
896 
898 (
899  const fileName& fName,
900  const bool followLink
901 ) const
902 {
903  return masterOp<mode_t, modeOp>
904  (
905  fName,
906  modeOp(followLink),
908  comm_
909  );
910 }
911 
912 
914 (
915  const fileName& fName,
916  const bool followLink
917 ) const
918 {
919  return fileName::Type
920  (
921  masterOp<label, typeOp>
922  (
923  fName,
924  typeOp(followLink),
926  comm_
927  )
928  );
929 }
930 
931 
933 (
934  const fileName& fName,
935  const bool checkGzip,
936  const bool followLink
937 ) const
938 {
939  return masterOp<bool, existsOp>
940  (
941  fName,
942  existsOp(checkGzip, followLink),
944  comm_
945  );
946 }
947 
948 
950 (
951  const fileName& fName,
952  const bool followLink
953 ) const
954 {
955  return masterOp<bool, isDirOp>
956  (
957  fName,
958  isDirOp(followLink),
960  comm_
961  );
962 }
963 
964 
966 (
967  const fileName& fName,
968  const bool checkGzip,
969  const bool followLink
970 ) const
971 {
972  return masterOp<bool, isFileOp>
973  (
974  fName,
975  isFileOp(checkGzip, followLink),
977  comm_
978  );
979 }
980 
981 
983 (
984  const fileName& fName,
985  const bool followLink
986 ) const
987 {
988  return masterOp<off_t, fileSizeOp>
989  (
990  fName,
991  fileSizeOp(followLink),
993  comm_
994  );
995 }
996 
997 
999 (
1000  const fileName& fName,
1001  const bool followLink
1002 ) const
1003 {
1004  return masterOp<time_t, lastModifiedOp>
1005  (
1006  fName,
1007  lastModifiedOp(followLink),
1008  Pstream::msgType(),
1009  comm_
1010  );
1011 }
1012 
1013 
1016  const fileName& fName,
1017  const bool followLink
1018 ) const
1019 {
1020  return masterOp<double, lastModifiedHROp>
1021  (
1022  fName,
1023  lastModifiedHROp(followLink),
1024  Pstream::msgType(),
1025  comm_
1026  );
1027 }
1028 
1029 
1032  const fileName& fName,
1033  const std::string& ext
1034 ) const
1035 {
1036  return masterOp<bool, mvBakOp>
1037  (
1038  fName,
1039  mvBakOp(ext),
1040  Pstream::msgType(),
1041  comm_
1042  );
1043 }
1044 
1045 
1048  const fileName& fName
1049 ) const
1050 {
1051  return masterOp<bool, rmOp>
1052  (
1053  fName,
1054  rmOp(),
1055  Pstream::msgType(),
1056  comm_
1057  );
1058 }
1059 
1060 
1063  const fileName& dir,
1064  const bool silent
1065 ) const
1066 {
1067  return masterOp<bool, rmDirOp>
1068  (
1069  dir,
1070  rmDirOp(silent),
1071  Pstream::msgType(),
1072  comm_
1073  );
1074 }
1075 
1076 
1079  const fileName& dir,
1080  const fileName::Type type,
1081  const bool filtergz,
1082  const bool followLink
1083 ) const
1084 {
1085  return masterOp<fileNameList, readDirOp>
1086  (
1087  dir,
1088  readDirOp(type, filtergz, followLink),
1089  Pstream::msgType(),
1090  comm_
1091  );
1092 }
1093 
1094 
1097  const fileName& src,
1098  const fileName& dst,
1099  const bool followLink
1100 ) const
1101 {
1102  return masterOp<bool, cpOp>
1103  (
1104  src,
1105  dst,
1106  cpOp(followLink),
1107  Pstream::msgType(),
1108  comm_
1109  );
1110 }
1111 
1112 
1115  const fileName& src,
1116  const fileName& dst
1117 ) const
1118 {
1119  return masterOp<bool, lnOp>
1120  (
1121  src,
1122  dst,
1123  lnOp(),
1124  Pstream::msgType(),
1125  comm_
1126  );
1127 }
1128 
1129 
1132  const fileName& src,
1133  const fileName& dst,
1134  const bool followLink
1135 ) const
1136 {
1137  return masterOp<bool, mvOp>
1138  (
1139  src,
1140  dst,
1141  mvOp(followLink),
1142  Pstream::msgType(),
1143  comm_
1144  );
1145 }
1146 
1147 
1150  const bool checkGlobal,
1151  const IOobject& io,
1152  const word& typeName,
1153  const bool search
1154 ) const
1155 {
1156  if (debug)
1157  {
1158  Pout<< "masterUncollatedFileOperation::filePath :"
1159  << " objectPath:" << io.objectPath()
1160  << " checkGlobal:" << checkGlobal << endl;
1161  }
1162 
1163  // Now that we have an IOobject path use it to detect & cache
1164  // processor directory naming
1165  (void)lookupProcessorsPath(io.objectPath());
1166 
1167  // Trigger caching of times
1168  (void)findTimes(io.time().path(), io.time().constant());
1169 
1170 
1171  // Determine master filePath and scatter
1172 
1173  fileName objPath;
1174  pathType searchType = NOTFOUND;
1175  word procsDir;
1176  word newInstancePath;
1177 
1178  if (Pstream::master(comm_))
1179  {
1180  // All masters search locally. Note that global objects might
1181  // fail (except on master). This gets handled later on (in PARENTOBJECT)
1182  objPath =
1183  filePathInfo
1184  (
1185  checkGlobal,
1186  true,
1187  io,
1188  search,
1189  searchType,
1190  procsDir,
1191  newInstancePath
1192  );
1193 
1194  if (debug)
1195  {
1196  Pout<< "masterUncollatedFileOperation::filePath :"
1197  << " master objPath:" << objPath
1198  << " searchType:" << fileOperation::pathTypeNames_[searchType]
1199  << " procsDir:" << procsDir << " instance:" << newInstancePath
1200  << endl;
1201  }
1202  }
1203 
1204  // Scatter the information about where the master found the object
1205  // Note: use the worldComm to make sure all processors decide
1206  // the same type. Only procsDir is allowed to differ; searchType
1207  // and instance have to be same
1208  {
1209  label masterType(searchType);
1210  Pstream::scatter(masterType);
1211  searchType = pathType(masterType);
1212  }
1213  Pstream::scatter(newInstancePath);
1214 
1215  if
1216  (
1217  checkGlobal
1218  || searchType == fileOperation::PARENTOBJECT
1219  || searchType == fileOperation::PROCBASEOBJECT
1220  || searchType == fileOperation::PROCBASEINSTANCE
1221  || io.local() == "uniform"
1222  )
1223  {
1224  // Distribute master path. This makes sure it is seen as uniform
1225  // and only gets read from the master.
1226  Pstream::scatter(objPath);
1227  Pstream::scatter(procsDir);
1228  }
1229  else
1230  {
1231  Pstream::scatter(procsDir, Pstream::msgType(), comm_);
1232 
1233  // Use the master type to determine if additional information is
1234  // needed to construct the local equivalent
1235  switch (searchType)
1236  {
1240  {
1241  // Already handled above
1242  }
1243  break;
1244 
1252  {
1253  // Construct equivalent local path
1254  objPath = localObjectPath
1255  (
1256  io,
1257  searchType,
1258  procsDir,
1259  newInstancePath
1260  );
1261  }
1262  break;
1263 
1264  case fileOperation::OBJECT:
1266  {
1267  // Retest all processors separately since some processors might
1268  // have the file and some not (e.g. lagrangian data)
1269 
1270  objPath = masterOp<fileName, fileOrNullOp>
1271  (
1272  io.objectPath(),
1273  fileOrNullOp(true),
1274  Pstream::msgType(),
1275  comm_
1276  );
1277  }
1278  break;
1279  }
1280  }
1281 
1282  if (debug)
1283  {
1284  Pout<< "masterUncollatedFileOperation::filePath :"
1285  << " Returning from file searching:" << endl
1286  << " objectPath:" << io.objectPath() << endl
1287  << " filePath :" << objPath << endl << endl;
1288  }
1289  return objPath;
1290 }
1291 
1292 
1295  const bool checkGlobal,
1296  const IOobject& io,
1297  const bool search
1298 ) const
1299 {
1300  if (debug)
1301  {
1302  Pout<< "masterUncollatedFileOperation::dirPath :"
1303  << " objectPath:" << io.objectPath()
1304  << " checkGlobal:" << checkGlobal << endl;
1305  }
1306 
1307  // Now that we have an IOobject path use it to detect & cache
1308  // processor directory naming
1309  (void)lookupProcessorsPath(io.objectPath());
1310 
1311  // Determine master dirPath and scatter
1312 
1313  fileName objPath;
1314  pathType searchType = NOTFOUND;
1315  word procsDir;
1316  word newInstancePath;
1317 
1318  if (Pstream::master(comm_))
1319  {
1320  objPath = filePathInfo
1321  (
1322  checkGlobal,
1323  false,
1324  io,
1325  search,
1326  searchType,
1327  procsDir,
1328  newInstancePath
1329  );
1330  }
1331 
1332  {
1333  label masterType(searchType);
1334  Pstream::scatter(masterType); //, Pstream::msgType(), comm_);
1335  searchType = pathType(masterType);
1336  }
1337  Pstream::scatter(newInstancePath); //, Pstream::msgType(), comm_);
1338 
1339  if
1340  (
1341  checkGlobal
1342  || searchType == fileOperation::PARENTOBJECT
1343  || searchType == fileOperation::PROCBASEOBJECT
1344  || searchType == fileOperation::PROCBASEINSTANCE
1345  || io.local() == "uniform"
1346  )
1347  {
1348  // Distribute master path. This makes sure it is seen as uniform
1349  // and only gets read from the master.
1350  Pstream::scatter(objPath);
1351  Pstream::scatter(procsDir);
1352  }
1353  else
1354  {
1355  Pstream::scatter(procsDir, Pstream::msgType(), comm_);
1356 
1357  // Use the master type to determine if additional information is
1358  // needed to construct the local equivalent
1359  switch (searchType)
1360  {
1364  {
1365  // Already handled above
1366  }
1367  break;
1368 
1376  {
1377  // Construct equivalent local path
1378  objPath = localObjectPath
1379  (
1380  io,
1381  searchType,
1382  procsDir,
1383  newInstancePath
1384  );
1385  }
1386  break;
1387 
1388  case fileOperation::OBJECT:
1390  {
1391  // Retest all processors separately since some processors might
1392  // have the file and some not (e.g. lagrangian data)
1393 
1394  objPath = masterOp<fileName, fileOrNullOp>
1395  (
1396  io.objectPath(),
1397  fileOrNullOp(false),
1398  Pstream::msgType(),
1399  comm_
1400  );
1401  }
1402  break;
1403  }
1404  }
1405 
1406  if (debug)
1407  {
1408  Pout<< "masterUncollatedFileOperation::dirPath :"
1409  << " Returning from file searching:" << endl
1410  << " objectPath:" << io.objectPath() << endl
1411  << " filePath :" << objPath << endl << endl;
1412  }
1413  return objPath;
1414 }
1415 
1416 
1419  const dirIndexList& pDirs,
1420  IOobject& io
1421 ) const
1422 {
1423  // Cut-down version of filePathInfo that does not look for
1424  // different instance or parent directory
1425 
1426  const bool isFile = !io.name().empty();
1427 
1428  // Generate output filename for object
1429  const fileName writePath(objectPath(io, word::null));
1430 
1431  // 1. Test writing name for either directory or a (valid) file
1432  if (isFileOrDir(isFile, writePath))
1433  {
1434  return true;
1435  }
1436 
1437  // 2. Check processors/
1438  if (io.time().processorCase())
1439  {
1440  for (const dirIndex& dirIdx : pDirs)
1441  {
1442  const fileName& pDir = dirIdx.first();
1443  fileName procPath =
1444  processorsPath(io, io.instance(), pDir)
1445  /io.name();
1446  if (procPath != writePath && isFileOrDir(isFile, procPath))
1447  {
1448  return true;
1449  }
1450  }
1451  }
1452 
1453  // 3. Check local
1454  fileName localPath = io.objectPath();
1455 
1456  if (localPath != writePath && isFileOrDir(isFile, localPath))
1457  {
1458  return true;
1459  }
1460 
1461  return false;
1462 }
1463 
1464 
1468  const IOobject& startIO,
1469  const scalar startValue,
1470  const word& stopInstance
1471 ) const
1472 {
1473  if (debug)
1474  {
1475  Pout<< "masterUncollatedFileOperation::findInstance :"
1476  << " Starting searching for name:" << startIO.name()
1477  << " local:" << startIO.local()
1478  << " from instance:" << startIO.instance()
1479  << endl;
1480  }
1481 
1482 
1483  const Time& time = startIO.time();
1484 
1485  IOobject io(startIO);
1486 
1487  // Note: - if name is empty, just check the directory itself
1488  // - check both for isFile and headerOk since the latter does a
1489  // filePath so searches for the file.
1490  // - check for an object with local file scope (so no looking up in
1491  // parent directory in case of parallel)
1492 
1493 
1494  refPtr<dirIndexList> pDirs(lookupProcessorsPath(io.objectPath()));
1495 
1496  word foundInstance;
1497 
1498  // if (Pstream::master(comm_))
1500  {
1501  if (exists(pDirs, io))
1502  {
1503  foundInstance = io.instance();
1504  }
1505  }
1506 
1507  // Do parallel early exit to avoid calling time.times()
1508  // Pstream::scatter(foundInstance, Pstream::msgType(), comm_);
1510  if (!foundInstance.empty())
1511  {
1512  io.instance() = foundInstance;
1513  if (debug)
1514  {
1515  Pout<< "masterUncollatedFileOperation::findInstance :"
1516  << " for name:" << io.name() << " local:" << io.local()
1517  << " found starting instance:" << io.instance() << endl;
1518  }
1519  return io;
1520  }
1521 
1522 
1523  // Search back through the time directories to find the time
1524  // closest to and lower than current time
1525 
1526  instantList ts = time.times();
1527  // if (Pstream::master(comm_))
1529  {
1530  label instanceI;
1531 
1532  for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
1533  {
1534  if (ts[instanceI].value() <= startValue)
1535  {
1536  break;
1537  }
1538  }
1539 
1540  // continue searching from here
1541  for (; instanceI >= 0; --instanceI)
1542  {
1543  // Shortcut: if actual directory is the timeName we've
1544  // already tested it
1545  if (ts[instanceI].name() == time.timeName())
1546  {
1547  continue;
1548  }
1549 
1550  io.instance() = ts[instanceI].name();
1551  if (exists(pDirs, io))
1552  {
1553  foundInstance = io.instance();
1554  if (debug)
1555  {
1556  Pout<< "masterUncollatedFileOperation::findInstance :"
1557  << " for name:" << io.name() << " local:" << io.local()
1558  << " found at:" << io.instance()
1559  << endl;
1560  }
1561  break;
1562  }
1563 
1564  // Check if hit minimum instance
1565  if (ts[instanceI].name() == stopInstance)
1566  {
1567  if
1568  (
1569  startIO.readOpt() == IOobject::MUST_READ
1571  )
1572  {
1573  if (io.name().empty())
1574  {
1576  << "Cannot find directory "
1577  << io.local() << " in times " << time.timeName()
1578  << " down to " << stopInstance
1579  << exit(FatalError);
1580  }
1581  else
1582  {
1584  << "Cannot find file \"" << io.name()
1585  << "\" in directory " << io.local()
1586  << " in times " << time.timeName()
1587  << " down to " << stopInstance
1588  << exit(FatalError);
1589  }
1590  }
1591  foundInstance = io.instance();
1592  if (debug)
1593  {
1594  Pout<< "masterUncollatedFileOperation::findInstance :"
1595  << " name:" << io.name() << " local:" << io.local()
1596  << " found at stopinstance:" << io.instance() << endl;
1597  }
1598  break;
1599  }
1600  }
1601 
1602 
1603  if (foundInstance.empty())
1604  {
1605  // times() usually already includes the constant() so would
1606  // have been checked above. Re-test if
1607  // - times() is empty. Sometimes this can happen (e.g. decomposePar
1608  // with collated)
1609  // - times()[0] is not constant
1610  if (!ts.size() || ts[0].name() != time.constant())
1611  {
1612  // Note. This needs to be a hard-coded constant, rather than the
1613  // constant function of the time, because the latter points to
1614  // the case constant directory in parallel cases
1615 
1616  io.instance() = time.constant();
1617  if (exists(pDirs, io))
1618  {
1619  if (debug)
1620  {
1621  Pout<< "masterUncollatedFileOperation::findInstance :"
1622  << " name:" << io.name()
1623  << " local:" << io.local()
1624  << " found at:" << io.instance() << endl;
1625  }
1626  foundInstance = io.instance();
1627  }
1628  }
1629  }
1630 
1631  if (foundInstance.empty())
1632  {
1633  if
1634  (
1635  startIO.readOpt() == IOobject::MUST_READ
1637  )
1638  {
1640  << "Cannot find file \"" << io.name() << "\" in directory "
1641  << io.local() << " in times " << startIO.instance()
1642  << " down to " << time.constant()
1643  << exit(FatalError);
1644  }
1645  else
1646  {
1647  foundInstance = time.constant();
1648  }
1649  }
1650  }
1651 
1652  // Pstream::scatter(foundInstance, Pstream::msgType(), comm_);
1654  io.instance() = foundInstance;
1655  if (debug)
1656  {
1657  Pout<< "masterUncollatedFileOperation::findInstance :"
1658  << " name:" << io.name() << " local:" << io.local()
1659  << " returning instance:" << io.instance() << endl;
1660  }
1661  return io;
1662 }
1663 
1664 
1668  const objectRegistry& db,
1669  const fileName& instance,
1670  const fileName& local,
1671  word& newInstance
1672 ) const
1673 {
1674  if (debug)
1675  {
1676  Pout<< "masterUncollatedFileOperation::readObjects :"
1677  << " db:" << db.objectPath()
1678  << " local:" << local << " instance:" << instance << endl;
1679  }
1680 
1681  fileNameList objectNames;
1682  newInstance = word::null;
1683 
1684  // Note: readObjects uses WORLD to make sure order of objects is the
1685  // same everywhere
1686 
1687  if (Pstream::master()) // comm_))
1688  {
1689  // Avoid fileOperation::readObjects from triggering parallel ops
1690  // (through call to filePath which triggers parallel )
1691  const bool oldParRun = UPstream::parRun(false);
1692 
1693  //- Use non-time searching version
1694  objectNames = fileOperation::readObjects
1695  (
1696  db,
1697  instance,
1698  local,
1699  newInstance
1700  );
1701 
1702  if (newInstance.empty())
1703  {
1704  // Find similar time
1705 
1706  // Copy of Time::findInstancePath. We want to avoid the
1707  // parallel call to findTimes. Alternative is to have
1708  // version of findInstancePath that takes instantList ...
1709  const instantList timeDirs
1710  (
1712  (
1713  db.time().path(),
1714  db.time().constant()
1715  )
1716  );
1717 
1718  const instant t(instance);
1719  forAllReverse(timeDirs, i)
1720  {
1721  if (t.equal(timeDirs[i].value()))
1722  {
1723  objectNames = fileOperation::readObjects
1724  (
1725  db,
1726  timeDirs[i].name(), // newly found time
1727  local,
1728  newInstance
1729  );
1730  break;
1731  }
1732  }
1733  }
1734 
1735  UPstream::parRun(oldParRun); // Restore parallel state
1736  }
1737 
1738  Pstream::scatter(newInstance); //, Pstream::msgType(), comm_);
1739  Pstream::scatter(objectNames); //, Pstream::msgType(), comm_);
1740 
1741  if (debug)
1742  {
1743  Pout<< "masterUncollatedFileOperation::readObjects :"
1744  << " newInstance:" << newInstance
1745  << " objectNames:" << objectNames << endl;
1746  }
1747 
1748  return objectNames;
1749 }
1750 
1751 
1754  IOobject& io,
1755  const fileName& fName,
1756  const word& typeName
1757 ) const
1758 {
1759  bool ok = false;
1760 
1761  if (debug)
1762  {
1763  Pout<< "masterUncollatedFileOperation::readHeader :" << endl
1764  << " objectPath:" << io.objectPath() << endl
1765  << " fName :" << fName << endl;
1766  }
1767 
1768  // Get filePaths on world master
1770  filePaths[Pstream::myProcNo(Pstream::worldComm)] = fName;
1772  bool uniform = uniformFile(filePaths);
1774 
1775  if (uniform)
1776  {
1778  {
1779  if (!fName.empty())
1780  {
1781  IFstream is(fName);
1782 
1783  if (is.good())
1784  {
1785  ok = io.readHeader(is);
1786  if (io.headerClassName() == decomposedBlockData::typeName)
1787  {
1788  // Read the header inside the container (master data)
1790  }
1791  }
1792  }
1793  }
1796  (
1797  io.headerClassName(),
1798  Pstream::msgType(),
1800  );
1802  }
1803  else
1804  {
1806  {
1807  // Re-gather file paths on local master
1808  filePaths.setSize(Pstream::nProcs(comm_));
1809  filePaths[Pstream::myProcNo(comm_)] = fName;
1810  Pstream::gatherList(filePaths, Pstream::msgType(), comm_);
1811  }
1812 
1813  boolList result(Pstream::nProcs(comm_), false);
1814  wordList headerClassName(Pstream::nProcs(comm_));
1815  stringList note(Pstream::nProcs(comm_));
1816  if (Pstream::master(comm_))
1817  {
1818  forAll(filePaths, proci)
1819  {
1820  if (!filePaths[proci].empty())
1821  {
1822  if (proci > 0 && filePaths[proci] == filePaths[proci-1])
1823  {
1824  result[proci] = result[proci-1];
1825  headerClassName[proci] = headerClassName[proci-1];
1826  note[proci] = note[proci-1];
1827  }
1828  else
1829  {
1830  IFstream is(filePaths[proci]);
1831 
1832  if (is.good())
1833  {
1834  result[proci] = io.readHeader(is);
1835  if
1836  (
1837  io.headerClassName()
1838  == decomposedBlockData::typeName
1839  )
1840  {
1841  // Read the header inside the container
1842  // (master data)
1843  result[proci] = decomposedBlockData::
1845  (
1846  io,
1847  is
1848  );
1849  }
1850  headerClassName[proci] = io.headerClassName();
1851  note[proci] = io.note();
1852  }
1853  }
1854  }
1855  }
1856  }
1857  ok = scatterList(result, Pstream::msgType(), comm_);
1858  io.headerClassName() = scatterList
1859  (
1860  headerClassName,
1861  Pstream::msgType(),
1862  comm_
1863  );
1864  io.note() = scatterList(note, Pstream::msgType(), comm_);
1865  }
1866 
1867  if (debug)
1868  {
1869  Pout<< "masterUncollatedFileOperation::readHeader :" << " ok:" << ok
1870  << " class:" << io.headerClassName() << endl;
1871  }
1872  return ok;
1873 }
1874 
1875 
1879  regIOobject& io,
1880  const fileName& fName,
1881  const word& typeName,
1882  const bool valid
1883 ) const
1884 {
1885  if (debug)
1886  {
1887  Pout<< "masterUncollatedFileOperation::readStream :"
1888  << " object : " << io.name()
1889  << " global : " << io.global()
1890  << " fName : " << fName << " valid:" << valid << endl;
1891  }
1892 
1893 
1894  autoPtr<ISstream> isPtr;
1895  bool isCollated = false;
1896  IOobject headerIO(io);
1897 
1898  // Detect collated format. This could be done on the local communicator
1899  // but we do it on the master node only for now.
1900  if (UPstream::master()) // comm_))
1901  {
1902  if (!fName.empty())
1903  {
1904  // This can happen in lagrangian field reading some processors
1905  // have no file to read from. This will only happen when using
1906  // normal writing since then the fName for the valid processors is
1907  // processorDDD/<instance>/.. . In case of collocated writing
1908  // the fName is already rewritten to processors/.
1909 
1910  isPtr.reset(new IFstream(fName));
1911 
1912  if (isPtr->good())
1913  {
1914  // Read header data (on copy)
1915  headerIO.readHeader(*isPtr);
1916 
1917  if (headerIO.headerClassName() == decomposedBlockData::typeName)
1918  {
1919  isCollated = true;
1920  }
1921  else if (!Pstream::parRun())
1922  {
1923  // Short circuit: non-collated format. No parallel bits.
1924  // Copy header and return.
1925  if (debug)
1926  {
1927  Pout<< "masterUncollatedFileOperation::readStream :"
1928  << " For object : " << io.name()
1929  << " doing straight IFstream input from "
1930  << fName << endl;
1931  }
1932  io = headerIO;
1933  return isPtr;
1934  }
1935  }
1936 
1937  if (!isCollated)
1938  {
1939  // Close file. Reopened below.
1940  isPtr.clear();
1941  }
1942  }
1943  }
1944 
1945  Pstream::scatter(isCollated); //, Pstream::msgType(), comm_);
1946 
1947  if (isCollated)
1948  {
1949  if (debug)
1950  {
1951  Pout<< "masterUncollatedFileOperation::readStream :"
1952  << " For object : " << io.name()
1953  << " starting collating input from " << fName << endl;
1954  }
1955 
1956 
1957  // Analyse the file path (on (co)master) to see the processors type
1958  // Note: this should really be part of filePath() which should return
1959  // both file and index in file.
1960 
1961  fileName path, procDir, local;
1963  label nProcs;
1964  splitProcessorPath(fName, path, procDir, local, group, nProcs);
1965 
1966 
1967  if (!Pstream::parRun())
1968  {
1969  // Analyse the objectpath to find out the processor we're trying
1970  // to access
1971  label proci = detectProcessorPath(io.objectPath());
1972 
1973  if (proci == -1)
1974  {
1975  FatalIOErrorInFunction(*isPtr)
1976  << "Could not detect processor number"
1977  << " from objectPath:" << io.objectPath()
1978  << exit(FatalIOError);
1979  }
1980 
1981  // The local rank (offset)
1982  if (!group.empty())
1983  {
1984  proci = proci - group.start();
1985  }
1986 
1987  if (debug)
1988  {
1989  Pout<< "masterUncollatedFileOperation::readStream :"
1990  << " For object : " << io.name()
1991  << " starting input from block " << proci
1992  << " of " << isPtr->name() << endl;
1993  }
1994 
1995  return decomposedBlockData::readBlock(proci, *isPtr, io);
1996  }
1997  else
1998  {
1999  // Get size of file
2000  off_t sz = Foam::fileSize(fName);
2001  bool bigSize = sz > off_t(maxMasterFileBufferSize);
2002  Pstream::scatter(bigSize);
2003 
2004  // Are we reading from single-master file ('processors256') or
2005  // from multi-master files ('processors256_0-9')
2006  label readComm = -1;
2007  if (!group.empty())
2008  {
2009  readComm = comm_;
2010  if (UPstream::master(comm_) && !isPtr && !fName.empty())
2011  {
2012  // In multi-master mode also open the file on the other
2013  // masters
2014  isPtr.reset(new IFstream(fName));
2015 
2016  if (isPtr->good())
2017  {
2018  // Read header data (on copy)
2019  IOobject headerIO(io);
2020  headerIO.readHeader(*isPtr);
2021  }
2022  }
2023  }
2024  else
2025  {
2026  // Single master so read on world
2027  readComm = Pstream::worldComm;
2028  }
2029 
2030  // Read my data
2032  (
2033  readComm,
2034  fName,
2035  isPtr,
2036  io,
2037  (
2038  bigSize
2041  )
2042  );
2043  }
2044  }
2045  else
2046  {
2047  if (debug)
2048  {
2049  Pout<< "masterUncollatedFileOperation::readStream :"
2050  << " For object : " << io.name()
2051  << " starting separated input from " << fName << endl;
2052  }
2053 
2054  if (io.global())
2055  {
2056  // Use worldComm. Note: should not really need to gather filePaths
2057  // since we enforce sending from master anyway ...
2058  fileNameList filePaths(Pstream::nProcs());
2059  filePaths[Pstream::myProcNo()] = fName;
2060  Pstream::gatherList(filePaths);
2061  boolList procValid(Pstream::nProcs());
2062  procValid[Pstream::myProcNo()] = valid;
2063  Pstream::gatherList(procValid);
2064 
2065  return read(io, Pstream::worldComm, true, filePaths, procValid);
2066  }
2067  else
2068  {
2069  // Use local communicator
2070  fileNameList filePaths(Pstream::nProcs(comm_));
2071  filePaths[Pstream::myProcNo(comm_)] = fName;
2072  Pstream::gatherList(filePaths, Pstream::msgType(), comm_);
2073  boolList procValid(Pstream::nProcs(comm_));
2074  procValid[Pstream::myProcNo(comm_)] = valid;
2075  Pstream::gatherList(procValid, Pstream::msgType(), comm_);
2076 
2077  // Uniform in local comm
2078  const bool uniform = uniformFile(filePaths);
2079 
2080  return read(io, comm_, uniform, filePaths, procValid);
2081  }
2082  }
2083 }
2084 
2085 
2088  regIOobject& io,
2089  const bool masterOnly,
2091  const word& typeName
2092 ) const
2093 {
2094  bool ok = true;
2095 
2096  if (io.globalObject())
2097  {
2098  if (debug)
2099  {
2100  Pout<< "masterUncollatedFileOperation::read :"
2101  << " Reading global object " << io.name() << endl;
2102  }
2103 
2104  bool ok = false;
2105  if (Pstream::master()) // comm_))
2106  {
2107  // Do master-only reading always.
2108  const bool oldParRun = UPstream::parRun(false);
2109 
2110  ok = io.readData(io.readStream(typeName));
2111  io.close();
2112 
2113  UPstream::parRun(oldParRun); // Restore parallel state
2114  }
2115 
2116  Pstream::scatter(ok); //, Pstream::msgType(), comm_);
2117  Pstream::scatter(io.headerClassName()); //, Pstream::msgType(), comm_);
2118  Pstream::scatter(io.note()); //, Pstream::msgType(), comm_);
2119 
2120 
2121  // scatter operation for regIOobjects
2122 
2123  // Get my communication order
2124  // const List<Pstream::commsStruct>& comms =
2125  //(
2126  // (Pstream::nProcs(comm_) < Pstream::nProcsSimpleSum)
2127  // ? Pstream::linearCommunication(comm_)
2128  // : Pstream::treeCommunication(comm_)
2129  //);
2130  // const Pstream::commsStruct& myComm = comms[Pstream::myProcNo(comm_)];
2131  const List<Pstream::commsStruct>& comms =
2132  (
2136  );
2137  const Pstream::commsStruct& myComm =
2139 
2140  // Receive from up
2141  if (myComm.above() != -1)
2142  {
2143  IPstream fromAbove
2144  (
2146  myComm.above(),
2147  0,
2148  Pstream::msgType(),
2149  Pstream::worldComm, // comm_,
2150  format
2151  );
2152  ok = io.readData(fromAbove);
2153  }
2154 
2155  // Send to my downstairs neighbours
2156  forAll(myComm.below(), belowI)
2157  {
2158  OPstream toBelow
2159  (
2161  myComm.below()[belowI],
2162  0,
2163  Pstream::msgType(),
2164  Pstream::worldComm, // comm_,
2165  format
2166  );
2167  bool okWrite = io.writeData(toBelow);
2168  ok = ok && okWrite;
2169  }
2170  }
2171  else
2172  {
2173  if (debug)
2174  {
2175  Pout<< "masterUncollatedFileOperation::read :"
2176  << " Reading local object " << io.name() << endl;
2177  }
2178 
2179  ok = io.readData(io.readStream(typeName));
2180  io.close();
2181  }
2182 
2183  return ok;
2184 }
2185 
2186 
2189  const regIOobject& io,
2190  IOstreamOption streamOpt,
2191  const bool valid
2192 ) const
2193 {
2194  fileName pathName(io.objectPath());
2195 
2196  if (debug)
2197  {
2198  Pout<< "masterUncollatedFileOperation::writeObject :"
2199  << " io:" << pathName << " valid:" << valid << endl;
2200  }
2201 
2202  // Make sure to pick up any new times
2203  setTime(io.time());
2204 
2205  autoPtr<OSstream> osPtr(NewOFstream(pathName, streamOpt, valid));
2206  OSstream& os = osPtr();
2207 
2208  // If any of these fail, return (leave error handling to Ostream class)
2209  if (!os.good())
2210  {
2211  return false;
2212  }
2213 
2214  if (!io.writeHeader(os))
2215  {
2216  return false;
2217  }
2218 
2219  // Write the data to the Ostream
2220  if (!io.writeData(os))
2221  {
2222  return false;
2223  }
2224 
2226 
2227  return true;
2228 }
2229 
2230 
2233  const fileName& directory,
2234  const word& constantName
2235 ) const
2236 {
2237  const auto iter = times_.cfind(directory);
2238  if (iter.found())
2239  {
2240  if (debug)
2241  {
2242  Pout<< "masterUncollatedFileOperation::findTimes :"
2243  << " Found " << iter()->size() << " cached times" << endl;
2244  }
2245  return *iter();
2246  }
2247  else
2248  {
2249  instantList times;
2250  if (Pstream::master()) // comm_))
2251  {
2252  // Do master-only reading always.
2253  const bool oldParRun = UPstream::parRun(false);
2254 
2255  times = fileOperation::findTimes(directory, constantName);
2256 
2257  UPstream::parRun(oldParRun); // Restore parallel state
2258  }
2259  Pstream::scatter(times); //, Pstream::msgType(), comm_);
2260 
2261  // Note: do we also cache if no times have been found since it might
2262  // indicate a directory that is being filled later on ...
2263 
2264  instantList* tPtr = new instantList(std::move(times));
2265 
2266  times_.set(directory, tPtr);
2267 
2268  if (debug)
2269  {
2270  Pout<< "masterUncollatedFileOperation::findTimes :"
2271  << " Caching times:" << *tPtr << nl
2272  << " for directory:" << directory << endl;
2273  }
2274  return *tPtr;
2275  }
2276 }
2277 
2278 
2281  const Time& tm
2282 ) const
2283 {
2284  if (tm.subCycling())
2285  {
2286  return;
2287  }
2288 
2289  // Mutable access to instantList for modification and sorting
2290  // - cannot use auto type deduction here
2291 
2292  HashPtrTable<instantList>::iterator iter = times_.find(tm.path());
2293 
2294  if (iter.found())
2295  {
2296  instantList& times = *iter();
2297 
2298  const instant timeNow(tm.value(), tm.timeName());
2299 
2300  // Exclude constant when checking and sorting
2301  const label skipConst =
2302  (
2303  (!times.empty() && times[0].name() == tm.constant())
2304  ? 1
2305  : 0
2306  );
2307 
2308  if
2309  (
2311  (
2312  SubList<instant>(times, times.size()-skipConst, skipConst),
2313  timeNow
2314  )
2315  == -1
2316  )
2317  {
2318  if (debug)
2319  {
2320  Pout<< "masterUncollatedFileOperation::setTime :"
2321  << " Caching time " << tm.timeName()
2322  << " for case:" << tm.path() << endl;
2323  }
2324 
2325  times.append(timeNow);
2326  SubList<instant> realTimes
2327  (
2328  times, times.size()-skipConst, skipConst
2329  );
2330  Foam::stableSort(realTimes);
2331  }
2332  }
2333 
2335 }
2336 
2337 
2341  const fileName& filePath
2342 ) const
2343 {
2344  autoPtr<ISstream> isPtr;
2345 
2346  if (Pstream::parRun())
2347  {
2348  // Insert logic of filePath. We assume that if a file is absolute
2349  // on the master it is absolute also on the slaves etc.
2350 
2352  filePaths[Pstream::myProcNo(Pstream::worldComm)] = filePath;
2354 
2355  PstreamBuffers pBufs
2356  (
2358  Pstream::msgType(),
2360  );
2361 
2363  {
2364  const bool uniform = uniformFile(filePaths);
2365 
2366  if (uniform)
2367  {
2368  if (debug)
2369  {
2370  Pout<< "masterUncollatedFileOperation::NewIFstream :"
2371  << " Opening global file " << filePath << endl;
2372  }
2373 
2374  readAndSend
2375  (
2376  filePath,
2378  pBufs
2379  );
2380  }
2381  else
2382  {
2383  for (const int proci : Pstream::subProcs(Pstream::worldComm))
2384  {
2385  readAndSend
2386  (
2387  filePaths[proci],
2388  labelList(one{}, proci),
2389  pBufs
2390  );
2391  }
2392  }
2393  }
2394 
2395 
2396  labelList recvSizes;
2397  pBufs.finishedSends(recvSizes);
2398 
2400  {
2401  // Read myself
2402  isPtr.reset(new IFstream(filePaths[Pstream::masterNo()]));
2403  }
2404  else
2405  {
2406  if (debug)
2407  {
2408  Pout<< "masterUncollatedFileOperation::NewIFstream :"
2409  << " Reading " << filePath
2410  << " from processor " << Pstream::masterNo() << endl;
2411  }
2412 
2413  UIPstream is(Pstream::masterNo(), pBufs);
2414 
2415  List<char> buf(recvSizes[Pstream::masterNo()]);
2416  is.read(buf.data(), buf.size());
2417 
2418  if (debug)
2419  {
2420  Pout<< "masterUncollatedFileOperation::NewIFstream :"
2421  << " Done reading " << buf.size() << " bytes" << endl;
2422  }
2423 
2424  // A local character buffer copy of the Pstream contents.
2425  // Construct with same parameters (ASCII, current version)
2426  // as the IFstream so that it has the same characteristics.
2427 
2428  isPtr.reset(new IListStream(std::move(buf)));
2429 
2430  // With the proper file name
2431  isPtr->name() = filePath;
2432  }
2433  }
2434  else
2435  {
2436  // Read myself
2437  isPtr.reset(new IFstream(filePath));
2438  }
2439 
2440  return isPtr;
2441 }
2442 
2443 
2447  const fileName& pathName,
2448  IOstreamOption streamOpt,
2449  const bool valid
2450 ) const
2451 {
2452  return autoPtr<OSstream>
2453  (
2454  new masterOFstream
2455  (
2456  pathName,
2457  streamOpt,
2458  false, // append=false
2459  valid
2460  )
2461  );
2462 }
2463 
2464 
2466 {
2468  times_.clear();
2469 }
2470 
2471 
2474  const fileName& fName
2475 ) const
2476 {
2477  label watchFd = -1;
2478  if (Pstream::master()) // comm_))
2479  {
2480  watchFd = monitor().addWatch(fName);
2481  }
2482  Pstream::scatter(watchFd); //, Pstream::msgType(), comm_);
2483  return watchFd;
2484 }
2485 
2486 
2489  const label watchIndex
2490 ) const
2491 {
2492  bool ok = false;
2493  if (Pstream::master()) // comm_))
2494  {
2495  ok = monitor().removeWatch(watchIndex);
2496  }
2497  Pstream::scatter(ok); //, Pstream::msgType(), comm_);
2498  return ok;
2499 }
2500 
2501 
2504  const labelList& watchIndices,
2505  const fileName& fName
2506 ) const
2507 {
2508  label index = -1;
2509 
2510  if (Pstream::master()) // comm_))
2511  {
2512  forAll(watchIndices, i)
2513  {
2514  if (monitor().getFile(watchIndices[i]) == fName)
2515  {
2516  index = i;
2517  break;
2518  }
2519  }
2520  }
2521  Pstream::scatter(index); //, Pstream::msgType(), comm_);
2522  return index;
2523 }
2524 
2525 
2528  regIOobject& rio,
2529  const fileNameList& files
2530 ) const
2531 {
2532  const labelList& watchIndices = rio.watchIndices();
2533 
2534  DynamicList<label> newWatchIndices;
2535  labelHashSet removedWatches(watchIndices);
2536 
2537  for (const fileName& f : files)
2538  {
2539  const label index = findWatch(watchIndices, f);
2540 
2541  if (index == -1)
2542  {
2543  newWatchIndices.append(addWatch(f));
2544  }
2545  else
2546  {
2547  // Existing watch
2548  newWatchIndices.append(watchIndices[index]);
2549  removedWatches.erase(index);
2550  }
2551  }
2552 
2553  // Remove any unused watches
2554  for (const label index : removedWatches)
2555  {
2556  removeWatch(watchIndices[index]);
2557  }
2558 
2559  rio.watchIndices() = newWatchIndices;
2560 }
2561 
2562 
2565  const label watchIndex
2566 ) const
2567 {
2568  fileName fName;
2569  if (Pstream::master()) // comm_))
2570  {
2571  fName = monitor().getFile(watchIndex);
2572  }
2573  Pstream::scatter(fName); //, Pstream::msgType(), comm_);
2574  return fName;
2575 }
2576 
2577 
2580  const bool masterOnly,
2581  const bool syncPar
2582 ) const
2583 {
2584  if (Pstream::master()) // comm_))
2585  {
2586  monitor().updateStates(true, false);
2587  }
2588 }
2589 
2590 
2594  const label watchFd
2595 ) const
2596 {
2597  unsigned int state = fileMonitor::UNMODIFIED;
2598  if (Pstream::master()) // comm_))
2599  {
2600  state = monitor().getState(watchFd);
2601  }
2602  Pstream::scatter(state); //, Pstream::msgType(), comm_);
2603  return fileMonitor::fileState(state);
2604 }
2605 
2606 
2609  const label watchFd
2610 ) const
2611 {
2612  if (Pstream::master()) // comm_))
2613  {
2614  monitor().setUnmodified(watchFd);
2615  }
2616 }
2617 
2618 
2619 // ************************************************************************* //
Foam::fileOperations::masterUncollatedFileOperation::setUnmodified
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
Definition: masterUncollatedFileOperation.C:2608
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::fileOperations::masterUncollatedFileOperation::type
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or LINK.
Definition: masterUncollatedFileOperation.C:914
Foam::fileOperations::masterUncollatedFileOperation::getFile
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
Definition: masterUncollatedFileOperation.C:2564
Foam::UPstream::linearCommunication
static const List< commsStruct > & linearCommunication(const label communicator=worldComm)
Communication schedule for linear all-to-master (proc 0)
Definition: UPstream.H:524
Foam::autoPtr::reset
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:109
Foam::TimePaths::globalCaseName
const fileName & globalCaseName() const
Return global case name.
Definition: TimePathsI.H:48
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::fileOperation::PARENTOBJECT
Definition: fileOperation.H:93
Foam::fileOperations::masterUncollatedFileOperation::cp
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
Definition: masterUncollatedFileOperation.C:1096
Foam::UPstream::commsTypes::nonBlocking
Foam::fileOperations::masterUncollatedFileOperation::setTime
virtual void setTime(const Time &) const
Callback for time change.
Definition: masterUncollatedFileOperation.C:2280
Foam::fileOperations::masterUncollatedFileOperation::readAndSend
static void readAndSend(const fileName &filePath, const labelUList &procs, PstreamBuffers &pBufs)
Read file contents and send to processors.
Definition: masterUncollatedFileOperation.C:497
Foam::UPstream::masterNo
static constexpr int masterNo() noexcept
Process index of the master (always 0)
Definition: UPstream.H:452
Foam::exists
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: MSwindows.C:625
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
SubList.H
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:70
Foam::fileOperations::masterUncollatedFileOperation::dirPath
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory. checkGlobal : also check undecomposed.
Definition: masterUncollatedFileOperation.C:1294
Foam::fileOperations::masterUncollatedFileOperation::lastModifiedOp
Definition: masterUncollatedFileOperation.H:228
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileOperation
An encapsulation of filesystem-related operations.
Definition: fileOperation.H:77
Foam::UOPstream
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:57
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::fileMonitor::UNMODIFIED
Definition: fileMonitor.H:75
Foam::fileOperations::masterUncollatedFileOperation::mvBakOp
Definition: masterUncollatedFileOperation.H:260
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::fileOperations::masterUncollatedFileOperation::uniformFile
static bool uniformFile(const fileNameList &)
Same file?
Definition: masterUncollatedFileOperation.C:479
Foam::fileOperations::masterUncollatedFileOperation::readDir
virtual fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true, const bool followLink=true) const
Read a directory and return the entries as a string list.
Definition: masterUncollatedFileOperation.C:1078
Foam::constant::atomic::group
constexpr const char *const group
Group name for atomic constants.
Definition: atomicConstants.H:52
Foam::fileOperations::masterUncollatedFileOperation::rmDirOp
Definition: masterUncollatedFileOperation.H:284
Foam::fileOperations::masterUncollatedFileOperation::lastModifiedHROp
Definition: masterUncollatedFileOperation.H:244
Foam::regIOobject::watchIndices
const labelList & watchIndices() const
Return file-monitoring handles.
Definition: regIOobjectI.H:196
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:53
Foam::DynamicList< label >
Foam::IntRange
An interval of (signed) integers defined by a start and a size.
Definition: IntRange.H:63
Foam::decomposedBlockData::readBlock
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
Definition: decomposedBlockData.C:232
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
Foam::IOobject::writeEndDivider
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
Definition: IOobjectWriteHeader.C:109
Foam::regIOobject::writeData
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
Foam::dummyISstream
Dummy input stream, which can be used as a placeholder for interfaces taking an Istream or ISstream....
Definition: dummyISstream.H:56
masterOFstream.H
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::IOobject::rootPath
const fileName & rootPath() const
Definition: IOobject.C:469
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobjectI.H:191
Foam::fileOperations::masterUncollatedFileOperation::mode
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
Definition: masterUncollatedFileOperation.C:898
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:87
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
Foam::fileOperations::masterUncollatedFileOperation::isFile
virtual bool isFile(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist as a FILE in the file system?
Definition: masterUncollatedFileOperation.C:966
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::fileOperation::pathTypeNames_
static const Enum< pathType > pathTypeNames_
Definition: fileOperation.H:99
Foam::fileOperation::PROCINSTANCE
Definition: fileOperation.H:97
Foam::fileOperation::flush
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
Definition: fileOperation.C:1120
Foam::fileOperations::masterUncollatedFileOperation::fileSize
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
Definition: masterUncollatedFileOperation.C:983
Foam::fileName::Type
Type
Enumerations to handle directory entry types.
Definition: fileName.H:76
Foam::one
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:61
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:458
Foam::regIOobject::global
virtual bool global() const
Is object global.
Definition: regIOobject.H:342
Foam::Pstream::scatter
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
Definition: gatherScatter.C:150
Foam::fileMonitor::fileState
fileState
Enumeration defining the file state.
Definition: fileMonitor.H:73
Foam::isFile
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
Definition: MSwindows.C:658
Foam::IListStream
An ISstream with internal List storage.
Definition: IListStream.H:133
Foam::fileOperations::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(fileOperationInitialise, collatedFileOperationInitialise, word, collated)
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:182
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
instant.H
Foam::setEnv
bool setEnv(const word &name, const std::string &value, const bool overwrite)
Set an environment variable, return true on success.
Definition: MSwindows.C:395
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
Foam::Instant::equal
bool equal(scalar val) const
True if values are equal (includes SMALL for rounding)
Definition: Instant.C:59
Foam::fileOperations::masterUncollatedFileOperation::mv
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
Definition: masterUncollatedFileOperation.C:1131
Foam::fileOperations::masterUncollatedFileOperation::maxMasterFileBufferSize
static float maxMasterFileBufferSize
Max size of parallel communications. Switches from non-blocking.
Definition: masterUncollatedFileOperation.H:485
Foam::fileOperations::masterUncollatedFileOperation::chMod
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
Definition: masterUncollatedFileOperation.C:882
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::HashSet< label, Hash< label > >
bitSet.H
Foam::IOobject::time
const Time & time() const
Return time.
Definition: IOobject.C:463
Foam::instantList
List< instant > instantList
List of instants.
Definition: instantList.H:44
setTime
runTimeSource setTime(sourceTimes[sourceTimeIndex], sourceTimeIndex)
Foam::fileOperations::masterUncollatedFileOperationInitialise::masterUncollatedFileOperationInitialise
masterUncollatedFileOperationInitialise(int &argc, char **&argv)
Construct from components.
Definition: masterUncollatedFileOperation.C:822
Foam::fileOperation::ABSOLUTE
Definition: fileOperation.H:85
Foam::fileOperations::masterUncollatedFileOperation::isDirOp
Definition: masterUncollatedFileOperation.H:179
Foam::getEnv
string getEnv(const std::string &envName)
Get environment value for given envName.
Definition: MSwindows.C:371
Foam::fileOperation::findTimes
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
Definition: fileOperation.C:815
Foam::fileOperations::masterUncollatedFileOperation::~masterUncollatedFileOperation
virtual ~masterUncollatedFileOperation()
Destructor.
Definition: masterUncollatedFileOperation.C:854
Foam::fileOperations::masterUncollatedFileOperation::fileOrNullOp
Definition: masterUncollatedFileOperation.H:343
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::stableSort
void stableSort(UList< T > &a)
Definition: UList.C:268
Foam::fileOperations::masterUncollatedFileOperation::typeOp
Definition: masterUncollatedFileOperation.H:147
Foam::IOobject::readHeader
bool readHeader(Istream &is)
Read header.
Definition: IOobjectReadHeader.C:35
dummyISstream.H
Foam::UIPstream::read
static label read(const commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Read into given buffer from given processor and return the.
Definition: UIPread.C:81
Foam::fileOperations::registerOptSwitch
registerOptSwitch("maxThreadFileBufferSize", float, collatedFileOperation::maxThreadFileBufferSize)
Foam::IOobject::db
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:457
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::mode
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Definition: MSwindows.C:564
Foam::Time::subCycling
label subCycling() const
Definition: Time.H:515
Foam::fileOperations::masterUncollatedFileOperation::readStream
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool valid=true) const
Reads header for regIOobject and returns an ISstream.
Definition: masterUncollatedFileOperation.C:1878
Foam::fileOperations::masterUncollatedFileOperation::modeOp
Definition: masterUncollatedFileOperation.H:132
Foam::uniform
Definition: uniform.H:50
n
label n
Definition: TABSMDCalcMethod2.H:31
format
word format(conversionProperties.get< word >("format"))
Foam::fileOperations::masterUncollatedFileOperation::read
static autoPtr< ISstream > read(IOobject &io, const label comm, const bool uniform, const fileNameList &filePaths, const boolList &procValid)
Read files on comms master.
Definition: masterUncollatedFileOperation.C:570
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:445
Foam::objectRegistry::dbDir
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
Definition: objectRegistry.H:198
Foam::IOobject::local
const fileName & local() const
Definition: IOobjectI.H:203
Foam::UOPstream::write
static bool write(const commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Write given buffer to given processor.
Definition: UOPwrite.C:36
Foam::UPstream::subProcs
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
Definition: UPstream.H:516
Foam::fileSize
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
Definition: MSwindows.C:676
Foam::fileOperations::masterUncollatedFileOperation::filePath
virtual fileName filePath(const bool checkGlobal, const IOobject &io, const word &typeName, const bool search) const
Search for an object. checkGlobal : also check undecomposed case.
Definition: masterUncollatedFileOperation.C:1149
Foam::decomposedBlockData::readMasterHeader
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
Definition: decomposedBlockData.C:165
Foam::HashTable::erase
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
Definition: HashTable.C:392
Foam::fileOperations::masterUncollatedFileOperation::fileSizeOp
Definition: masterUncollatedFileOperation.H:212
Foam::fileOperations::masterUncollatedFileOperation::rmOp
Definition: masterUncollatedFileOperation.H:275
Foam::fileOperation::pathType
pathType
Enumeration for the location of an IOobject.
Definition: fileOperation.H:82
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fileOperation::setTime
virtual void setTime(const Time &) const
Callback for time change.
Definition: fileOperation.H:551
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:474
Foam::fileOperations::masterUncollatedFileOperation::lastModified
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
Definition: masterUncollatedFileOperation.C:999
Foam::fileOperations::masterUncollatedFileOperation::writeObject
virtual bool writeObject(const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
Definition: masterUncollatedFileOperation.C:2188
Foam::IOobject::caseName
const fileName & caseName() const
Definition: IOobject.C:475
Foam::fileOperations::addToRunTimeSelectionTable
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
Foam::IOobject::globalObject
bool globalObject() const
Is object same for all processors?
Definition: IOobjectI.H:124
Foam::fileOperations::masterUncollatedFileOperation::findWatch
virtual label findWatch(const labelList &watchIndices, const fileName &) const
Find index (or -1) of file in list of handles.
Definition: masterUncollatedFileOperation.C:2503
Foam::TimePaths::times
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:149
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::fileOperations::masterUncollatedFileOperation::exists
bool exists(const dirIndexList &, IOobject &io) const
Helper: check IO for local existence. Like filePathInfo but.
Definition: masterUncollatedFileOperation.C:1418
Foam::OSstream
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:54
Foam::fileOperations::masterUncollatedFileOperation::existsOp
Definition: masterUncollatedFileOperation.H:162
Foam::fileOperations::masterUncollatedFileOperation::cpOp
Definition: masterUncollatedFileOperation.H:302
Foam::findSortedIndex
label findSortedIndex(const ListType &input, typename ListType::const_reference val, const label start=0)
Foam::UPstream::freeCommunicator
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
Definition: UPstream.C:166
Foam::fileOperations::masterUncollatedFileOperation::highResLastModified
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
Definition: masterUncollatedFileOperation.C:1015
Foam::fileOperation::NOTFOUND
Definition: fileOperation.H:84
Foam::fileOperations::masterUncollatedFileOperation::removeWatch
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
Definition: masterUncollatedFileOperation.C:2488
DetailInfo
#define DetailInfo
Definition: evalEntry.C:36
Foam::fileOperations::unthreadedInitialise
Definition: unthreadedInitialise.H:46
IFstream.H
Foam::fileOperation::PROCBASEINSTANCE
Definition: fileOperation.H:96
Foam::PstreamBuffers::finishedSends
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
Definition: PstreamBuffers.C:80
Foam::UPstream::commsTypes::scheduled
Foam::fileOperations::masterUncollatedFileOperation::masterUncollatedFileOperation
masterUncollatedFileOperation(bool verbose)
Construct null.
Definition: masterUncollatedFileOperation.C:725
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::FatalError
error FatalError
Foam::fileOperations::masterUncollatedFileOperation::updateStates
virtual void updateStates(const bool masterOnly, const bool syncPar) const
Update state of all files.
Definition: masterUncollatedFileOperation.C:2579
Foam::fileOperation::PROCUNCOLLATEDINSTANCE
Definition: fileOperation.H:95
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fileOperations::masterUncollatedFileOperation::isFileOp
Definition: masterUncollatedFileOperation.H:195
Pstream.H
Foam::IStringStream
Input from string buffer, using a ISstream.
Definition: StringStream.H:111
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fileOperations::masterUncollatedFileOperation::rmDir
virtual bool rmDir(const fileName &dir, const bool silent=false) const
Remove a directory and its contents.
Definition: masterUncollatedFileOperation.C:1062
Foam::fileOperations::masterUncollatedFileOperation::mvBak
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
Definition: masterUncollatedFileOperation.C:1031
fileOperationInitialise
Foam::UPstream::commsStruct::above
label above() const
Definition: UPstream.H:132
Foam::fileOperations::masterUncollatedFileOperation::readObjects
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Definition: masterUncollatedFileOperation.C:1667
Foam::infoDetailLevel
int infoDetailLevel
Global for selective suppression of Info output.
Foam::UPstream::commsStruct
Structure for communicating between processors.
Definition: UPstream.H:83
Foam::fileOperations::masterUncollatedFileOperation::filePathInfo
virtual fileName filePathInfo(const bool checkGlobal, const bool isFile, const IOobject &, const bool search, pathType &searchType, word &processorsDir, word &instance) const
Search (locally!) for object; return info on how it was found.
Definition: masterUncollatedFileOperation.C:160
Foam::fileOperations::masterUncollatedFileOperation::findInstancePath
static word findInstancePath(const instantList &timeDirs, const instant &t)
Equivalent of Time::findInstance.
Definition: masterUncollatedFileOperation.C:135
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::fileOperations::masterUncollatedFileOperation::mkDir
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
Definition: masterUncollatedFileOperation.C:866
Foam::IOobject::headerClassName
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobjectI.H:88
Foam::fileOperations::masterUncollatedFileOperation::getState
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
Definition: masterUncollatedFileOperation.C:2593
IListStream.H
Foam::UPstream::nProcsSimpleSum
static int nProcsSimpleSum
Definition: UPstream.H:280
Foam::IFstream::stdStream
virtual std::istream & stdStream()
Access to underlying std::istream.
Definition: IFstream.C:94
unthreadedInitialise.H
Time.H
Foam::IOobject::note
const string & note() const
Return the optional note.
Definition: IOobjectI.H:100
Foam::autoPtr< Foam::ISstream >
Foam::fileOperations::masterUncollatedFileOperation::chModOp
Definition: masterUncollatedFileOperation.H:117
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:71
Foam::fileOperations::masterUncollatedFileOperation::flush
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
Definition: masterUncollatedFileOperation.C:2465
masterUncollatedFileOperation.H
Foam::TimePaths::system
const word & system() const
Return system name.
Definition: TimePathsI.H:94
Foam::UPstream::msgType
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:541
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::Pstream::gatherList
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Definition: gatherScatterList.C:52
Foam::debug::floatOptimisationSwitch
float floatOptimisationSwitch(const char *name, const float deflt=0)
Lookup optimisation switch or add default value.
Definition: debug.C:243
Foam::decomposedBlockData::readBlocks
static bool readBlocks(const label comm, autoPtr< ISstream > &isPtr, List< char > &data, const UPstream::commsTypes commsType)
Read data into *this. ISstream is only valid on master.
Definition: decomposedBlockData.C:312
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:464
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:358
Foam::fileOperations::masterUncollatedFileOperation::addWatch
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
Definition: masterUncollatedFileOperation.C:2473
Foam::fileOperations::masterUncollatedFileOperation::rm
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
Definition: masterUncollatedFileOperation.C:1047
f
labelList f(nPoints)
Foam::regIOobject::close
void close()
Close Istream.
Definition: regIOobjectRead.C:182
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::fileOperation::WRITEOBJECT
Definition: fileOperation.H:87
decomposedBlockData.H
Foam::UPstream::worldComm
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:295
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::IOobject::readOpt
readOption readOpt() const
The read option.
Definition: IOobjectI.H:165
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::fileOperations::masterUncollatedFileOperation::NewIFstream
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
Definition: masterUncollatedFileOperation.C:2340
Foam::UList< label >
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::fileOperation::readObjects
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Definition: fileOperation.C:1015
path
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
bool
bool
Definition: EEqn.H:20
Foam::search
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:576
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:121
Foam::fileOperations::masterUncollatedFileOperation::readHeader
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
Definition: masterUncollatedFileOperation.C:1753
Foam::fileOperation::PROCOBJECT
Definition: fileOperation.H:91
Foam::fileOperations::masterUncollatedFileOperation::isDir
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
Definition: masterUncollatedFileOperation.C:950
Foam::autoPtr::clear
void clear() noexcept
Same as reset(nullptr)
Definition: autoPtr.H:181
Foam::fileOperations::masterUncollatedFileOperation::lnOp
Definition: masterUncollatedFileOperation.H:318
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:309
Foam::fileOperations::masterUncollatedFileOperation::localObjectPath
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
Definition: masterUncollatedFileOperation.C:337
Foam::fileOperation::PROCUNCOLLATED
Definition: fileOperation.H:88
Foam::regIOobject::readData
virtual bool readData(Istream &)
Virtual readData function.
Definition: regIOobjectRead.C:196
Foam::fileOperations::masterUncollatedFileOperation::readDirOp
Definition: masterUncollatedFileOperation.H:364
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
Foam::fileOperation::FINDINSTANCE
Definition: fileOperation.H:94
Foam::IOobject::writeHeader
bool writeHeader(Ostream &os) const
Write header.
Definition: IOobjectWriteHeader.C:156
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
registerSwitch.H
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
Foam::UPstream::treeCommunication
static const List< commsStruct > & treeCommunication(const label communicator=worldComm)
Communication schedule for tree all-to-master (proc 0)
Definition: UPstream.H:533
Foam::fileOperations::masterUncollatedFileOperation::NewOFstream
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool valid=true) const
Generate an OSstream that writes a file.
Definition: masterUncollatedFileOperation.C:2446
Foam::UIPstream
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:56
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:57
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:224
Foam::fileOperations::masterUncollatedFileOperation::findTimes
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
Definition: masterUncollatedFileOperation.C:2232
Foam::IOobject::objectPath
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:209
Foam::TimePaths::processorCase
bool processorCase() const
Return true if this is a processor case.
Definition: TimePathsI.H:36
Foam::IOstreamOption::compression
compressionType compression() const noexcept
Get the stream compression.
Definition: IOstreamOption.H:315
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
Foam::fileOperations::masterUncollatedFileOperation::ln
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
Definition: masterUncollatedFileOperation.C:1114
Foam::fileOperation::OBJECT
Definition: fileOperation.H:86
Foam::HashPtrTable::iterator
typename parent_type::iterator iterator
Definition: HashPtrTable.H:88
Foam::IOobject::path
fileName path() const
The complete path.
Definition: IOobject.C:481
Foam::fileOperations::masterUncollatedFileOperation::addWatches
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
Definition: masterUncollatedFileOperation.C:2527
Foam::fileOperations::masterUncollatedFileOperation::mkDirOp
Definition: masterUncollatedFileOperation.H:102
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
Foam::fileOperations::masterUncollatedFileOperation::subRanks
static labelList subRanks(const label n)
Get the list of processors that are part of this communicator.
Definition: masterUncollatedFileOperation.C:84
Foam::fileName::isAbsolute
static bool isAbsolute(const std::string &str)
Return true if string starts with a '/'.
Definition: fileNameI.H:136
Foam::masterOFstream
Master-only drop-in replacement for OFstream.
Definition: masterOFstream.H:51
Foam::UPstream::nProcs
static label nProcs(const label communicator=worldComm)
Number of processes in parallel run, and 1 for serial run.
Definition: UPstream.H:446
Foam::fileOperations::defineTypeNameAndDebug
defineTypeNameAndDebug(collatedFileOperation, 0)
Foam::fileOperation::PROCBASEOBJECT
Definition: fileOperation.H:89
Foam::fileOperations::masterUncollatedFileOperation::mvOp
Definition: masterUncollatedFileOperation.H:327
Foam::UPstream::commsStruct::below
const labelList & below() const
Definition: UPstream.H:137
Foam::refPtr
A class for managing references or pointers (no reference counting)
Definition: PtrList.H:60
Foam::IOobject::MUST_READ
Definition: IOobject.H:120
Foam::fileOperations::masterUncollatedFileOperation::findInstance
virtual IOobject findInstance(const IOobject &io, const scalar startValue, const word &stopInstance) const
Find instance where IOobject is. Fails if cannot be found.
Definition: masterUncollatedFileOperation.C:1467