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 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  tmpNrc<dirIndexList> pDirs(lookupProcessorsPath(io.objectPath()));
203  forAll(pDirs(), i)
204  {
205  const fileName& pDir = pDirs()[i].first();
206  fileName objPath =
207  processorsPath(io, io.instance(), pDir)
208  /io.name();
209  if (objPath != writePath && isFileOrDir(isFile, objPath))
210  {
211  searchType = pDirs()[i].second().first();
212  procsDir = pDir;
213  return objPath;
214  }
215  }
216  }
217  {
218  // 3. Check local
219  fileName localPath = io.objectPath();
220 
221  if
222  (
223  localPath != writePath
224  && isFileOrDir(isFile, localPath)
225  )
226  {
227  searchType = fileOperation::OBJECT;
228  return localPath;
229  }
230  }
231 
232 
233 
234  // Any global checks
235  if
236  (
237  checkGlobal
238  && io.time().processorCase()
239  && (
240  io.instance() == io.time().system()
241  || io.instance() == io.time().constant()
242  )
243  )
244  {
245  fileName parentPath =
246  io.rootPath()/io.time().globalCaseName()
247  /io.instance()/io.db().dbDir()/io.local()/io.name();
248 
249  if (isFileOrDir(isFile, parentPath))
250  {
251  searchType = fileOperation::PARENTOBJECT;
252  return parentPath;
253  }
254  }
255 
256  // Check for approximately same time. E.g. if time = 1e-2 and
257  // directory is 0.01 (due to different time formats)
258  const auto pathFnd = times_.cfind(io.time().path());
259 
260  if (search && pathFnd.found())
261  {
262  newInstancePath = findInstancePath
263  (
264  *pathFnd(),
265  instant(io.instance())
266  );
267 
268  if (newInstancePath.size() && newInstancePath != io.instance())
269  {
270  // 1. Try processors equivalent
272  (
273  lookupProcessorsPath(io.objectPath())
274  );
275  forAll(pDirs(), i)
276  {
277  const fileName& pDir = pDirs()[i].first();
278 
279  fileName fName
280  (
281  processorsPath(io, newInstancePath, pDir)
282  /io.name()
283  );
284  if (isFileOrDir(isFile, fName))
285  {
286  switch (pDirs()[i].second().first())
287  {
288  case fileOperation::PROCUNCOLLATED:
289  {
290  searchType =
291  fileOperation::PROCUNCOLLATEDINSTANCE;
292  }
293  break;
294  case fileOperation::PROCBASEOBJECT:
295  {
296  searchType = fileOperation::PROCBASEINSTANCE;
297  }
298  break;
299  case fileOperation::PROCOBJECT:
300  {
301  searchType = fileOperation::PROCINSTANCE;
302  }
303  break;
304  default:
305  break;
306  }
307  procsDir = pDir;
308  return fName;
309  }
310  }
311 
312 
313  // 2. Check local
314  fileName fName
315  (
316  io.rootPath()/io.caseName()
317  /newInstancePath/io.db().dbDir()/io.local()/io.name()
318  );
319  if (isFileOrDir(isFile, fName))
320  {
321  searchType = fileOperation::FINDINSTANCE;
322  return fName;
323  }
324  }
325  }
326 
327  searchType = fileOperation::NOTFOUND;
328  return fileName::null;
329  }
330 }
331 
332 
335 (
336  const IOobject& io,
337  const pathType& searchType,
338  const word& procDir,
339  const word& instancePath
340 ) const
341 {
342  // Replacement for IOobject::objectPath()
343 
344  switch (searchType)
345  {
346  case fileOperation::ABSOLUTE:
347  {
348  return io.instance()/io.name();
349  }
350  break;
351 
352  case fileOperation::OBJECT:
353  {
354  return io.path()/io.name();
355  }
356  break;
357 
358  case fileOperation::WRITEOBJECT:
359  {
360  return objectPath(io, io.headerClassName());
361  }
362  break;
363 
364  case fileOperation::PROCUNCOLLATED:
365  {
366  // Uncollated type, e.g. processor1
367  const word procName
368  (
369  "processor" + Foam::name(Pstream::myProcNo(Pstream::worldComm))
370  );
371  return
372  processorsPath
373  (
374  io,
375  io.instance(),
376  (
377  Pstream::parRun()
378  ? procName
379  : procDir
380  )
381  )
382  /io.name();
383  }
384  break;
385 
386  case fileOperation::PROCBASEOBJECT:
387  {
388  // Collated, e.g. processors4
389  return
390  processorsPath(io, io.instance(), procDir)
391  /io.name();
392  }
393  break;
394 
395  case fileOperation::PROCOBJECT:
396  {
397  // Processors directory locally provided by the fileHandler itself
398  return
399  processorsPath(io, io.instance(), processorsDir(io))
400  /io.name();
401  }
402  break;
403 
404  case fileOperation::PARENTOBJECT:
405  {
406  return
407  io.rootPath()/io.time().globalCaseName()
408  /io.instance()/io.db().dbDir()/io.local()/io.name();
409  }
410  break;
411 
412  case fileOperation::FINDINSTANCE:
413  {
414  return
415  io.rootPath()/io.caseName()
416  /instancePath/io.db().dbDir()/io.local()/io.name();
417  }
418  break;
419 
420  case fileOperation::PROCUNCOLLATEDINSTANCE:
421  {
422  // Uncollated type, e.g. processor1
423  const word procName
424  (
425  "processor"
426  +Foam::name(Pstream::myProcNo(Pstream::worldComm))
427  );
428  return
429  processorsPath
430  (
431  io,
432  instancePath,
433  (
434  Pstream::parRun()
435  ? procName
436  : procDir
437  )
438  )
439  /io.name();
440  }
441  break;
442 
443  case fileOperation::PROCBASEINSTANCE:
444  {
445  // Collated, e.g. processors4
446  return
447  processorsPath(io, instancePath, procDir)
448  /io.name();
449  }
450  break;
451 
452  case fileOperation::PROCINSTANCE:
453  {
454  // Processors directory locally provided by the fileHandler itself
455  return
456  processorsPath(io, instancePath, processorsDir(io))
457  /io.name();
458  }
459  break;
460 
461  case fileOperation::NOTFOUND:
462  {
463  return fileName::null;
464  }
465  break;
466 
467  default:
468  {
470  return fileName::null;
471  }
472  }
473 }
474 
475 
477 (
478  const fileNameList& filePaths
479 )
480 {
481  const fileName& object0 = filePaths[0];
482 
483  for (label i = 1; i < filePaths.size(); i++)
484  {
485  if (filePaths[i] != object0)
486  {
487  return false;
488  }
489  }
490  return true;
491 }
492 
493 
495 (
496  const fileName& filePath,
497  const IOstream::compressionType cmp,
498  const labelUList& procs,
499  PstreamBuffers& pBufs
500 )
501 {
502  if (cmp == IOstream::compressionType::COMPRESSED)
503  {
504  if (debug)
505  {
506  Pout<< "masterUncollatedFileOperation::readAndSend :"
507  << " Opening compressed " << filePath << endl;
508  }
509 
510  IFstream is(filePath, IOstream::streamFormat::BINARY);
511 
512  if (!is.good())
513  {
514  FatalIOErrorInFunction(filePath) << "Cannot open file " << filePath
515  << exit(FatalIOError);
516  }
517 
518  std::ostringstream stringStr;
519  stringStr << is.stdStream().rdbuf();
520  string buf(stringStr.str());
521 
522  forAll(procs, i)
523  {
524  UOPstream os(procs[i], pBufs);
525  os.write(&buf[0], buf.size());
526  }
527  }
528  else
529  {
530  off_t count(Foam::fileSize(filePath));
531  IFstream is(filePath, IOstream::streamFormat::BINARY);
532 
533  if (!is.good())
534  {
535  FatalIOErrorInFunction(filePath) << "Cannot open file " << filePath
536  << exit(FatalIOError);
537  }
538 
539 
540  if (debug)
541  {
542  Pout<< "masterUncollatedFileOperation::readStream :"
543  << " From " << filePath << " reading " << label(count)
544  << " bytes" << endl;
545  }
546  List<char> buf(static_cast<label>(count));
547  is.stdStream().read(buf.begin(), count);
548 
549  forAll(procs, i)
550  {
551  UOPstream os(procs[i], pBufs);
552  os.write(buf.begin(), count);
553  }
554  }
555 }
556 
557 
559 (
560  const fileName& fName,
561  const labelUList& procs,
562  PstreamBuffers& pBufs
563 )
564 {
565  if (Foam::exists(fName+".gz", false))
566  {
567  readAndSend
568  (
569  fName,
570  IOstream::compressionType::COMPRESSED,
571  procs,
572  pBufs
573  );
574  }
575  else
576  {
577  readAndSend
578  (
579  fName,
580  IOstream::compressionType::UNCOMPRESSED,
581  procs,
582  pBufs
583  );
584  }
585 }
586 
587 
590 (
591  IOobject& io,
592  const label comm,
593  const bool uniform, // on comms master only
594  const fileNameList& filePaths, // on comms master only
595  const boolList& procValid // on comms master only
596 )
597 {
598  autoPtr<ISstream> isPtr;
599 
600  // const bool uniform = uniformFile(filePaths);
601 
602  PstreamBuffers pBufs
603  (
604  Pstream::commsTypes::nonBlocking,
605  Pstream::msgType(),
606  comm
607  );
608 
609  if (Pstream::master(comm))
610  {
611  if (uniform)
612  {
613  if (procValid[0])
614  {
615  if (filePaths[0].empty())
616  {
617  FatalIOErrorInFunction(filePaths[0])
618  << "cannot find file " << io.objectPath()
619  << exit(FatalIOError);
620  }
621 
622  DynamicList<label> validProcs(Pstream::nProcs(comm));
623  for
624  (
625  label proci = 0;
626  proci < Pstream::nProcs(comm);
627  proci++
628  )
629  {
630  if (procValid[proci])
631  {
632  validProcs.append(proci);
633  }
634  }
635 
636  // Read on master and send to all processors (including
637  // master for simplicity)
638  if (debug)
639  {
640  Pout<< "masterUncollatedFileOperation::readStream :"
641  << " For uniform file " << filePaths[0]
642  << " sending to " << validProcs
643  << " in comm:" << comm << endl;
644  }
645  readAndSend(filePaths[0], validProcs, pBufs);
646  }
647  }
648  else
649  {
650  if (procValid[0])
651  {
652  if (filePaths[0].empty())
653  {
654  FatalIOErrorInFunction(filePaths[0])
655  << "cannot find file " << io.objectPath()
656  << exit(FatalIOError);
657  }
658 
659  autoPtr<IFstream> ifsPtr(new IFstream(filePaths[0]));
660 
661  // Read header
662  if (!io.readHeader(ifsPtr()))
663  {
664  FatalIOErrorInFunction(ifsPtr())
665  << "problem while reading header for object "
666  << io.name() << exit(FatalIOError);
667  }
668 
669  // Open master (steal from ifsPtr)
670  isPtr.reset(ifsPtr.ptr());
671  }
672 
673  // Read slave files
674  for
675  (
676  label proci = 1;
677  proci < Pstream::nProcs(comm);
678  proci++
679  )
680  {
681  if (debug)
682  {
683  Pout<< "masterUncollatedFileOperation::readStream :"
684  << " For processor " << proci
685  << " opening " << filePaths[proci] << endl;
686  }
687 
688  const fileName& fPath = filePaths[proci];
689 
690  if (procValid[proci] && !fPath.empty())
691  {
692  // Note: handle compression ourselves since size cannot
693  // be determined without actually uncompressing
694  readAndSend(fPath, labelList(1, proci), pBufs);
695  }
696  }
697  }
698  }
699 
700  labelList recvSizes;
701  pBufs.finishedSends(recvSizes);
702 
703  // isPtr will be valid on master and will be the unbuffered
704  // IFstream. Else the information is in the PstreamBuffers (and
705  // the special case of a uniform file)
706 
707  if (procValid[Pstream::myProcNo(comm)])
708  {
709  // This processor needs to return something
710 
711  if (!isPtr.valid())
712  {
713  UIPstream is(Pstream::masterNo(), pBufs);
714 
715  List<char> buf(recvSizes[Pstream::masterNo()]);
716  if (recvSizes[Pstream::masterNo()] > 0)
717  {
718  is.read(buf.begin(), recvSizes[Pstream::masterNo()]);
719  }
720 
721  if (debug)
722  {
723  Pout<< "masterUncollatedFileOperation::readStream :"
724  << " Done reading " << buf.size() << " bytes" << endl;
725  }
726  const fileName& fName = filePaths[Pstream::myProcNo(comm)];
727  isPtr.reset
728  (
729  new IListStream
730  (
731  std::move(buf),
732  IOstream::BINARY,
733  IOstream::currentVersion,
734  fName
735  )
736  );
737 
738  if (!io.readHeader(isPtr()))
739  {
740  FatalIOErrorInFunction(isPtr())
741  << "problem while reading header for object "
742  << io.name() << exit(FatalIOError);
743  }
744  }
745  }
746  else
747  {
748  isPtr.reset(new dummyISstream());
749  }
750 
751  return isPtr;
752 }
753 
754 
755 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
756 
759 (
760  bool verbose
761 )
762 :
764  (
765  UPstream::allocateCommunicator
766  (
767  UPstream::worldComm,
768  subRanks(Pstream::nProcs())
769  )
770  ),
771  myComm_(comm_)
772 {
773  verbose = (verbose && Foam::infoDetailLevel > 0);
774 
775  if (verbose)
776  {
777  Info
778  << "I/O : " << typeName
779  << " (maxMasterFileBufferSize " << maxMasterFileBufferSize << ')'
780  << endl;
781  }
782 
783  if (regIOobject::fileModificationChecking == regIOobject::timeStampMaster)
784  {
785  if (verbose)
786  {
788  << "Resetting fileModificationChecking to timeStamp" << endl;
789  }
790  regIOobject::fileModificationChecking = regIOobject::timeStamp;
791  }
792  else if
793  (
794  regIOobject::fileModificationChecking
795  == regIOobject::inotifyMaster
796  )
797  {
798  if (verbose)
799  {
801  << "Resetting fileModificationChecking to inotify"
802  << endl;
803  }
804  regIOobject::fileModificationChecking = regIOobject::inotify;
805  }
806 }
807 
808 
811 (
812  const label comm,
813  bool verbose
814 )
815 :
816  fileOperation(comm),
817  myComm_(-1)
818 {
819  verbose = (verbose && Foam::infoDetailLevel > 0);
820 
821  if (verbose)
822  {
823  Info
824  << "I/O : " << typeName
825  << " (maxMasterFileBufferSize " << maxMasterFileBufferSize << ')'
826  << endl;
827  }
828 
829  if (regIOobject::fileModificationChecking == regIOobject::timeStampMaster)
830  {
831  if (verbose)
832  {
834  << "Resetting fileModificationChecking to timeStamp" << endl;
835  }
836  regIOobject::fileModificationChecking = regIOobject::timeStamp;
837  }
838  else if
839  (
840  regIOobject::fileModificationChecking
841  == regIOobject::inotifyMaster
842  )
843  {
844  if (verbose)
845  {
847  << "Resetting fileModificationChecking to inotify"
848  << endl;
849  }
850  regIOobject::fileModificationChecking = regIOobject::inotify;
851  }
852 }
853 
854 
857 :
858  unthreadedInitialise(argc, argv)
859 {
860  // Filter out any of my arguments
861  const string s("-ioRanks");
862 
863  int index = -1;
864  for (int i=1; i<argc-1; i++)
865  {
866  if (argv[i] == s)
867  {
868  index = i;
869  setEnv("FOAM_IORANKS", argv[i+1], true);
870  break;
871  }
872  }
873 
874  if (index != -1)
875  {
876  for (int i=index+2; i<argc; i++)
877  {
878  argv[i-2] = argv[i];
879  }
880  argc -= 2;
881  }
882 }
883 
884 
885 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
886 
889 {
890  if (myComm_ != -1 && myComm_ != UPstream::worldComm)
891  {
893  }
894 }
895 
896 
897 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
898 
900 (
901  const fileName& dir,
902  mode_t mode
903 ) const
904 {
905  return masterOp<mode_t, mkDirOp>
906  (
907  dir,
908  mkDirOp(mode),
910  comm_
911  );
912 }
913 
914 
916 (
917  const fileName& fName,
918  mode_t mode
919 ) const
920 {
921  return masterOp<mode_t, chModOp>
922  (
923  fName,
924  chModOp(mode),
926  comm_
927  );
928 }
929 
930 
932 (
933  const fileName& fName,
934  const bool followLink
935 ) const
936 {
937  return masterOp<mode_t, modeOp>
938  (
939  fName,
940  modeOp(followLink),
942  comm_
943  );
944 }
945 
946 
948 (
949  const fileName& fName,
950  const bool followLink
951 ) const
952 {
953  return fileName::Type
954  (
955  masterOp<label, typeOp>
956  (
957  fName,
958  typeOp(followLink),
960  comm_
961  )
962  );
963 }
964 
965 
967 (
968  const fileName& fName,
969  const bool checkGzip,
970  const bool followLink
971 ) const
972 {
973  return masterOp<bool, existsOp>
974  (
975  fName,
976  existsOp(checkGzip, followLink),
978  comm_
979  );
980 }
981 
982 
984 (
985  const fileName& fName,
986  const bool followLink
987 ) const
988 {
989  return masterOp<bool, isDirOp>
990  (
991  fName,
992  isDirOp(followLink),
994  comm_
995  );
996 }
997 
998 
1001  const fileName& fName,
1002  const bool checkGzip,
1003  const bool followLink
1004 ) const
1005 {
1006  return masterOp<bool, isFileOp>
1007  (
1008  fName,
1009  isFileOp(checkGzip, followLink),
1010  Pstream::msgType(),
1011  comm_
1012  );
1013 }
1014 
1015 
1018  const fileName& fName,
1019  const bool followLink
1020 ) const
1021 {
1022  return masterOp<off_t, fileSizeOp>
1023  (
1024  fName,
1025  fileSizeOp(followLink),
1026  Pstream::msgType(),
1027  comm_
1028  );
1029 }
1030 
1031 
1034  const fileName& fName,
1035  const bool followLink
1036 ) const
1037 {
1038  return masterOp<time_t, lastModifiedOp>
1039  (
1040  fName,
1041  lastModifiedOp(followLink),
1042  Pstream::msgType(),
1043  comm_
1044  );
1045 }
1046 
1047 
1050  const fileName& fName,
1051  const bool followLink
1052 ) const
1053 {
1054  return masterOp<double, lastModifiedHROp>
1055  (
1056  fName,
1057  lastModifiedHROp(followLink),
1058  Pstream::msgType(),
1059  comm_
1060  );
1061 }
1062 
1063 
1066  const fileName& fName,
1067  const std::string& ext
1068 ) const
1069 {
1070  return masterOp<bool, mvBakOp>
1071  (
1072  fName,
1073  mvBakOp(ext),
1074  Pstream::msgType(),
1075  comm_
1076  );
1077 }
1078 
1079 
1082  const fileName& fName
1083 ) const
1084 {
1085  return masterOp<bool, rmOp>
1086  (
1087  fName,
1088  rmOp(),
1089  Pstream::msgType(),
1090  comm_
1091  );
1092 }
1093 
1094 
1097  const fileName& dir,
1098  const bool silent
1099 ) const
1100 {
1101  return masterOp<bool, rmDirOp>
1102  (
1103  dir,
1104  rmDirOp(silent),
1105  Pstream::msgType(),
1106  comm_
1107  );
1108 }
1109 
1110 
1113  const fileName& dir,
1114  const fileName::Type type,
1115  const bool filtergz,
1116  const bool followLink
1117 ) const
1118 {
1119  return masterOp<fileNameList, readDirOp>
1120  (
1121  dir,
1122  readDirOp(type, filtergz, followLink),
1123  Pstream::msgType(),
1124  comm_
1125  );
1126 }
1127 
1128 
1131  const fileName& src,
1132  const fileName& dst,
1133  const bool followLink
1134 ) const
1135 {
1136  return masterOp<bool, cpOp>
1137  (
1138  src,
1139  dst,
1140  cpOp(followLink),
1141  Pstream::msgType(),
1142  comm_
1143  );
1144 }
1145 
1146 
1149  const fileName& src,
1150  const fileName& dst
1151 ) const
1152 {
1153  return masterOp<bool, lnOp>
1154  (
1155  src,
1156  dst,
1157  lnOp(),
1158  Pstream::msgType(),
1159  comm_
1160  );
1161 }
1162 
1163 
1166  const fileName& src,
1167  const fileName& dst,
1168  const bool followLink
1169 ) const
1170 {
1171  return masterOp<bool, mvOp>
1172  (
1173  src,
1174  dst,
1175  mvOp(followLink),
1176  Pstream::msgType(),
1177  comm_
1178  );
1179 }
1180 
1181 
1184  const bool checkGlobal,
1185  const IOobject& io,
1186  const word& typeName,
1187  const bool search
1188 ) const
1189 {
1190  if (debug)
1191  {
1192  Pout<< "masterUncollatedFileOperation::filePath :"
1193  << " objectPath:" << io.objectPath()
1194  << " checkGlobal:" << checkGlobal << endl;
1195  }
1196 
1197  // Now that we have an IOobject path use it to detect & cache
1198  // processor directory naming
1199  (void)lookupProcessorsPath(io.objectPath());
1200 
1201  // Trigger caching of times
1202  (void)findTimes(io.time().path(), io.time().constant());
1203 
1204 
1205  // Determine master filePath and scatter
1206 
1207  fileName objPath;
1208  pathType searchType = NOTFOUND;
1209  word procsDir;
1210  word newInstancePath;
1211 
1212  if (Pstream::master(comm_))
1213  {
1214  // All masters search locally. Note that global objects might
1215  // fail (except on master). This gets handled later on (in PARENTOBJECT)
1216  objPath =
1217  filePathInfo
1218  (
1219  checkGlobal,
1220  true,
1221  io,
1222  search,
1223  searchType,
1224  procsDir,
1225  newInstancePath
1226  );
1227 
1228  if (debug)
1229  {
1230  Pout<< "masterUncollatedFileOperation::filePath :"
1231  << " master objPath:" << objPath
1232  << " searchType:" << fileOperation::pathTypeNames_[searchType]
1233  << " procsDir:" << procsDir << " instance:" << newInstancePath
1234  << endl;
1235  }
1236  }
1237 
1238  // Scatter the information about where the master found the object
1239  // Note: use the worldComm to make sure all processors decide
1240  // the same type. Only procsDir is allowed to differ; searchType
1241  // and instance have to be same
1242  {
1243  label masterType(searchType);
1244  Pstream::scatter(masterType);
1245  searchType = pathType(masterType);
1246  }
1247  Pstream::scatter(newInstancePath);
1248 
1249  if
1250  (
1251  checkGlobal
1252  || searchType == fileOperation::PARENTOBJECT
1253  || searchType == fileOperation::PROCBASEOBJECT
1254  || searchType == fileOperation::PROCBASEINSTANCE
1255  || io.local() == "uniform"
1256  )
1257  {
1258  // Distribute master path. This makes sure it is seen as uniform
1259  // and only gets read from the master.
1260  Pstream::scatter(objPath);
1261  Pstream::scatter(procsDir);
1262  }
1263  else
1264  {
1265  Pstream::scatter(procsDir, Pstream::msgType(), comm_);
1266 
1267  // Use the master type to determine if additional information is
1268  // needed to construct the local equivalent
1269  switch (searchType)
1270  {
1274  {
1275  // Already handled above
1276  }
1277  break;
1278 
1286  {
1287  // Construct equivalent local path
1288  objPath = localObjectPath
1289  (
1290  io,
1291  searchType,
1292  procsDir,
1293  newInstancePath
1294  );
1295  }
1296  break;
1297 
1298  case fileOperation::OBJECT:
1300  {
1301  // Retest all processors separately since some processors might
1302  // have the file and some not (e.g. lagrangian data)
1303 
1304  objPath = masterOp<fileName, fileOrNullOp>
1305  (
1306  io.objectPath(),
1307  fileOrNullOp(true),
1308  Pstream::msgType(),
1309  comm_
1310  );
1311  }
1312  break;
1313  }
1314  }
1315 
1316  if (debug)
1317  {
1318  Pout<< "masterUncollatedFileOperation::filePath :"
1319  << " Returning from file searching:" << endl
1320  << " objectPath:" << io.objectPath() << endl
1321  << " filePath :" << objPath << endl << endl;
1322  }
1323  return objPath;
1324 }
1325 
1326 
1329  const bool checkGlobal,
1330  const IOobject& io,
1331  const bool search
1332 ) const
1333 {
1334  if (debug)
1335  {
1336  Pout<< "masterUncollatedFileOperation::dirPath :"
1337  << " objectPath:" << io.objectPath()
1338  << " checkGlobal:" << checkGlobal << endl;
1339  }
1340 
1341  // Now that we have an IOobject path use it to detect & cache
1342  // processor directory naming
1343  (void)lookupProcessorsPath(io.objectPath());
1344 
1345  // Determine master dirPath and scatter
1346 
1347  fileName objPath;
1348  pathType searchType = NOTFOUND;
1349  word procsDir;
1350  word newInstancePath;
1351 
1352  if (Pstream::master(comm_))
1353  {
1354  objPath = filePathInfo
1355  (
1356  checkGlobal,
1357  false,
1358  io,
1359  search,
1360  searchType,
1361  procsDir,
1362  newInstancePath
1363  );
1364  }
1365 
1366  {
1367  label masterType(searchType);
1368  Pstream::scatter(masterType); //, Pstream::msgType(), comm_);
1369  searchType = pathType(masterType);
1370  }
1371  Pstream::scatter(newInstancePath); //, Pstream::msgType(), comm_);
1372 
1373  if
1374  (
1375  checkGlobal
1376  || searchType == fileOperation::PARENTOBJECT
1377  || searchType == fileOperation::PROCBASEOBJECT
1378  || searchType == fileOperation::PROCBASEINSTANCE
1379  || io.local() == "uniform"
1380  )
1381  {
1382  // Distribute master path. This makes sure it is seen as uniform
1383  // and only gets read from the master.
1384  Pstream::scatter(objPath);
1385  Pstream::scatter(procsDir);
1386  }
1387  else
1388  {
1389  Pstream::scatter(procsDir, Pstream::msgType(), comm_);
1390 
1391  // Use the master type to determine if additional information is
1392  // needed to construct the local equivalent
1393  switch (searchType)
1394  {
1398  {
1399  // Already handled above
1400  }
1401  break;
1402 
1410  {
1411  // Construct equivalent local path
1412  objPath = localObjectPath
1413  (
1414  io,
1415  searchType,
1416  procsDir,
1417  newInstancePath
1418  );
1419  }
1420  break;
1421 
1422  case fileOperation::OBJECT:
1424  {
1425  // Retest all processors separately since some processors might
1426  // have the file and some not (e.g. lagrangian data)
1427  objPath = masterOp<fileName, fileOrNullOp>
1428  (
1429  io.objectPath(),
1430  fileOrNullOp(false),
1431  Pstream::msgType(),
1432  comm_
1433  );
1434  }
1435  break;
1436  }
1437  }
1438 
1439  if (debug)
1440  {
1441  Pout<< "masterUncollatedFileOperation::dirPath :"
1442  << " Returning from file searching:" << endl
1443  << " objectPath:" << io.objectPath() << endl
1444  << " filePath :" << objPath << endl << endl;
1445  }
1446  return objPath;
1447 }
1448 
1449 
1452  const dirIndexList& pDirs,
1453  IOobject& io
1454 ) const
1455 {
1456  // Cut-down version of filePathInfo that does not look for
1457  // different instance or parent directory
1458 
1459  const bool isFile = !io.name().empty();
1460 
1461  // Generate output filename for object
1462  const fileName writePath(objectPath(io, word::null));
1463 
1464  // 1. Test writing name for either directory or a (valid) file
1465  if (isFileOrDir(isFile, writePath))
1466  {
1467  return true;
1468  }
1469 
1470  // 2. Check processors/
1471  if (io.time().processorCase())
1472  {
1473  forAll(pDirs, i)
1474  {
1475  const fileName& pDir = pDirs[i].first();
1476  fileName procPath =
1477  processorsPath(io, io.instance(), pDir)
1478  /io.name();
1479  if (procPath != writePath && isFileOrDir(isFile, procPath))
1480  {
1481  return true;
1482  }
1483  }
1484  }
1485 
1486  // 3. Check local
1487  fileName localPath = io.objectPath();
1488 
1489  if (localPath != writePath && isFileOrDir(isFile, localPath))
1490  {
1491  return true;
1492  }
1493 
1494  return false;
1495 }
1496 
1497 
1501  const IOobject& startIO,
1502  const scalar startValue,
1503  const word& stopInstance
1504 ) const
1505 {
1506  if (debug)
1507  {
1508  Pout<< "masterUncollatedFileOperation::findInstance :"
1509  << " Starting searching for name:" << startIO.name()
1510  << " local:" << startIO.local()
1511  << " from instance:" << startIO.instance()
1512  << endl;
1513  }
1514 
1515 
1516  const Time& time = startIO.time();
1517 
1518  IOobject io(startIO);
1519 
1520  // Note: - if name is empty, just check the directory itself
1521  // - check both for isFile and headerOk since the latter does a
1522  // filePath so searches for the file.
1523  // - check for an object with local file scope (so no looking up in
1524  // parent directory in case of parallel)
1525 
1526 
1527  tmpNrc<dirIndexList> pDirs(lookupProcessorsPath(io.objectPath()));
1528 
1529  word foundInstance;
1530 
1531  // if (Pstream::master(comm_))
1533  {
1534  if (exists(pDirs, io))
1535  {
1536  foundInstance = io.instance();
1537  }
1538  }
1539 
1540  // Do parallel early exit to avoid calling time.times()
1541  // Pstream::scatter(foundInstance, Pstream::msgType(), comm_);
1543  if (!foundInstance.empty())
1544  {
1545  io.instance() = foundInstance;
1546  if (debug)
1547  {
1548  Pout<< "masterUncollatedFileOperation::findInstance :"
1549  << " for name:" << io.name() << " local:" << io.local()
1550  << " found starting instance:" << io.instance() << endl;
1551  }
1552  return io;
1553  }
1554 
1555 
1556  // Search back through the time directories to find the time
1557  // closest to and lower than current time
1558 
1559  instantList ts = time.times();
1560  // if (Pstream::master(comm_))
1562  {
1563  label instanceI;
1564 
1565  for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
1566  {
1567  if (ts[instanceI].value() <= startValue)
1568  {
1569  break;
1570  }
1571  }
1572 
1573  // continue searching from here
1574  for (; instanceI >= 0; --instanceI)
1575  {
1576  // Shortcut: if actual directory is the timeName we've
1577  // already tested it
1578  if (ts[instanceI].name() == time.timeName())
1579  {
1580  continue;
1581  }
1582 
1583  io.instance() = ts[instanceI].name();
1584  if (exists(pDirs, io))
1585  {
1586  foundInstance = io.instance();
1587  if (debug)
1588  {
1589  Pout<< "masterUncollatedFileOperation::findInstance :"
1590  << " for name:" << io.name() << " local:" << io.local()
1591  << " found at:" << io.instance()
1592  << endl;
1593  }
1594  break;
1595  }
1596 
1597  // Check if hit minimum instance
1598  if (ts[instanceI].name() == stopInstance)
1599  {
1600  if
1601  (
1602  startIO.readOpt() == IOobject::MUST_READ
1604  )
1605  {
1606  if (io.name().empty())
1607  {
1609  << "Cannot find directory "
1610  << io.local() << " in times " << time.timeName()
1611  << " down to " << stopInstance
1612  << exit(FatalError);
1613  }
1614  else
1615  {
1617  << "Cannot find file \"" << io.name()
1618  << "\" in directory " << io.local()
1619  << " in times " << time.timeName()
1620  << " down to " << stopInstance
1621  << exit(FatalError);
1622  }
1623  }
1624  foundInstance = io.instance();
1625  if (debug)
1626  {
1627  Pout<< "masterUncollatedFileOperation::findInstance :"
1628  << " name:" << io.name() << " local:" << io.local()
1629  << " found at stopinstance:" << io.instance() << endl;
1630  }
1631  break;
1632  }
1633  }
1634 
1635 
1636  if (foundInstance.empty())
1637  {
1638  // times() usually already includes the constant() so would
1639  // have been checked above. Re-test if
1640  // - times() is empty. Sometimes this can happen (e.g. decomposePar
1641  // with collated)
1642  // - times()[0] is not constant
1643  if (!ts.size() || ts[0].name() != time.constant())
1644  {
1645  // Note. This needs to be a hard-coded constant, rather than the
1646  // constant function of the time, because the latter points to
1647  // the case constant directory in parallel cases
1648 
1649  io.instance() = time.constant();
1650  if (exists(pDirs, io))
1651  {
1652  if (debug)
1653  {
1654  Pout<< "masterUncollatedFileOperation::findInstance :"
1655  << " name:" << io.name()
1656  << " local:" << io.local()
1657  << " found at:" << io.instance() << endl;
1658  }
1659  foundInstance = io.instance();
1660  }
1661  }
1662  }
1663 
1664  if (foundInstance.empty())
1665  {
1666  if
1667  (
1668  startIO.readOpt() == IOobject::MUST_READ
1670  )
1671  {
1673  << "Cannot find file \"" << io.name() << "\" in directory "
1674  << io.local() << " in times " << startIO.instance()
1675  << " down to " << time.constant()
1676  << exit(FatalError);
1677  }
1678  else
1679  {
1680  foundInstance = time.constant();
1681  }
1682  }
1683  }
1684 
1685  // Pstream::scatter(foundInstance, Pstream::msgType(), comm_);
1687  io.instance() = foundInstance;
1688  if (debug)
1689  {
1690  Pout<< "masterUncollatedFileOperation::findInstance :"
1691  << " name:" << io.name() << " local:" << io.local()
1692  << " returning instance:" << io.instance() << endl;
1693  }
1694  return io;
1695 }
1696 
1697 
1701  const objectRegistry& db,
1702  const fileName& instance,
1703  const fileName& local,
1704  word& newInstance
1705 ) const
1706 {
1707  if (debug)
1708  {
1709  Pout<< "masterUncollatedFileOperation::readObjects :"
1710  << " db:" << db.objectPath()
1711  << " local:" << local << " instance:" << instance << endl;
1712  }
1713 
1714  fileNameList objectNames;
1715  newInstance = word::null;
1716 
1717  // Note: readObjects uses WORLD to make sure order of objects is the
1718  // same everywhere
1719 
1720  if (Pstream::master()) // comm_))
1721  {
1722  // Avoid fileOperation::readObjects from triggering parallel ops
1723  // (through call to filePath which triggers parallel )
1724  bool oldParRun = UPstream::parRun();
1725  UPstream::parRun() = false;
1726 
1727  //- Use non-time searching version
1728  objectNames = fileOperation::readObjects
1729  (
1730  db,
1731  instance,
1732  local,
1733  newInstance
1734  );
1735 
1736  if (newInstance.empty())
1737  {
1738  // Find similar time
1739 
1740  // Copy of Time::findInstancePath. We want to avoid the
1741  // parallel call to findTimes. Alternative is to have
1742  // version of findInstancePath that takes instantList ...
1743  const instantList timeDirs
1744  (
1746  (
1747  db.time().path(),
1748  db.time().constant()
1749  )
1750  );
1751 
1752  const instant t(instance);
1753  forAllReverse(timeDirs, i)
1754  {
1755  if (t.equal(timeDirs[i].value()))
1756  {
1757  objectNames = fileOperation::readObjects
1758  (
1759  db,
1760  timeDirs[i].name(), // newly found time
1761  local,
1762  newInstance
1763  );
1764  break;
1765  }
1766  }
1767  }
1768 
1769  UPstream::parRun() = oldParRun;
1770  }
1771 
1772  Pstream::scatter(newInstance); //, Pstream::msgType(), comm_);
1773  Pstream::scatter(objectNames); //, Pstream::msgType(), comm_);
1774 
1775  if (debug)
1776  {
1777  Pout<< "masterUncollatedFileOperation::readObjects :"
1778  << " newInstance:" << newInstance
1779  << " objectNames:" << objectNames << endl;
1780  }
1781 
1782  return objectNames;
1783 }
1784 
1785 
1788  IOobject& io,
1789  const fileName& fName,
1790  const word& typeName
1791 ) const
1792 {
1793  bool ok = false;
1794 
1795  if (debug)
1796  {
1797  Pout<< "masterUncollatedFileOperation::readHeader :" << endl
1798  << " objectPath:" << io.objectPath() << endl
1799  << " fName :" << fName << endl;
1800  }
1801 
1802  // Get filePaths on world master
1804  filePaths[Pstream::myProcNo(Pstream::worldComm)] = fName;
1806  bool uniform = uniformFile(filePaths);
1808 
1809  if (uniform)
1810  {
1812  {
1813  if (!fName.empty())
1814  {
1815  IFstream is(fName);
1816 
1817  if (is.good())
1818  {
1819  ok = io.readHeader(is);
1820  if (io.headerClassName() == decomposedBlockData::typeName)
1821  {
1822  // Read the header inside the container (master data)
1824  }
1825  }
1826  }
1827  }
1830  (
1831  io.headerClassName(),
1832  Pstream::msgType(),
1834  );
1836  }
1837  else
1838  {
1840  {
1841  // Re-gather file paths on local master
1842  filePaths.setSize(Pstream::nProcs(comm_));
1843  filePaths[Pstream::myProcNo(comm_)] = fName;
1844  Pstream::gatherList(filePaths, Pstream::msgType(), comm_);
1845  }
1846 
1847  boolList result(Pstream::nProcs(comm_), false);
1848  wordList headerClassName(Pstream::nProcs(comm_));
1849  stringList note(Pstream::nProcs(comm_));
1850  if (Pstream::master(comm_))
1851  {
1852  forAll(filePaths, proci)
1853  {
1854  if (!filePaths[proci].empty())
1855  {
1856  if (proci > 0 && filePaths[proci] == filePaths[proci-1])
1857  {
1858  result[proci] = result[proci-1];
1859  headerClassName[proci] = headerClassName[proci-1];
1860  note[proci] = note[proci-1];
1861  }
1862  else
1863  {
1864  IFstream is(filePaths[proci]);
1865 
1866  if (is.good())
1867  {
1868  result[proci] = io.readHeader(is);
1869  if
1870  (
1871  io.headerClassName()
1872  == decomposedBlockData::typeName
1873  )
1874  {
1875  // Read the header inside the container (master
1876  // data)
1877  result[proci] = decomposedBlockData::
1879  (
1880  io,
1881  is
1882  );
1883  }
1884  headerClassName[proci] = io.headerClassName();
1885  note[proci] = io.note();
1886  }
1887  }
1888  }
1889  }
1890  }
1891  ok = scatterList(result, Pstream::msgType(), comm_);
1892  io.headerClassName() = scatterList
1893  (
1894  headerClassName,
1895  Pstream::msgType(),
1896  comm_
1897  );
1898  io.note() = scatterList(note, Pstream::msgType(), comm_);
1899  }
1900 
1901  if (debug)
1902  {
1903  Pout<< "masterUncollatedFileOperation::readHeader :" << " ok:" << ok
1904  << " class:" << io.headerClassName() << endl;
1905  }
1906  return ok;
1907 }
1908 
1909 
1913  regIOobject& io,
1914  const fileName& fName,
1915  const word& typeName,
1916  const bool valid
1917 ) const
1918 {
1919  if (debug)
1920  {
1921  Pout<< "masterUncollatedFileOperation::readStream :"
1922  << " object : " << io.name()
1923  << " global : " << io.global()
1924  << " fName : " << fName << " valid:" << valid << endl;
1925  }
1926 
1927 
1928  autoPtr<ISstream> isPtr;
1929  bool isCollated = false;
1930  IOobject headerIO(io);
1931 
1932  // Detect collated format. This could be done on the local communicator
1933  // but we do it on the master node only for now.
1934  if (UPstream::master()) // comm_))
1935  {
1936  if (!fName.empty())
1937  {
1938  // This can happen in lagrangian field reading some processors
1939  // have no file to read from. This will only happen when using
1940  // normal writing since then the fName for the valid processors is
1941  // processorDDD/<instance>/.. . In case of collocated writing
1942  // the fName is already rewritten to processors/.
1943 
1944  isPtr.reset(new IFstream(fName));
1945 
1946  if (isPtr().good())
1947  {
1948  // Read header data (on copy)
1949  headerIO.readHeader(isPtr());
1950 
1951  if (headerIO.headerClassName() == decomposedBlockData::typeName)
1952  {
1953  isCollated = true;
1954  }
1955  else if (!Pstream::parRun())
1956  {
1957  // Short circuit: non-collated format. No parallel bits.
1958  // Copy header and return.
1959  if (debug)
1960  {
1961  Pout<< "masterUncollatedFileOperation::readStream :"
1962  << " For object : " << io.name()
1963  << " doing straight IFstream input from "
1964  << fName << endl;
1965  }
1966  io = headerIO;
1967  return isPtr;
1968  }
1969  }
1970 
1971  if (!isCollated)
1972  {
1973  // Close file. Reopened below.
1974  isPtr.clear();
1975  }
1976  }
1977  }
1978 
1979  Pstream::scatter(isCollated); //, Pstream::msgType(), comm_);
1980 
1981  if (isCollated)
1982  {
1983  if (debug)
1984  {
1985  Pout<< "masterUncollatedFileOperation::readStream :"
1986  << " For object : " << io.name()
1987  << " starting collating input from " << fName << endl;
1988  }
1989 
1990 
1991  // Analyse the file path (on (co)master) to see the processors type
1992  fileName path, procDir, local;
1993  label groupStart, groupSize, nProcs;
1994  splitProcessorPath
1995  (
1996  fName,
1997  path,
1998  procDir,
1999  local,
2000  groupStart,
2001  groupSize,
2002  nProcs
2003  );
2004 
2005 
2006  List<char> data;
2007  if (!Pstream::parRun())
2008  {
2009  // Analyse the objectpath to find out the processor we're trying
2010  // to access
2011  label proci = detectProcessorPath(io.objectPath());
2012 
2013  if (proci == -1)
2014  {
2015  FatalIOErrorInFunction(isPtr())
2016  << "Could not detect processor number"
2017  << " from objectPath:" << io.objectPath()
2018  << exit(FatalIOError);
2019  }
2020 
2021  // Analyse the fileName for any processor subset. Note: this
2022  // should really be part of filePath() which should return
2023  // both file and index in file.
2024  if (groupStart != -1 && groupSize > 0)
2025  {
2026  proci = proci-groupStart;
2027  }
2028 
2029  if (debug)
2030  {
2031  Pout<< "masterUncollatedFileOperation::readStream :"
2032  << " For object : " << io.name()
2033  << " starting input from block " << proci
2034  << " of " << isPtr().name() << endl;
2035  }
2036 
2037  return decomposedBlockData::readBlock(proci, isPtr(), io);
2038  }
2039  else
2040  {
2041  // Scatter master header info
2042  string versionString;
2043  string formatString;
2044  if (isPtr.valid())
2045  {
2046  versionString = isPtr().version().str();
2047  OStringStream os;
2048  os << isPtr().format();
2049  formatString = (os.str());
2050  }
2051 
2052  Pstream::scatter(versionString); //, Pstream::msgType(), comm);
2053  Pstream::scatter(formatString); //, Pstream::msgType(), comm);
2054 
2055  // Get size of file
2056  off_t sz = Foam::fileSize(fName);
2057  bool bigSize = sz > off_t(maxMasterFileBufferSize);
2058  Pstream::scatter(bigSize);
2059 
2060  // Are we reading from single-master file ('processors256') or
2061  // from multi-master files ('processors256_0-9')
2062  label readComm = -1;
2063  if (groupStart != -1 && groupSize > 0)
2064  {
2065  readComm = comm_;
2066  if (UPstream::master(comm_) && !isPtr.valid() && !fName.empty())
2067  {
2068  // In multi-master mode also open the file on the other
2069  // masters
2070  isPtr.reset(new IFstream(fName));
2071 
2072  if (isPtr().good())
2073  {
2074  // Read header data (on copy)
2075  IOobject headerIO(io);
2076  headerIO.readHeader(isPtr());
2077  }
2078  }
2079  }
2080  else
2081  {
2082  // Single master so read on world
2083  readComm = Pstream::worldComm;
2084  }
2085 
2086  // Read my data
2088  (
2089  readComm,
2090  fName,
2091  isPtr,
2092  io,
2093  (
2094  bigSize
2097  )
2098  );
2099  }
2100  }
2101  else
2102  {
2103  if (debug)
2104  {
2105  Pout<< "masterUncollatedFileOperation::readStream :"
2106  << " For object : " << io.name()
2107  << " starting separated input from " << fName << endl;
2108  }
2109 
2110  if (io.global())
2111  {
2112  // Use worldComm. Note: should not really need to gather filePaths
2113  // since we enforce sending from master anyway ...
2114  fileNameList filePaths(Pstream::nProcs());
2115  filePaths[Pstream::myProcNo()] = fName;
2116  Pstream::gatherList(filePaths);
2117  boolList procValid(Pstream::nProcs());
2118  procValid[Pstream::myProcNo()] = valid;
2119  Pstream::gatherList(procValid);
2120 
2121  return read(io, Pstream::worldComm, true, filePaths, procValid);
2122  }
2123  else
2124  {
2125  // Use local communicator
2126  fileNameList filePaths(Pstream::nProcs(comm_));
2127  filePaths[Pstream::myProcNo(comm_)] = fName;
2128  Pstream::gatherList(filePaths, Pstream::msgType(), comm_);
2129  boolList procValid(Pstream::nProcs(comm_));
2130  procValid[Pstream::myProcNo(comm_)] = valid;
2131  Pstream::gatherList(procValid, Pstream::msgType(), comm_);
2132 
2133  // Uniform in local comm
2134  bool uniform = uniformFile(filePaths);
2135 
2136  return read(io, comm_, uniform, filePaths, procValid);
2137  }
2138  }
2139 }
2140 
2141 
2144  regIOobject& io,
2145  const bool masterOnly,
2147  const word& typeName
2148 ) const
2149 {
2150  bool ok = true;
2151 
2152  if (io.globalObject())
2153  {
2154  if (debug)
2155  {
2156  Pout<< "masterUncollatedFileOperation::read :"
2157  << " Reading global object " << io.name() << endl;
2158  }
2159 
2160  bool ok = false;
2161  if (Pstream::master()) // comm_))
2162  {
2163  // Do master-only reading always.
2164  bool oldParRun = UPstream::parRun();
2165  UPstream::parRun() = false;
2166 
2167  ok = io.readData(io.readStream(typeName));
2168  io.close();
2169 
2170  UPstream::parRun() = oldParRun;
2171  }
2172 
2173  Pstream::scatter(ok); //, Pstream::msgType(), comm_);
2174  Pstream::scatter(io.headerClassName()); //, Pstream::msgType(), comm_);
2175  Pstream::scatter(io.note()); //, Pstream::msgType(), comm_);
2176 
2177 
2178  // scatter operation for regIOobjects
2179 
2180  // Get my communication order
2181  // const List<Pstream::commsStruct>& comms =
2182  //(
2183  // (Pstream::nProcs(comm_) < Pstream::nProcsSimpleSum)
2184  // ? Pstream::linearCommunication(comm_)
2185  // : Pstream::treeCommunication(comm_)
2186  //);
2187  // const Pstream::commsStruct& myComm = comms[Pstream::myProcNo(comm_)];
2188  const List<Pstream::commsStruct>& comms =
2189  (
2193  );
2194  const Pstream::commsStruct& myComm =
2196 
2197  // Receive from up
2198  if (myComm.above() != -1)
2199  {
2200  IPstream fromAbove
2201  (
2203  myComm.above(),
2204  0,
2205  Pstream::msgType(),
2206  Pstream::worldComm, // comm_,
2207  format
2208  );
2209  ok = io.readData(fromAbove);
2210  }
2211 
2212  // Send to my downstairs neighbours
2213  forAll(myComm.below(), belowI)
2214  {
2215  OPstream toBelow
2216  (
2218  myComm.below()[belowI],
2219  0,
2220  Pstream::msgType(),
2221  Pstream::worldComm, // comm_,
2222  format
2223  );
2224  bool okWrite = io.writeData(toBelow);
2225  ok = ok && okWrite;
2226  }
2227  }
2228  else
2229  {
2230  if (debug)
2231  {
2232  Pout<< "masterUncollatedFileOperation::read :"
2233  << " Reading local object " << io.name() << endl;
2234  }
2235 
2236  ok = io.readData(io.readStream(typeName));
2237  io.close();
2238  }
2239 
2240  return ok;
2241 }
2242 
2243 
2246  const regIOobject& io,
2250  const bool valid
2251 ) const
2252 {
2253  fileName pathName(io.objectPath());
2254 
2255  if (debug)
2256  {
2257  Pout<< "masterUncollatedFileOperation::writeObject :"
2258  << " io:" << pathName << " valid:" << valid << endl;
2259  }
2260 
2261  // Make sure to pick up any new times
2262  setTime(io.time());
2263 
2264  autoPtr<Ostream> osPtr
2265  (
2266  NewOFstream
2267  (
2268  pathName,
2269  fmt,
2270  ver,
2271  cmp,
2272  valid
2273  )
2274  );
2275  Ostream& os = osPtr();
2276 
2277  // If any of these fail, return (leave error handling to Ostream class)
2278  if (!os.good())
2279  {
2280  return false;
2281  }
2282 
2283  if (!io.writeHeader(os))
2284  {
2285  return false;
2286  }
2287 
2288  // Write the data to the Ostream
2289  if (!io.writeData(os))
2290  {
2291  return false;
2292  }
2293 
2295 
2296  return true;
2297 }
2298 
2299 
2302  const fileName& directory,
2303  const word& constantName
2304 ) const
2305 {
2306  const auto iter = times_.cfind(directory);
2307  if (iter.found())
2308  {
2309  if (debug)
2310  {
2311  Pout<< "masterUncollatedFileOperation::findTimes :"
2312  << " Found " << iter()->size() << " cached times" << endl;
2313  }
2314  return *iter();
2315  }
2316  else
2317  {
2318  instantList times;
2319  if (Pstream::master()) // comm_))
2320  {
2321  // Do master-only reading always.
2322  bool oldParRun = UPstream::parRun();
2323  UPstream::parRun() = false;
2324  times = fileOperation::findTimes(directory, constantName);
2325  UPstream::parRun() = oldParRun;
2326  }
2327  Pstream::scatter(times); //, Pstream::msgType(), comm_);
2328 
2329  // Note: do we also cache if no times have been found since it might
2330  // indicate a directory that is being filled later on ...
2331 
2332  instantList* tPtr = new instantList(std::move(times));
2333 
2334  times_.set(directory, tPtr);
2335 
2336  if (debug)
2337  {
2338  Pout<< "masterUncollatedFileOperation::findTimes :"
2339  << " Caching times:" << *tPtr << nl
2340  << " for directory:" << directory << endl;
2341  }
2342  return *tPtr;
2343  }
2344 }
2345 
2346 
2349  const Time& tm
2350 ) const
2351 {
2352  if (tm.subCycling())
2353  {
2354  return;
2355  }
2356 
2357  // Mutable access to instantList for modification and sorting
2358  HashPtrTable<instantList>::iterator iter = times_.find(tm.path());
2359 
2360  if (iter.found())
2361  {
2362  instantList& times = *iter();
2363 
2364  const instant timeNow(tm.value(), tm.timeName());
2365 
2366  if (times.size() > 0 && times[0].name() == tm.constant())
2367  {
2368  // Exclude constant
2369  SubList<instant> realTimes(times, times.size()-1, 1);
2370  if
2371  (
2373  (
2374  SubList<instant>(times, times.size()-1, 1),
2375  timeNow
2376  )
2377  == -1
2378  )
2379  {
2380  if (debug)
2381  {
2382  Pout<< "masterUncollatedFileOperation::setTime :"
2383  << " Caching time " << tm.timeName()
2384  << " for case:" << tm.path() << endl;
2385  }
2386 
2387  times.append(timeNow);
2388  SubList<instant> realTimes(times, times.size()-1, 1);
2389  Foam::stableSort(realTimes);
2390  }
2391  }
2392  else
2393  {
2394  if (findSortedIndex(times, timeNow) == -1)
2395  {
2396  if (debug)
2397  {
2398  Pout<< "masterUncollatedFileOperation::setTime :"
2399  << " Caching time " << tm.timeName()
2400  << " for case:" << tm.path() << endl;
2401  }
2402 
2403  times.append(timeNow);
2404  Foam::stableSort(times);
2405  }
2406  }
2407  }
2409 }
2410 
2411 
2415  const fileName& filePath
2416 ) const
2417 {
2418  if (Pstream::parRun())
2419  {
2420  // Insert logic of filePath. We assume that if a file is absolute
2421  // on the master it is absolute also on the slaves etc.
2422 
2424  filePaths[Pstream::myProcNo(Pstream::worldComm)] = filePath;
2426 
2427  PstreamBuffers pBufs
2428  (
2430  Pstream::msgType(),
2432  );
2433 
2435  {
2436  const bool uniform = uniformFile(filePaths);
2437 
2438  if (uniform)
2439  {
2440  if (debug)
2441  {
2442  Pout<< "masterUncollatedFileOperation::NewIFstream :"
2443  << " Opening global file " << filePath << endl;
2444  }
2445 
2447  (
2448  Foam::exists(filePath+".gz", false)
2449  ? IOstream::compressionType::COMPRESSED
2450  : IOstream::compressionType::UNCOMPRESSED
2451  );
2452 
2454  for
2455  (
2456  label proci = 1;
2458  proci++
2459  )
2460  {
2461  procs[proci-1] = proci;
2462  }
2463 
2464  readAndSend(filePath, cmp, procs, pBufs);
2465  }
2466  else
2467  {
2468  for
2469  (
2470  label proci = 1;
2472  proci++
2473  )
2474  {
2476  (
2477  Foam::exists(filePaths[proci]+".gz", false)
2478  ? IOstream::compressionType::COMPRESSED
2479  : IOstream::compressionType::UNCOMPRESSED
2480  );
2481 
2482  readAndSend
2483  (
2484  filePaths[proci],
2485  cmp,
2486  labelList(1, proci),
2487  pBufs
2488  );
2489  }
2490  }
2491  }
2492 
2493 
2494  labelList recvSizes;
2495  pBufs.finishedSends(recvSizes);
2496 
2498  {
2499  // Read myself
2500  return autoPtr<ISstream>
2501  (
2502  new IFstream(filePaths[Pstream::masterNo()])
2503  );
2504  }
2505  else
2506  {
2507  if (debug)
2508  {
2509  Pout<< "masterUncollatedFileOperation::NewIFstream :"
2510  << " Reading " << filePath
2511  << " from processor " << Pstream::masterNo() << endl;
2512  }
2513 
2514  UIPstream is(Pstream::masterNo(), pBufs);
2515 
2516  List<char> buf(recvSizes[Pstream::masterNo()]);
2517  is.read(buf.begin(), buf.size());
2518 
2519  if (debug)
2520  {
2521  Pout<< "masterUncollatedFileOperation::NewIFstream :"
2522  << " Done reading " << buf.size() << " bytes" << endl;
2523  }
2524 
2525  // Note: IPstream is not an IStream so use a IStringStream to
2526  // convert the buffer. Note that we construct with a string
2527  // so it holds a copy of the buffer.
2528  return autoPtr<ISstream>
2529  (
2530  new IListStream
2531  (
2532  std::move(buf),
2535  filePath
2536  )
2537  );
2538  }
2539  }
2540  else
2541  {
2542  // Read myself
2543  return autoPtr<ISstream>(new IFstream(filePath));
2544  }
2545 }
2546 
2547 
2551  const fileName& pathName,
2555  const bool valid
2556 ) const
2557 {
2558  return autoPtr<Ostream>
2559  (
2560  new masterOFstream
2561  (
2562  pathName,
2563  fmt,
2564  ver,
2565  cmp,
2566  false, // append
2567  valid
2568  )
2569  );
2570 }
2571 
2572 
2574 {
2576  times_.clear();
2577 }
2578 
2579 
2582  const fileName& fName
2583 ) const
2584 {
2585  label watchFd = -1;
2586  if (Pstream::master()) // comm_))
2587  {
2588  watchFd = monitor().addWatch(fName);
2589  }
2590  Pstream::scatter(watchFd); //, Pstream::msgType(), comm_);
2591  return watchFd;
2592 }
2593 
2594 
2597  const label watchIndex
2598 ) const
2599 {
2600  bool ok = false;
2601  if (Pstream::master()) // comm_))
2602  {
2603  ok = monitor().removeWatch(watchIndex);
2604  }
2605  Pstream::scatter(ok); //, Pstream::msgType(), comm_);
2606  return ok;
2607 }
2608 
2609 
2612  const labelList& watchIndices,
2613  const fileName& fName
2614 ) const
2615 {
2616  label index = -1;
2617 
2618  if (Pstream::master()) // comm_))
2619  {
2620  forAll(watchIndices, i)
2621  {
2622  if (monitor().getFile(watchIndices[i]) == fName)
2623  {
2624  index = i;
2625  break;
2626  }
2627  }
2628  }
2629  Pstream::scatter(index); //, Pstream::msgType(), comm_);
2630  return index;
2631 }
2632 
2633 
2636  regIOobject& rio,
2637  const fileNameList& files
2638 ) const
2639 {
2640  const labelList& watchIndices = rio.watchIndices();
2641 
2642  DynamicList<label> newWatchIndices;
2643  labelHashSet removedWatches(watchIndices);
2644 
2645  for (const fileName& f : files)
2646  {
2647  const label index = findWatch(watchIndices, f);
2648 
2649  if (index == -1)
2650  {
2651  newWatchIndices.append(addWatch(f));
2652  }
2653  else
2654  {
2655  // Existing watch
2656  newWatchIndices.append(watchIndices[index]);
2657  removedWatches.erase(index);
2658  }
2659  }
2660 
2661  // Remove any unused watches
2662  for (const label index : removedWatches)
2663  {
2664  removeWatch(watchIndices[index]);
2665  }
2666 
2667  rio.watchIndices() = newWatchIndices;
2668 }
2669 
2670 
2673  const label watchIndex
2674 ) const
2675 {
2676  fileName fName;
2677  if (Pstream::master()) // comm_))
2678  {
2679  fName = monitor().getFile(watchIndex);
2680  }
2681  Pstream::scatter(fName); //, Pstream::msgType(), comm_);
2682  return fName;
2683 }
2684 
2685 
2688  const bool masterOnly,
2689  const bool syncPar
2690 ) const
2691 {
2692  if (Pstream::master()) // comm_))
2693  {
2694  monitor().updateStates(true, false);
2695  }
2696 }
2697 
2698 
2702  const label watchFd
2703 ) const
2704 {
2705  unsigned int state = fileMonitor::UNMODIFIED;
2706  if (Pstream::master()) // comm_))
2707  {
2708  state = monitor().getState(watchFd);
2709  }
2710  Pstream::scatter(state); //, Pstream::msgType(), comm_);
2711  return fileMonitor::fileState(state);
2712 }
2713 
2714 
2717  const label watchFd
2718 ) const
2719 {
2720  if (Pstream::master()) // comm_))
2721  {
2722  monitor().setUnmodified(watchFd);
2723  }
2724 }
2725 
2726 
2727 // ************************************************************************* //
Foam::fileOperations::masterUncollatedFileOperation::setUnmodified
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
Definition: masterUncollatedFileOperation.C:2716
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
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:948
Foam::fileOperations::masterUncollatedFileOperation::getFile
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
Definition: masterUncollatedFileOperation.C:2672
Foam::autoPtr::reset
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:158
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:91
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:1130
Foam::UPstream::commsTypes::nonBlocking
Foam::fileOperations::masterUncollatedFileOperation::setTime
virtual void setTime(const Time &) const
Callback for time change.
Definition: masterUncollatedFileOperation.C:2348
Foam::UPstream::masterNo
static constexpr int masterNo() noexcept
Process index of the master.
Definition: UPstream.H:432
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:46
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:1328
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:75
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:74
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:64
Foam::fileOperations::masterUncollatedFileOperation::uniformFile
static bool uniformFile(const fileNameList &)
Same file?
Definition: masterUncollatedFileOperation.C:477
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:1112
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:94
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:97
Foam::DynamicList< label >
Foam::decomposedBlockData::readBlock
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
Definition: decomposedBlockData.C:243
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 stream for input. Aborts at any attempt to read from it.
Definition: dummyISstream.H:50
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:444
Foam::IOobject::instance
const fileName & instance() const
Definition: IOobjectI.H:167
Foam::fileOperations::masterUncollatedFileOperation::mode
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
Definition: masterUncollatedFileOperation.C:932
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:426
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:88
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:414
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:1000
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:764
Foam::fileOperation::pathTypeNames_
static const Enum< pathType > pathTypeNames_
Definition: fileOperation.H:97
Foam::fileOperation::PROCINSTANCE
Definition: fileOperation.H:95
Foam::fileOperation::flush
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
Definition: fileOperation.C:988
Foam::fileOperations::masterUncollatedFileOperation::fileSize
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
Definition: masterUncollatedFileOperation.C:1017
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::fileName::Type
Type
Enumerations to handle directory entry types.
Definition: fileName.H:76
Foam::regIOobject::global
virtual bool global() const
Is object global.
Definition: regIOobject.H:313
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:72
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::autoPtr::valid
bool valid() const noexcept
True if the managed pointer is non-null.
Definition: autoPtrI.H:107
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
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:404
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:1165
Foam::fileOperations::masterUncollatedFileOperation::maxMasterFileBufferSize
static float maxMasterFileBufferSize
Max size of parallel communications. Switches from non-blocking.
Definition: masterUncollatedFileOperation.H:494
Foam::fileOperations::masterUncollatedFileOperation::chMod
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
Definition: masterUncollatedFileOperation.C:916
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
Foam::HashSet< label, Hash< label > >
bitSet.H
Foam::IOobject::time
const Time & time() const
Return time.
Definition: IOobject.C:438
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:856
Foam::fileOperation::ABSOLUTE
Definition: fileOperation.H:83
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:677
Foam::fileOperations::masterUncollatedFileOperation::~masterUncollatedFileOperation
virtual ~masterUncollatedFileOperation()
Destructor.
Definition: masterUncollatedFileOperation.C:888
Foam::fileOperations::masterUncollatedFileOperation::fileOrNullOp
Definition: masterUncollatedFileOperation.H:343
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::stableSort
void stableSort(UList< T > &a)
Definition: UList.C:255
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:432
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:462
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:1912
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:590
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:419
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:179
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::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:1183
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::decomposedBlockData::readMasterHeader
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
Definition: decomposedBlockData.C:170
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::HashTable::erase
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
Definition: HashTable.C:392
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::fileOperations::masterUncollatedFileOperation::fileSizeOp
Definition: masterUncollatedFileOperation.H:212
Foam::tmpNrc
A class for managing temporary objects without reference counting.
Definition: tmpNrc.H:56
Foam::fileOperations::masterUncollatedFileOperation::rmOp
Definition: masterUncollatedFileOperation.H:275
Foam::fileOperation::pathType
pathType
Enumeration for the location of an IOobject.
Definition: fileOperation.H:80
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:515
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:472
Foam::fileOperations::masterUncollatedFileOperation::lastModified
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
Definition: masterUncollatedFileOperation.C:1033
Foam::IOobject::caseName
const fileName & caseName() const
Definition: IOobject.C:450
Foam::fileOperations::addToRunTimeSelectionTable
addToRunTimeSelectionTable(fileOperation, collatedFileOperation, word)
Foam::IOobject::globalObject
bool globalObject() const
Is object same for all processors?
Definition: IOobjectI.H:100
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:2611
Foam::TimePaths::times
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:149
Foam::fileOperations::masterUncollatedFileOperation::exists
bool exists(const dirIndexList &, IOobject &io) const
Helper: check IO for local existence. Like filePathInfo but.
Definition: masterUncollatedFileOperation.C:1451
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::autoPtr::ptr
T * ptr() noexcept
Definition: autoPtrI.H:144
Foam::fileOperations::masterUncollatedFileOperation::highResLastModified
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
Definition: masterUncollatedFileOperation.C:1049
Foam::fileOperation::NOTFOUND
Definition: fileOperation.H:82
Foam::fileOperations::masterUncollatedFileOperation::removeWatch
virtual bool removeWatch(const label) const
Remove watch on a file (using handle)
Definition: masterUncollatedFileOperation.C:2596
Foam::fileOperations::unthreadedInitialise
Definition: unthreadedInitialise.H:46
IFstream.H
Foam::fileOperation::PROCBASEINSTANCE
Definition: fileOperation.H:94
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:759
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
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:2687
Foam::fileOperation::PROCUNCOLLATEDINSTANCE
Definition: fileOperation.H:93
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:112
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:1096
Foam::fileOperations::masterUncollatedFileOperation::mvBak
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
Definition: masterUncollatedFileOperation.C:1065
fileOperationInitialise
Foam::UPstream::commsStruct::above
label above() const
Definition: UPstream.H:129
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:1700
Foam::infoDetailLevel
int infoDetailLevel
Global for selective suppression of Info output.
Foam::UPstream::commsStruct
Structure for communicating between processors.
Definition: UPstream.H:80
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:900
Foam::IOobject::headerClassName
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobjectI.H:64
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:444
Foam::fileOperations::masterUncollatedFileOperation::getState
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
Definition: masterUncollatedFileOperation.C:2701
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:438
IListStream.H
Foam::UPstream::nProcsSimpleSum
static int nProcsSimpleSum
Definition: UPstream.H:270
Foam::IFstream::stdStream
virtual std::istream & stdStream()
Access to underlying std::istream.
Definition: IFstream.C:144
unthreadedInitialise.H
Foam::Detail::StringStreamAllocator::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:92
Time.H
Foam::IOobject::note
const string & note() const
Return the optional note.
Definition: IOobjectI.H:76
Foam::autoPtr< Foam::ISstream >
Foam::fileOperations::masterUncollatedFileOperation::chModOp
Definition: masterUncollatedFileOperation.H:117
Foam::fileOperations::masterUncollatedFileOperation::readAndSend
static void readAndSend(const fileName &filePath, const IOstream::compressionType cmp, const labelUList &procs, PstreamBuffers &pBufs)
Read file contents and send to processors.
Definition: masterUncollatedFileOperation.C:495
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::fileOperations::masterUncollatedFileOperation::flush
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
Definition: masterUncollatedFileOperation.C:2573
Foam::IOstreamOption::BINARY
"binary"
Definition: IOstreamOption.H:67
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:491
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
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:339
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:303
Foam::fileOperations::masterUncollatedFileOperation::addWatch
virtual label addWatch(const fileName &) const
Add watching of a file. Returns handle.
Definition: masterUncollatedFileOperation.C:2581
Foam::fileOperations::masterUncollatedFileOperation::rm
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
Definition: masterUncollatedFileOperation.C:1081
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:74
Foam::fileOperation::WRITEOBJECT
Definition: fileOperation.H:85
decomposedBlockData.H
Foam::UPstream::worldComm
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:285
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::IOobject::readOpt
readOption readOpt() const
The read option.
Definition: IOobjectI.H:141
Foam::OStringStream
Output to string buffer, using a OSstream.
Definition: StringStream.H:189
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:2414
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:882
path
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
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::writeObject
virtual bool writeObject(const regIOobject &, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool valid=true) const
Writes a regIOobject (so header, contents and divider).
Definition: masterUncollatedFileOperation.C:2245
Foam::fileOperations::masterUncollatedFileOperation::readHeader
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
Definition: masterUncollatedFileOperation.C:1787
Foam::fileOperation::PROCOBJECT
Definition: fileOperation.H:89
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:984
Foam::autoPtr::clear
void clear() noexcept
Delete managed object and set pointer to nullptr.
Definition: autoPtrI.H:151
Foam::fileOperations::masterUncollatedFileOperation::lnOp
Definition: masterUncollatedFileOperation.H:318
forAllReverse
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: stdFoam.H:303
Foam::fileOperations::masterUncollatedFileOperation::localObjectPath
fileName localObjectPath(const IOobject &, const pathType &searchType, const word &processorsDir, const word &instancePath) const
Construct filePath.
Definition: masterUncollatedFileOperation.C:335
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:71
Foam::fileOperation::PROCUNCOLLATED
Definition: fileOperation.H:86
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:92
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:375
registerSwitch.H
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::UIPstream
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:56
Foam::UPstream::linearCommunication
static const List< commsStruct > & linearCommunication(const label communicator=0)
Communication schedule for linear all-to-master (proc 0)
Definition: UPstream.H:474
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:216
Foam::fileOperations::masterUncollatedFileOperation::findTimes
virtual instantList findTimes(const fileName &, const word &) const
Get sorted list of times.
Definition: masterUncollatedFileOperation.C:2301
Foam::IOobject::objectPath
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:185
Foam::TimePaths::processorCase
bool processorCase() const
Return true if this is a processor case.
Definition: TimePathsI.H:36
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:1148
Foam::fileOperation::OBJECT
Definition: fileOperation.H:84
Foam::fileOperations::masterUncollatedFileOperation::NewOFstream
virtual autoPtr< Ostream > NewOFstream(const fileName &pathname, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool valid=true) const
Generate an Ostream that writes a file.
Definition: masterUncollatedFileOperation.C:2550
Foam::HashPtrTable::iterator
typename parent_type::iterator iterator
Definition: HashPtrTable.H:88
Foam::IOobject::path
fileName path() const
The complete path.
Definition: IOobject.C:456
Foam::fileOperations::masterUncollatedFileOperation::addWatches
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
Definition: masterUncollatedFileOperation.C:2635
Foam::fileOperations::masterUncollatedFileOperation::mkDirOp
Definition: masterUncollatedFileOperation.H:102
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
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::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54
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:50
Foam::fileOperations::defineTypeNameAndDebug
defineTypeNameAndDebug(collatedFileOperation, 0)
Foam::fileOperation::PROCBASEOBJECT
Definition: fileOperation.H:87
Foam::fileOperations::masterUncollatedFileOperation::mvOp
Definition: masterUncollatedFileOperation.H:327
Foam::UPstream::commsStruct::below
const labelList & below() const
Definition: UPstream.H:134
Foam::UPstream::treeCommunication
static const List< commsStruct > & treeCommunication(const label communicator=0)
Communication schedule for tree all-to-master (proc 0)
Definition: UPstream.H:483
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:1500