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  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 labelUList& procs,
498  PstreamBuffers& pBufs
499 )
500 {
501  IFstream ifs(filePath, IOstream::streamFormat::BINARY);
502 
503  if (!ifs.good())
504  {
505  FatalIOErrorInFunction(filePath)
506  << "Cannot open file " << filePath
507  << exit(FatalIOError);
508  }
509 
510  if (debug)
511  {
512  Pout<< "masterUncollatedFileOperation::readAndSend :"
513  << " compressed:" << bool(ifs.compression()) << " "
514  << filePath << endl;
515  }
516 
517  if (ifs.compression() == IOstream::compressionType::COMPRESSED)
518  {
519  // Could use Foam::fileSize, estimate uncompressed size (eg, 2x)
520  // and then string reserve followed by string assign...
521 
522  // Uncompress and read file contents into a character buffer
523  const std::string buf
524  (
525  std::istreambuf_iterator<char>(ifs.stdStream()),
526  std::istreambuf_iterator<char>()
527  );
528 
529  for (const label proci : procs)
530  {
531  UOPstream os(proci, pBufs);
532  os.write(buf.data(), buf.length());
533  }
534 
535  if (debug)
536  {
537  Pout<< "masterUncollatedFileOperation::readStream :"
538  << " From " << filePath << " sent " << buf.size()
539  << " bytes" << endl;
540  }
541  }
542  else
543  {
544  const off_t count(Foam::fileSize(filePath));
545 
546  // Read file contents into a character buffer
547  List<char> buf(static_cast<label>(count));
548  ifs.stdStream().read(buf.data(), count);
549 
550  for (const label proci : procs)
551  {
552  UOPstream os(proci, pBufs);
553  os.write(buf.cdata(), count);
554  }
555 
556  if (debug)
557  {
558  Pout<< "masterUncollatedFileOperation::readStream :"
559  << " From " << filePath << " sent " << buf.size()
560  << " bytes" << endl;
561  }
562  }
563 }
564 
565 
568 (
569  IOobject& io,
570  const label comm,
571  const bool uniform, // on comms master only
572  const fileNameList& filePaths, // on comms master only
573  const boolList& procValid // on comms master only
574 )
575 {
576  autoPtr<ISstream> isPtr;
577 
578  // const bool uniform = uniformFile(filePaths);
579 
580  PstreamBuffers pBufs
581  (
582  Pstream::commsTypes::nonBlocking,
583  Pstream::msgType(),
584  comm
585  );
586 
587  if (Pstream::master(comm))
588  {
589  if (uniform)
590  {
591  if (procValid[0])
592  {
593  if (filePaths[0].empty())
594  {
595  FatalIOErrorInFunction(filePaths[0])
596  << "cannot find file " << io.objectPath()
597  << exit(FatalIOError);
598  }
599 
600  DynamicList<label> validProcs(Pstream::nProcs(comm));
601  for
602  (
603  label proci = 0;
604  proci < Pstream::nProcs(comm);
605  proci++
606  )
607  {
608  if (procValid[proci])
609  {
610  validProcs.append(proci);
611  }
612  }
613 
614  // Read on master and send to all processors (including
615  // master for simplicity)
616  if (debug)
617  {
618  Pout<< "masterUncollatedFileOperation::readStream :"
619  << " For uniform file " << filePaths[0]
620  << " sending to " << validProcs
621  << " in comm:" << comm << endl;
622  }
623  readAndSend(filePaths[0], validProcs, pBufs);
624  }
625  }
626  else
627  {
628  if (procValid[0])
629  {
630  if (filePaths[0].empty())
631  {
632  FatalIOErrorInFunction(filePaths[0])
633  << "cannot find file " << io.objectPath()
634  << exit(FatalIOError);
635  }
636 
637  // Open master
638  isPtr.reset(new IFstream(filePaths[0]));
639 
640  // Read header
641  if (!io.readHeader(*isPtr))
642  {
643  FatalIOErrorInFunction(*isPtr)
644  << "problem while reading header for object "
645  << io.name() << exit(FatalIOError);
646  }
647  }
648 
649  // Read slave files
650  for
651  (
652  label proci = 1;
653  proci < Pstream::nProcs(comm);
654  proci++
655  )
656  {
657  if (debug)
658  {
659  Pout<< "masterUncollatedFileOperation::readStream :"
660  << " For processor " << proci
661  << " opening " << filePaths[proci] << endl;
662  }
663 
664  const fileName& fPath = filePaths[proci];
665 
666  if (procValid[proci] && !fPath.empty())
667  {
668  // Note: handle compression ourselves since size cannot
669  // be determined without actually uncompressing
670  readAndSend(fPath, labelList(1, proci), pBufs);
671  }
672  }
673  }
674  }
675 
676  labelList recvSizes;
677  pBufs.finishedSends(recvSizes);
678 
679  // isPtr will be valid on master and will be the unbuffered
680  // IFstream. Else the information is in the PstreamBuffers (and
681  // the special case of a uniform file)
682 
683  if (procValid[Pstream::myProcNo(comm)])
684  {
685  // This processor needs to return something
686 
687  if (!isPtr)
688  {
689  UIPstream is(Pstream::masterNo(), pBufs);
690 
691  List<char> buf(recvSizes[Pstream::masterNo()]);
692  if (recvSizes[Pstream::masterNo()] > 0)
693  {
694  is.read(buf.data(), recvSizes[Pstream::masterNo()]);
695  }
696 
697  if (debug)
698  {
699  Pout<< "masterUncollatedFileOperation::readStream :"
700  << " Done reading " << buf.size() << " bytes" << endl;
701  }
702 
703  // A local character buffer copy of the Pstream contents.
704  // Construct with same parameters (ASCII, current version)
705  // as the IFstream so that it has the same characteristics.
706 
707  isPtr.reset(new IListStream(std::move(buf)));
708 
709  // With the proper file name
710  isPtr->name() = filePaths[Pstream::myProcNo(comm)];
711 
712  if (!io.readHeader(*isPtr))
713  {
714  FatalIOErrorInFunction(*isPtr)
715  << "problem while reading header for object "
716  << io.name() << exit(FatalIOError);
717  }
718  }
719  }
720  else
721  {
722  isPtr.reset(new dummyISstream());
723  }
724 
725  return isPtr;
726 }
727 
728 
729 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
730 
733 (
734  bool verbose
735 )
736 :
738  (
739  UPstream::allocateCommunicator
740  (
741  UPstream::worldComm,
742  subRanks(Pstream::nProcs())
743  )
744  ),
745  myComm_(comm_)
746 {
747  verbose = (verbose && Foam::infoDetailLevel > 0);
748 
749  if (verbose)
750  {
751  DetailInfo
752  << "I/O : " << typeName
753  << " (maxMasterFileBufferSize " << maxMasterFileBufferSize << ')'
754  << endl;
755  }
756 
757  if (regIOobject::fileModificationChecking == regIOobject::timeStampMaster)
758  {
759  if (verbose)
760  {
762  << "Resetting fileModificationChecking to timeStamp" << endl;
763  }
764  regIOobject::fileModificationChecking = regIOobject::timeStamp;
765  }
766  else if
767  (
768  regIOobject::fileModificationChecking
769  == regIOobject::inotifyMaster
770  )
771  {
772  if (verbose)
773  {
775  << "Resetting fileModificationChecking to inotify"
776  << endl;
777  }
778  regIOobject::fileModificationChecking = regIOobject::inotify;
779  }
780 }
781 
782 
785 (
786  const label comm,
787  bool verbose
788 )
789 :
790  fileOperation(comm),
791  myComm_(-1)
792 {
793  verbose = (verbose && Foam::infoDetailLevel > 0);
794 
795  if (verbose)
796  {
797  DetailInfo
798  << "I/O : " << typeName
799  << " (maxMasterFileBufferSize " << maxMasterFileBufferSize << ')'
800  << endl;
801  }
802 
803  if (regIOobject::fileModificationChecking == regIOobject::timeStampMaster)
804  {
805  if (verbose)
806  {
808  << "Resetting fileModificationChecking to timeStamp" << endl;
809  }
810  regIOobject::fileModificationChecking = regIOobject::timeStamp;
811  }
812  else if
813  (
814  regIOobject::fileModificationChecking
815  == regIOobject::inotifyMaster
816  )
817  {
818  if (verbose)
819  {
821  << "Resetting fileModificationChecking to inotify"
822  << endl;
823  }
824  regIOobject::fileModificationChecking = regIOobject::inotify;
825  }
826 }
827 
828 
831 :
832  unthreadedInitialise(argc, argv)
833 {
834  // Filter out any of my arguments
835  const string s("-ioRanks");
836 
837  int index = -1;
838  for (int i=1; i<argc-1; i++)
839  {
840  if (argv[i] == s)
841  {
842  index = i;
843  setEnv("FOAM_IORANKS", argv[i+1], true);
844  break;
845  }
846  }
847 
848  if (index != -1)
849  {
850  for (int i=index+2; i<argc; i++)
851  {
852  argv[i-2] = argv[i];
853  }
854  argc -= 2;
855  }
856 }
857 
858 
859 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
860 
863 {
864  if (myComm_ != -1 && myComm_ != UPstream::worldComm)
865  {
867  }
868 }
869 
870 
871 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
872 
874 (
875  const fileName& dir,
876  mode_t mode
877 ) const
878 {
879  return masterOp<mode_t, mkDirOp>
880  (
881  dir,
882  mkDirOp(mode),
884  comm_
885  );
886 }
887 
888 
890 (
891  const fileName& fName,
892  mode_t mode
893 ) const
894 {
895  return masterOp<mode_t, chModOp>
896  (
897  fName,
898  chModOp(mode),
900  comm_
901  );
902 }
903 
904 
906 (
907  const fileName& fName,
908  const bool followLink
909 ) const
910 {
911  return masterOp<mode_t, modeOp>
912  (
913  fName,
914  modeOp(followLink),
916  comm_
917  );
918 }
919 
920 
922 (
923  const fileName& fName,
924  const bool followLink
925 ) const
926 {
927  return fileName::Type
928  (
929  masterOp<label, typeOp>
930  (
931  fName,
932  typeOp(followLink),
934  comm_
935  )
936  );
937 }
938 
939 
941 (
942  const fileName& fName,
943  const bool checkGzip,
944  const bool followLink
945 ) const
946 {
947  return masterOp<bool, existsOp>
948  (
949  fName,
950  existsOp(checkGzip, followLink),
952  comm_
953  );
954 }
955 
956 
958 (
959  const fileName& fName,
960  const bool followLink
961 ) const
962 {
963  return masterOp<bool, isDirOp>
964  (
965  fName,
966  isDirOp(followLink),
968  comm_
969  );
970 }
971 
972 
974 (
975  const fileName& fName,
976  const bool checkGzip,
977  const bool followLink
978 ) const
979 {
980  return masterOp<bool, isFileOp>
981  (
982  fName,
983  isFileOp(checkGzip, followLink),
985  comm_
986  );
987 }
988 
989 
991 (
992  const fileName& fName,
993  const bool followLink
994 ) const
995 {
996  return masterOp<off_t, fileSizeOp>
997  (
998  fName,
999  fileSizeOp(followLink),
1000  Pstream::msgType(),
1001  comm_
1002  );
1003 }
1004 
1005 
1008  const fileName& fName,
1009  const bool followLink
1010 ) const
1011 {
1012  return masterOp<time_t, lastModifiedOp>
1013  (
1014  fName,
1015  lastModifiedOp(followLink),
1016  Pstream::msgType(),
1017  comm_
1018  );
1019 }
1020 
1021 
1024  const fileName& fName,
1025  const bool followLink
1026 ) const
1027 {
1028  return masterOp<double, lastModifiedHROp>
1029  (
1030  fName,
1031  lastModifiedHROp(followLink),
1032  Pstream::msgType(),
1033  comm_
1034  );
1035 }
1036 
1037 
1040  const fileName& fName,
1041  const std::string& ext
1042 ) const
1043 {
1044  return masterOp<bool, mvBakOp>
1045  (
1046  fName,
1047  mvBakOp(ext),
1048  Pstream::msgType(),
1049  comm_
1050  );
1051 }
1052 
1053 
1056  const fileName& fName
1057 ) const
1058 {
1059  return masterOp<bool, rmOp>
1060  (
1061  fName,
1062  rmOp(),
1063  Pstream::msgType(),
1064  comm_
1065  );
1066 }
1067 
1068 
1071  const fileName& dir,
1072  const bool silent
1073 ) const
1074 {
1075  return masterOp<bool, rmDirOp>
1076  (
1077  dir,
1078  rmDirOp(silent),
1079  Pstream::msgType(),
1080  comm_
1081  );
1082 }
1083 
1084 
1087  const fileName& dir,
1088  const fileName::Type type,
1089  const bool filtergz,
1090  const bool followLink
1091 ) const
1092 {
1093  return masterOp<fileNameList, readDirOp>
1094  (
1095  dir,
1096  readDirOp(type, filtergz, followLink),
1097  Pstream::msgType(),
1098  comm_
1099  );
1100 }
1101 
1102 
1105  const fileName& src,
1106  const fileName& dst,
1107  const bool followLink
1108 ) const
1109 {
1110  return masterOp<bool, cpOp>
1111  (
1112  src,
1113  dst,
1114  cpOp(followLink),
1115  Pstream::msgType(),
1116  comm_
1117  );
1118 }
1119 
1120 
1123  const fileName& src,
1124  const fileName& dst
1125 ) const
1126 {
1127  return masterOp<bool, lnOp>
1128  (
1129  src,
1130  dst,
1131  lnOp(),
1132  Pstream::msgType(),
1133  comm_
1134  );
1135 }
1136 
1137 
1140  const fileName& src,
1141  const fileName& dst,
1142  const bool followLink
1143 ) const
1144 {
1145  return masterOp<bool, mvOp>
1146  (
1147  src,
1148  dst,
1149  mvOp(followLink),
1150  Pstream::msgType(),
1151  comm_
1152  );
1153 }
1154 
1155 
1158  const bool checkGlobal,
1159  const IOobject& io,
1160  const word& typeName,
1161  const bool search
1162 ) const
1163 {
1164  if (debug)
1165  {
1166  Pout<< "masterUncollatedFileOperation::filePath :"
1167  << " objectPath:" << io.objectPath()
1168  << " checkGlobal:" << checkGlobal << endl;
1169  }
1170 
1171  // Now that we have an IOobject path use it to detect & cache
1172  // processor directory naming
1173  (void)lookupProcessorsPath(io.objectPath());
1174 
1175  // Trigger caching of times
1176  (void)findTimes(io.time().path(), io.time().constant());
1177 
1178 
1179  // Determine master filePath and scatter
1180 
1181  fileName objPath;
1182  pathType searchType = NOTFOUND;
1183  word procsDir;
1184  word newInstancePath;
1185 
1186  if (Pstream::master(comm_))
1187  {
1188  // All masters search locally. Note that global objects might
1189  // fail (except on master). This gets handled later on (in PARENTOBJECT)
1190  objPath =
1191  filePathInfo
1192  (
1193  checkGlobal,
1194  true,
1195  io,
1196  search,
1197  searchType,
1198  procsDir,
1199  newInstancePath
1200  );
1201 
1202  if (debug)
1203  {
1204  Pout<< "masterUncollatedFileOperation::filePath :"
1205  << " master objPath:" << objPath
1206  << " searchType:" << fileOperation::pathTypeNames_[searchType]
1207  << " procsDir:" << procsDir << " instance:" << newInstancePath
1208  << endl;
1209  }
1210  }
1211 
1212  // Scatter the information about where the master found the object
1213  // Note: use the worldComm to make sure all processors decide
1214  // the same type. Only procsDir is allowed to differ; searchType
1215  // and instance have to be same
1216  {
1217  label masterType(searchType);
1218  Pstream::scatter(masterType);
1219  searchType = pathType(masterType);
1220  }
1221  Pstream::scatter(newInstancePath);
1222 
1223  if
1224  (
1225  checkGlobal
1226  || searchType == fileOperation::PARENTOBJECT
1227  || searchType == fileOperation::PROCBASEOBJECT
1228  || searchType == fileOperation::PROCBASEINSTANCE
1229  || io.local() == "uniform"
1230  )
1231  {
1232  // Distribute master path. This makes sure it is seen as uniform
1233  // and only gets read from the master.
1234  Pstream::scatter(objPath);
1235  Pstream::scatter(procsDir);
1236  }
1237  else
1238  {
1239  Pstream::scatter(procsDir, Pstream::msgType(), comm_);
1240 
1241  // Use the master type to determine if additional information is
1242  // needed to construct the local equivalent
1243  switch (searchType)
1244  {
1248  {
1249  // Already handled above
1250  }
1251  break;
1252 
1260  {
1261  // Construct equivalent local path
1262  objPath = localObjectPath
1263  (
1264  io,
1265  searchType,
1266  procsDir,
1267  newInstancePath
1268  );
1269  }
1270  break;
1271 
1272  case fileOperation::OBJECT:
1274  {
1275  // Retest all processors separately since some processors might
1276  // have the file and some not (e.g. lagrangian data)
1277 
1278  objPath = masterOp<fileName, fileOrNullOp>
1279  (
1280  io.objectPath(),
1281  fileOrNullOp(true),
1282  Pstream::msgType(),
1283  comm_
1284  );
1285  }
1286  break;
1287  }
1288  }
1289 
1290  if (debug)
1291  {
1292  Pout<< "masterUncollatedFileOperation::filePath :"
1293  << " Returning from file searching:" << endl
1294  << " objectPath:" << io.objectPath() << endl
1295  << " filePath :" << objPath << endl << endl;
1296  }
1297  return objPath;
1298 }
1299 
1300 
1303  const bool checkGlobal,
1304  const IOobject& io,
1305  const bool search
1306 ) const
1307 {
1308  if (debug)
1309  {
1310  Pout<< "masterUncollatedFileOperation::dirPath :"
1311  << " objectPath:" << io.objectPath()
1312  << " checkGlobal:" << checkGlobal << endl;
1313  }
1314 
1315  // Now that we have an IOobject path use it to detect & cache
1316  // processor directory naming
1317  (void)lookupProcessorsPath(io.objectPath());
1318 
1319  // Determine master dirPath and scatter
1320 
1321  fileName objPath;
1322  pathType searchType = NOTFOUND;
1323  word procsDir;
1324  word newInstancePath;
1325 
1326  if (Pstream::master(comm_))
1327  {
1328  objPath = filePathInfo
1329  (
1330  checkGlobal,
1331  false,
1332  io,
1333  search,
1334  searchType,
1335  procsDir,
1336  newInstancePath
1337  );
1338  }
1339 
1340  {
1341  label masterType(searchType);
1342  Pstream::scatter(masterType); //, Pstream::msgType(), comm_);
1343  searchType = pathType(masterType);
1344  }
1345  Pstream::scatter(newInstancePath); //, Pstream::msgType(), comm_);
1346 
1347  if
1348  (
1349  checkGlobal
1350  || searchType == fileOperation::PARENTOBJECT
1351  || searchType == fileOperation::PROCBASEOBJECT
1352  || searchType == fileOperation::PROCBASEINSTANCE
1353  || io.local() == "uniform"
1354  )
1355  {
1356  // Distribute master path. This makes sure it is seen as uniform
1357  // and only gets read from the master.
1358  Pstream::scatter(objPath);
1359  Pstream::scatter(procsDir);
1360  }
1361  else
1362  {
1363  Pstream::scatter(procsDir, Pstream::msgType(), comm_);
1364 
1365  // Use the master type to determine if additional information is
1366  // needed to construct the local equivalent
1367  switch (searchType)
1368  {
1372  {
1373  // Already handled above
1374  }
1375  break;
1376 
1384  {
1385  // Construct equivalent local path
1386  objPath = localObjectPath
1387  (
1388  io,
1389  searchType,
1390  procsDir,
1391  newInstancePath
1392  );
1393  }
1394  break;
1395 
1396  case fileOperation::OBJECT:
1398  {
1399  // Retest all processors separately since some processors might
1400  // have the file and some not (e.g. lagrangian data)
1401 
1402  objPath = masterOp<fileName, fileOrNullOp>
1403  (
1404  io.objectPath(),
1405  fileOrNullOp(false),
1406  Pstream::msgType(),
1407  comm_
1408  );
1409  }
1410  break;
1411  }
1412  }
1413 
1414  if (debug)
1415  {
1416  Pout<< "masterUncollatedFileOperation::dirPath :"
1417  << " Returning from file searching:" << endl
1418  << " objectPath:" << io.objectPath() << endl
1419  << " filePath :" << objPath << endl << endl;
1420  }
1421  return objPath;
1422 }
1423 
1424 
1427  const dirIndexList& pDirs,
1428  IOobject& io
1429 ) const
1430 {
1431  // Cut-down version of filePathInfo that does not look for
1432  // different instance or parent directory
1433 
1434  const bool isFile = !io.name().empty();
1435 
1436  // Generate output filename for object
1437  const fileName writePath(objectPath(io, word::null));
1438 
1439  // 1. Test writing name for either directory or a (valid) file
1440  if (isFileOrDir(isFile, writePath))
1441  {
1442  return true;
1443  }
1444 
1445  // 2. Check processors/
1446  if (io.time().processorCase())
1447  {
1448  forAll(pDirs, i)
1449  {
1450  const fileName& pDir = pDirs[i].first();
1451  fileName procPath =
1452  processorsPath(io, io.instance(), pDir)
1453  /io.name();
1454  if (procPath != writePath && isFileOrDir(isFile, procPath))
1455  {
1456  return true;
1457  }
1458  }
1459  }
1460 
1461  // 3. Check local
1462  fileName localPath = io.objectPath();
1463 
1464  if (localPath != writePath && isFileOrDir(isFile, localPath))
1465  {
1466  return true;
1467  }
1468 
1469  return false;
1470 }
1471 
1472 
1476  const IOobject& startIO,
1477  const scalar startValue,
1478  const word& stopInstance
1479 ) const
1480 {
1481  if (debug)
1482  {
1483  Pout<< "masterUncollatedFileOperation::findInstance :"
1484  << " Starting searching for name:" << startIO.name()
1485  << " local:" << startIO.local()
1486  << " from instance:" << startIO.instance()
1487  << endl;
1488  }
1489 
1490 
1491  const Time& time = startIO.time();
1492 
1493  IOobject io(startIO);
1494 
1495  // Note: - if name is empty, just check the directory itself
1496  // - check both for isFile and headerOk since the latter does a
1497  // filePath so searches for the file.
1498  // - check for an object with local file scope (so no looking up in
1499  // parent directory in case of parallel)
1500 
1501 
1502  tmpNrc<dirIndexList> pDirs(lookupProcessorsPath(io.objectPath()));
1503 
1504  word foundInstance;
1505 
1506  // if (Pstream::master(comm_))
1508  {
1509  if (exists(pDirs, io))
1510  {
1511  foundInstance = io.instance();
1512  }
1513  }
1514 
1515  // Do parallel early exit to avoid calling time.times()
1516  // Pstream::scatter(foundInstance, Pstream::msgType(), comm_);
1518  if (!foundInstance.empty())
1519  {
1520  io.instance() = foundInstance;
1521  if (debug)
1522  {
1523  Pout<< "masterUncollatedFileOperation::findInstance :"
1524  << " for name:" << io.name() << " local:" << io.local()
1525  << " found starting instance:" << io.instance() << endl;
1526  }
1527  return io;
1528  }
1529 
1530 
1531  // Search back through the time directories to find the time
1532  // closest to and lower than current time
1533 
1534  instantList ts = time.times();
1535  // if (Pstream::master(comm_))
1537  {
1538  label instanceI;
1539 
1540  for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
1541  {
1542  if (ts[instanceI].value() <= startValue)
1543  {
1544  break;
1545  }
1546  }
1547 
1548  // continue searching from here
1549  for (; instanceI >= 0; --instanceI)
1550  {
1551  // Shortcut: if actual directory is the timeName we've
1552  // already tested it
1553  if (ts[instanceI].name() == time.timeName())
1554  {
1555  continue;
1556  }
1557 
1558  io.instance() = ts[instanceI].name();
1559  if (exists(pDirs, io))
1560  {
1561  foundInstance = io.instance();
1562  if (debug)
1563  {
1564  Pout<< "masterUncollatedFileOperation::findInstance :"
1565  << " for name:" << io.name() << " local:" << io.local()
1566  << " found at:" << io.instance()
1567  << endl;
1568  }
1569  break;
1570  }
1571 
1572  // Check if hit minimum instance
1573  if (ts[instanceI].name() == stopInstance)
1574  {
1575  if
1576  (
1577  startIO.readOpt() == IOobject::MUST_READ
1579  )
1580  {
1581  if (io.name().empty())
1582  {
1584  << "Cannot find directory "
1585  << io.local() << " in times " << time.timeName()
1586  << " down to " << stopInstance
1587  << exit(FatalError);
1588  }
1589  else
1590  {
1592  << "Cannot find file \"" << io.name()
1593  << "\" in directory " << io.local()
1594  << " in times " << time.timeName()
1595  << " down to " << stopInstance
1596  << exit(FatalError);
1597  }
1598  }
1599  foundInstance = io.instance();
1600  if (debug)
1601  {
1602  Pout<< "masterUncollatedFileOperation::findInstance :"
1603  << " name:" << io.name() << " local:" << io.local()
1604  << " found at stopinstance:" << io.instance() << endl;
1605  }
1606  break;
1607  }
1608  }
1609 
1610 
1611  if (foundInstance.empty())
1612  {
1613  // times() usually already includes the constant() so would
1614  // have been checked above. Re-test if
1615  // - times() is empty. Sometimes this can happen (e.g. decomposePar
1616  // with collated)
1617  // - times()[0] is not constant
1618  if (!ts.size() || ts[0].name() != time.constant())
1619  {
1620  // Note. This needs to be a hard-coded constant, rather than the
1621  // constant function of the time, because the latter points to
1622  // the case constant directory in parallel cases
1623 
1624  io.instance() = time.constant();
1625  if (exists(pDirs, io))
1626  {
1627  if (debug)
1628  {
1629  Pout<< "masterUncollatedFileOperation::findInstance :"
1630  << " name:" << io.name()
1631  << " local:" << io.local()
1632  << " found at:" << io.instance() << endl;
1633  }
1634  foundInstance = io.instance();
1635  }
1636  }
1637  }
1638 
1639  if (foundInstance.empty())
1640  {
1641  if
1642  (
1643  startIO.readOpt() == IOobject::MUST_READ
1645  )
1646  {
1648  << "Cannot find file \"" << io.name() << "\" in directory "
1649  << io.local() << " in times " << startIO.instance()
1650  << " down to " << time.constant()
1651  << exit(FatalError);
1652  }
1653  else
1654  {
1655  foundInstance = time.constant();
1656  }
1657  }
1658  }
1659 
1660  // Pstream::scatter(foundInstance, Pstream::msgType(), comm_);
1662  io.instance() = foundInstance;
1663  if (debug)
1664  {
1665  Pout<< "masterUncollatedFileOperation::findInstance :"
1666  << " name:" << io.name() << " local:" << io.local()
1667  << " returning instance:" << io.instance() << endl;
1668  }
1669  return io;
1670 }
1671 
1672 
1676  const objectRegistry& db,
1677  const fileName& instance,
1678  const fileName& local,
1679  word& newInstance
1680 ) const
1681 {
1682  if (debug)
1683  {
1684  Pout<< "masterUncollatedFileOperation::readObjects :"
1685  << " db:" << db.objectPath()
1686  << " local:" << local << " instance:" << instance << endl;
1687  }
1688 
1689  fileNameList objectNames;
1690  newInstance = word::null;
1691 
1692  // Note: readObjects uses WORLD to make sure order of objects is the
1693  // same everywhere
1694 
1695  if (Pstream::master()) // comm_))
1696  {
1697  // Avoid fileOperation::readObjects from triggering parallel ops
1698  // (through call to filePath which triggers parallel )
1699  const bool oldParRun = UPstream::parRun();
1700  UPstream::parRun() = false;
1701 
1702  //- Use non-time searching version
1703  objectNames = fileOperation::readObjects
1704  (
1705  db,
1706  instance,
1707  local,
1708  newInstance
1709  );
1710 
1711  if (newInstance.empty())
1712  {
1713  // Find similar time
1714 
1715  // Copy of Time::findInstancePath. We want to avoid the
1716  // parallel call to findTimes. Alternative is to have
1717  // version of findInstancePath that takes instantList ...
1718  const instantList timeDirs
1719  (
1721  (
1722  db.time().path(),
1723  db.time().constant()
1724  )
1725  );
1726 
1727  const instant t(instance);
1728  forAllReverse(timeDirs, i)
1729  {
1730  if (t.equal(timeDirs[i].value()))
1731  {
1732  objectNames = fileOperation::readObjects
1733  (
1734  db,
1735  timeDirs[i].name(), // newly found time
1736  local,
1737  newInstance
1738  );
1739  break;
1740  }
1741  }
1742  }
1743 
1744  UPstream::parRun() = oldParRun;
1745  }
1746 
1747  Pstream::scatter(newInstance); //, Pstream::msgType(), comm_);
1748  Pstream::scatter(objectNames); //, Pstream::msgType(), comm_);
1749 
1750  if (debug)
1751  {
1752  Pout<< "masterUncollatedFileOperation::readObjects :"
1753  << " newInstance:" << newInstance
1754  << " objectNames:" << objectNames << endl;
1755  }
1756 
1757  return objectNames;
1758 }
1759 
1760 
1763  IOobject& io,
1764  const fileName& fName,
1765  const word& typeName
1766 ) const
1767 {
1768  bool ok = false;
1769 
1770  if (debug)
1771  {
1772  Pout<< "masterUncollatedFileOperation::readHeader :" << endl
1773  << " objectPath:" << io.objectPath() << endl
1774  << " fName :" << fName << endl;
1775  }
1776 
1777  // Get filePaths on world master
1779  filePaths[Pstream::myProcNo(Pstream::worldComm)] = fName;
1781  bool uniform = uniformFile(filePaths);
1783 
1784  if (uniform)
1785  {
1787  {
1788  if (!fName.empty())
1789  {
1790  IFstream is(fName);
1791 
1792  if (is.good())
1793  {
1794  ok = io.readHeader(is);
1795  if (io.headerClassName() == decomposedBlockData::typeName)
1796  {
1797  // Read the header inside the container (master data)
1799  }
1800  }
1801  }
1802  }
1805  (
1806  io.headerClassName(),
1807  Pstream::msgType(),
1809  );
1811  }
1812  else
1813  {
1815  {
1816  // Re-gather file paths on local master
1817  filePaths.setSize(Pstream::nProcs(comm_));
1818  filePaths[Pstream::myProcNo(comm_)] = fName;
1819  Pstream::gatherList(filePaths, Pstream::msgType(), comm_);
1820  }
1821 
1822  boolList result(Pstream::nProcs(comm_), false);
1823  wordList headerClassName(Pstream::nProcs(comm_));
1824  stringList note(Pstream::nProcs(comm_));
1825  if (Pstream::master(comm_))
1826  {
1827  forAll(filePaths, proci)
1828  {
1829  if (!filePaths[proci].empty())
1830  {
1831  if (proci > 0 && filePaths[proci] == filePaths[proci-1])
1832  {
1833  result[proci] = result[proci-1];
1834  headerClassName[proci] = headerClassName[proci-1];
1835  note[proci] = note[proci-1];
1836  }
1837  else
1838  {
1839  IFstream is(filePaths[proci]);
1840 
1841  if (is.good())
1842  {
1843  result[proci] = io.readHeader(is);
1844  if
1845  (
1846  io.headerClassName()
1847  == decomposedBlockData::typeName
1848  )
1849  {
1850  // Read the header inside the container
1851  // (master data)
1852  result[proci] = decomposedBlockData::
1854  (
1855  io,
1856  is
1857  );
1858  }
1859  headerClassName[proci] = io.headerClassName();
1860  note[proci] = io.note();
1861  }
1862  }
1863  }
1864  }
1865  }
1866  ok = scatterList(result, Pstream::msgType(), comm_);
1867  io.headerClassName() = scatterList
1868  (
1869  headerClassName,
1870  Pstream::msgType(),
1871  comm_
1872  );
1873  io.note() = scatterList(note, Pstream::msgType(), comm_);
1874  }
1875 
1876  if (debug)
1877  {
1878  Pout<< "masterUncollatedFileOperation::readHeader :" << " ok:" << ok
1879  << " class:" << io.headerClassName() << endl;
1880  }
1881  return ok;
1882 }
1883 
1884 
1888  regIOobject& io,
1889  const fileName& fName,
1890  const word& typeName,
1891  const bool valid
1892 ) const
1893 {
1894  if (debug)
1895  {
1896  Pout<< "masterUncollatedFileOperation::readStream :"
1897  << " object : " << io.name()
1898  << " global : " << io.global()
1899  << " fName : " << fName << " valid:" << valid << endl;
1900  }
1901 
1902 
1903  autoPtr<ISstream> isPtr;
1904  bool isCollated = false;
1905  IOobject headerIO(io);
1906 
1907  // Detect collated format. This could be done on the local communicator
1908  // but we do it on the master node only for now.
1909  if (UPstream::master()) // comm_))
1910  {
1911  if (!fName.empty())
1912  {
1913  // This can happen in lagrangian field reading some processors
1914  // have no file to read from. This will only happen when using
1915  // normal writing since then the fName for the valid processors is
1916  // processorDDD/<instance>/.. . In case of collocated writing
1917  // the fName is already rewritten to processors/.
1918 
1919  isPtr.reset(new IFstream(fName));
1920 
1921  if (isPtr->good())
1922  {
1923  // Read header data (on copy)
1924  headerIO.readHeader(*isPtr);
1925 
1926  if (headerIO.headerClassName() == decomposedBlockData::typeName)
1927  {
1928  isCollated = true;
1929  }
1930  else if (!Pstream::parRun())
1931  {
1932  // Short circuit: non-collated format. No parallel bits.
1933  // Copy header and return.
1934  if (debug)
1935  {
1936  Pout<< "masterUncollatedFileOperation::readStream :"
1937  << " For object : " << io.name()
1938  << " doing straight IFstream input from "
1939  << fName << endl;
1940  }
1941  io = headerIO;
1942  return isPtr;
1943  }
1944  }
1945 
1946  if (!isCollated)
1947  {
1948  // Close file. Reopened below.
1949  isPtr.clear();
1950  }
1951  }
1952  }
1953 
1954  Pstream::scatter(isCollated); //, Pstream::msgType(), comm_);
1955 
1956  if (isCollated)
1957  {
1958  if (debug)
1959  {
1960  Pout<< "masterUncollatedFileOperation::readStream :"
1961  << " For object : " << io.name()
1962  << " starting collating input from " << fName << endl;
1963  }
1964 
1965 
1966  // Analyse the file path (on (co)master) to see the processors type
1967  fileName path, procDir, local;
1968  label groupStart, groupSize, nProcs;
1969  splitProcessorPath
1970  (
1971  fName,
1972  path,
1973  procDir,
1974  local,
1975  groupStart,
1976  groupSize,
1977  nProcs
1978  );
1979 
1980 
1981  if (!Pstream::parRun())
1982  {
1983  // Analyse the objectpath to find out the processor we're trying
1984  // to access
1985  label proci = detectProcessorPath(io.objectPath());
1986 
1987  if (proci == -1)
1988  {
1989  FatalIOErrorInFunction(*isPtr)
1990  << "Could not detect processor number"
1991  << " from objectPath:" << io.objectPath()
1992  << exit(FatalIOError);
1993  }
1994 
1995  // Analyse the fileName for any processor subset. Note: this
1996  // should really be part of filePath() which should return
1997  // both file and index in file.
1998  if (groupStart != -1 && groupSize > 0)
1999  {
2000  proci = proci-groupStart;
2001  }
2002 
2003  if (debug)
2004  {
2005  Pout<< "masterUncollatedFileOperation::readStream :"
2006  << " For object : " << io.name()
2007  << " starting input from block " << proci
2008  << " of " << isPtr->name() << endl;
2009  }
2010 
2011  return decomposedBlockData::readBlock(proci, *isPtr, io);
2012  }
2013  else
2014  {
2015  // Get size of file
2016  off_t sz = Foam::fileSize(fName);
2017  bool bigSize = sz > off_t(maxMasterFileBufferSize);
2018  Pstream::scatter(bigSize);
2019 
2020  // Are we reading from single-master file ('processors256') or
2021  // from multi-master files ('processors256_0-9')
2022  label readComm = -1;
2023  if (groupStart != -1 && groupSize > 0)
2024  {
2025  readComm = comm_;
2026  if (UPstream::master(comm_) && !isPtr && !fName.empty())
2027  {
2028  // In multi-master mode also open the file on the other
2029  // masters
2030  isPtr.reset(new IFstream(fName));
2031 
2032  if (isPtr->good())
2033  {
2034  // Read header data (on copy)
2035  IOobject headerIO(io);
2036  headerIO.readHeader(*isPtr);
2037  }
2038  }
2039  }
2040  else
2041  {
2042  // Single master so read on world
2043  readComm = Pstream::worldComm;
2044  }
2045 
2046  // Read my data
2048  (
2049  readComm,
2050  fName,
2051  isPtr,
2052  io,
2053  (
2054  bigSize
2057  )
2058  );
2059  }
2060  }
2061  else
2062  {
2063  if (debug)
2064  {
2065  Pout<< "masterUncollatedFileOperation::readStream :"
2066  << " For object : " << io.name()
2067  << " starting separated input from " << fName << endl;
2068  }
2069 
2070  if (io.global())
2071  {
2072  // Use worldComm. Note: should not really need to gather filePaths
2073  // since we enforce sending from master anyway ...
2074  fileNameList filePaths(Pstream::nProcs());
2075  filePaths[Pstream::myProcNo()] = fName;
2076  Pstream::gatherList(filePaths);
2077  boolList procValid(Pstream::nProcs());
2078  procValid[Pstream::myProcNo()] = valid;
2079  Pstream::gatherList(procValid);
2080 
2081  return read(io, Pstream::worldComm, true, filePaths, procValid);
2082  }
2083  else
2084  {
2085  // Use local communicator
2086  fileNameList filePaths(Pstream::nProcs(comm_));
2087  filePaths[Pstream::myProcNo(comm_)] = fName;
2088  Pstream::gatherList(filePaths, Pstream::msgType(), comm_);
2089  boolList procValid(Pstream::nProcs(comm_));
2090  procValid[Pstream::myProcNo(comm_)] = valid;
2091  Pstream::gatherList(procValid, Pstream::msgType(), comm_);
2092 
2093  // Uniform in local comm
2094  const bool uniform = uniformFile(filePaths);
2095 
2096  return read(io, comm_, uniform, filePaths, procValid);
2097  }
2098  }
2099 }
2100 
2101 
2104  regIOobject& io,
2105  const bool masterOnly,
2107  const word& typeName
2108 ) const
2109 {
2110  bool ok = true;
2111 
2112  if (io.globalObject())
2113  {
2114  if (debug)
2115  {
2116  Pout<< "masterUncollatedFileOperation::read :"
2117  << " Reading global object " << io.name() << endl;
2118  }
2119 
2120  bool ok = false;
2121  if (Pstream::master()) // comm_))
2122  {
2123  // Do master-only reading always.
2124  const bool oldParRun = UPstream::parRun();
2125  UPstream::parRun() = false;
2126 
2127  ok = io.readData(io.readStream(typeName));
2128  io.close();
2129 
2130  UPstream::parRun() = oldParRun;
2131  }
2132 
2133  Pstream::scatter(ok); //, Pstream::msgType(), comm_);
2134  Pstream::scatter(io.headerClassName()); //, Pstream::msgType(), comm_);
2135  Pstream::scatter(io.note()); //, Pstream::msgType(), comm_);
2136 
2137 
2138  // scatter operation for regIOobjects
2139 
2140  // Get my communication order
2141  // const List<Pstream::commsStruct>& comms =
2142  //(
2143  // (Pstream::nProcs(comm_) < Pstream::nProcsSimpleSum)
2144  // ? Pstream::linearCommunication(comm_)
2145  // : Pstream::treeCommunication(comm_)
2146  //);
2147  // const Pstream::commsStruct& myComm = comms[Pstream::myProcNo(comm_)];
2148  const List<Pstream::commsStruct>& comms =
2149  (
2153  );
2154  const Pstream::commsStruct& myComm =
2156 
2157  // Receive from up
2158  if (myComm.above() != -1)
2159  {
2160  IPstream fromAbove
2161  (
2163  myComm.above(),
2164  0,
2165  Pstream::msgType(),
2166  Pstream::worldComm, // comm_,
2167  format
2168  );
2169  ok = io.readData(fromAbove);
2170  }
2171 
2172  // Send to my downstairs neighbours
2173  forAll(myComm.below(), belowI)
2174  {
2175  OPstream toBelow
2176  (
2178  myComm.below()[belowI],
2179  0,
2180  Pstream::msgType(),
2181  Pstream::worldComm, // comm_,
2182  format
2183  );
2184  bool okWrite = io.writeData(toBelow);
2185  ok = ok && okWrite;
2186  }
2187  }
2188  else
2189  {
2190  if (debug)
2191  {
2192  Pout<< "masterUncollatedFileOperation::read :"
2193  << " Reading local object " << io.name() << endl;
2194  }
2195 
2196  ok = io.readData(io.readStream(typeName));
2197  io.close();
2198  }
2199 
2200  return ok;
2201 }
2202 
2203 
2206  const regIOobject& io,
2207  IOstreamOption streamOpt,
2208  const bool valid
2209 ) const
2210 {
2211  fileName pathName(io.objectPath());
2212 
2213  if (debug)
2214  {
2215  Pout<< "masterUncollatedFileOperation::writeObject :"
2216  << " io:" << pathName << " valid:" << valid << endl;
2217  }
2218 
2219  // Make sure to pick up any new times
2220  setTime(io.time());
2221 
2222  autoPtr<OSstream> osPtr(NewOFstream(pathName, streamOpt, valid));
2223  OSstream& os = osPtr();
2224 
2225  // If any of these fail, return (leave error handling to Ostream class)
2226  if (!os.good())
2227  {
2228  return false;
2229  }
2230 
2231  if (!io.writeHeader(os))
2232  {
2233  return false;
2234  }
2235 
2236  // Write the data to the Ostream
2237  if (!io.writeData(os))
2238  {
2239  return false;
2240  }
2241 
2243 
2244  return true;
2245 }
2246 
2247 
2250  const fileName& directory,
2251  const word& constantName
2252 ) const
2253 {
2254  const auto iter = times_.cfind(directory);
2255  if (iter.found())
2256  {
2257  if (debug)
2258  {
2259  Pout<< "masterUncollatedFileOperation::findTimes :"
2260  << " Found " << iter()->size() << " cached times" << endl;
2261  }
2262  return *iter();
2263  }
2264  else
2265  {
2266  instantList times;
2267  if (Pstream::master()) // comm_))
2268  {
2269  // Do master-only reading always.
2270  const bool oldParRun = UPstream::parRun();
2271  UPstream::parRun() = false;
2272  times = fileOperation::findTimes(directory, constantName);
2273  UPstream::parRun() = oldParRun;
2274  }
2275  Pstream::scatter(times); //, Pstream::msgType(), comm_);
2276 
2277  // Note: do we also cache if no times have been found since it might
2278  // indicate a directory that is being filled later on ...
2279 
2280  instantList* tPtr = new instantList(std::move(times));
2281 
2282  times_.set(directory, tPtr);
2283 
2284  if (debug)
2285  {
2286  Pout<< "masterUncollatedFileOperation::findTimes :"
2287  << " Caching times:" << *tPtr << nl
2288  << " for directory:" << directory << endl;
2289  }
2290  return *tPtr;
2291  }
2292 }
2293 
2294 
2297  const Time& tm
2298 ) const
2299 {
2300  if (tm.subCycling())
2301  {
2302  return;
2303  }
2304 
2305  // Mutable access to instantList for modification and sorting
2306  // - cannot use auto type deduction here
2307 
2308  HashPtrTable<instantList>::iterator iter = times_.find(tm.path());
2309 
2310  if (iter.found())
2311  {
2312  instantList& times = *iter();
2313 
2314  const instant timeNow(tm.value(), tm.timeName());
2315 
2316  // Exclude constant when checking and sorting
2317  const label skipConst =
2318  (
2319  (!times.empty() && times[0].name() == tm.constant())
2320  ? 1
2321  : 0
2322  );
2323 
2324  if
2325  (
2327  (
2328  SubList<instant>(times, times.size()-skipConst, skipConst),
2329  timeNow
2330  )
2331  == -1
2332  )
2333  {
2334  if (debug)
2335  {
2336  Pout<< "masterUncollatedFileOperation::setTime :"
2337  << " Caching time " << tm.timeName()
2338  << " for case:" << tm.path() << endl;
2339  }
2340 
2341  times.append(timeNow);
2342  SubList<instant> realTimes
2343  (
2344  times, times.size()-skipConst, skipConst
2345  );
2346  Foam::stableSort(realTimes);
2347  }
2348  }
2349 
2351 }
2352 
2353 
2357  const fileName& filePath
2358 ) const
2359 {
2360  autoPtr<ISstream> isPtr;
2361 
2362  if (Pstream::parRun())
2363  {
2364  // Insert logic of filePath. We assume that if a file is absolute
2365  // on the master it is absolute also on the slaves etc.
2366 
2368  filePaths[Pstream::myProcNo(Pstream::worldComm)] = filePath;
2370 
2371  PstreamBuffers pBufs
2372  (
2374  Pstream::msgType(),
2376  );
2377 
2379  {
2380  const bool uniform = uniformFile(filePaths);
2381 
2382  if (uniform)
2383  {
2384  if (debug)
2385  {
2386  Pout<< "masterUncollatedFileOperation::NewIFstream :"
2387  << " Opening global file " << filePath << endl;
2388  }
2389 
2390  readAndSend
2391  (
2392  filePath,
2394  pBufs
2395  );
2396  }
2397  else
2398  {
2399  for
2400  (
2401  label proci = 1;
2403  proci++
2404  )
2405  {
2406  readAndSend
2407  (
2408  filePaths[proci],
2409  labelList(1, proci),
2410  pBufs
2411  );
2412  }
2413  }
2414  }
2415 
2416 
2417  labelList recvSizes;
2418  pBufs.finishedSends(recvSizes);
2419 
2421  {
2422  // Read myself
2423  isPtr.reset(new IFstream(filePaths[Pstream::masterNo()]));
2424  }
2425  else
2426  {
2427  if (debug)
2428  {
2429  Pout<< "masterUncollatedFileOperation::NewIFstream :"
2430  << " Reading " << filePath
2431  << " from processor " << Pstream::masterNo() << endl;
2432  }
2433 
2434  UIPstream is(Pstream::masterNo(), pBufs);
2435 
2436  List<char> buf(recvSizes[Pstream::masterNo()]);
2437  is.read(buf.data(), buf.size());
2438 
2439  if (debug)
2440  {
2441  Pout<< "masterUncollatedFileOperation::NewIFstream :"
2442  << " Done reading " << buf.size() << " bytes" << endl;
2443  }
2444 
2445  // A local character buffer copy of the Pstream contents.
2446  // Construct with same parameters (ASCII, current version)
2447  // as the IFstream so that it has the same characteristics.
2448 
2449  isPtr.reset(new IListStream(std::move(buf)));
2450 
2451  // With the proper file name
2452  isPtr->name() = filePath;
2453  }
2454  }
2455  else
2456  {
2457  // Read myself
2458  isPtr.reset(new IFstream(filePath));
2459  }
2460 
2461  return isPtr;
2462 }
2463 
2464 
2468  const fileName& pathName,
2469  IOstreamOption streamOpt,
2470  const bool valid
2471 ) const
2472 {
2473  return autoPtr<OSstream>
2474  (
2475  new masterOFstream
2476  (
2477  pathName,
2478  streamOpt,
2479  false, // append=false
2480  valid
2481  )
2482  );
2483 }
2484 
2485 
2487 {
2489  times_.clear();
2490 }
2491 
2492 
2495  const fileName& fName
2496 ) const
2497 {
2498  label watchFd = -1;
2499  if (Pstream::master()) // comm_))
2500  {
2501  watchFd = monitor().addWatch(fName);
2502  }
2503  Pstream::scatter(watchFd); //, Pstream::msgType(), comm_);
2504  return watchFd;
2505 }
2506 
2507 
2510  const label watchIndex
2511 ) const
2512 {
2513  bool ok = false;
2514  if (Pstream::master()) // comm_))
2515  {
2516  ok = monitor().removeWatch(watchIndex);
2517  }
2518  Pstream::scatter(ok); //, Pstream::msgType(), comm_);
2519  return ok;
2520 }
2521 
2522 
2525  const labelList& watchIndices,
2526  const fileName& fName
2527 ) const
2528 {
2529  label index = -1;
2530 
2531  if (Pstream::master()) // comm_))
2532  {
2533  forAll(watchIndices, i)
2534  {
2535  if (monitor().getFile(watchIndices[i]) == fName)
2536  {
2537  index = i;
2538  break;
2539  }
2540  }
2541  }
2542  Pstream::scatter(index); //, Pstream::msgType(), comm_);
2543  return index;
2544 }
2545 
2546 
2549  regIOobject& rio,
2550  const fileNameList& files
2551 ) const
2552 {
2553  const labelList& watchIndices = rio.watchIndices();
2554 
2555  DynamicList<label> newWatchIndices;
2556  labelHashSet removedWatches(watchIndices);
2557 
2558  for (const fileName& f : files)
2559  {
2560  const label index = findWatch(watchIndices, f);
2561 
2562  if (index == -1)
2563  {
2564  newWatchIndices.append(addWatch(f));
2565  }
2566  else
2567  {
2568  // Existing watch
2569  newWatchIndices.append(watchIndices[index]);
2570  removedWatches.erase(index);
2571  }
2572  }
2573 
2574  // Remove any unused watches
2575  for (const label index : removedWatches)
2576  {
2577  removeWatch(watchIndices[index]);
2578  }
2579 
2580  rio.watchIndices() = newWatchIndices;
2581 }
2582 
2583 
2586  const label watchIndex
2587 ) const
2588 {
2589  fileName fName;
2590  if (Pstream::master()) // comm_))
2591  {
2592  fName = monitor().getFile(watchIndex);
2593  }
2594  Pstream::scatter(fName); //, Pstream::msgType(), comm_);
2595  return fName;
2596 }
2597 
2598 
2601  const bool masterOnly,
2602  const bool syncPar
2603 ) const
2604 {
2605  if (Pstream::master()) // comm_))
2606  {
2607  monitor().updateStates(true, false);
2608  }
2609 }
2610 
2611 
2615  const label watchFd
2616 ) const
2617 {
2618  unsigned int state = fileMonitor::UNMODIFIED;
2619  if (Pstream::master()) // comm_))
2620  {
2621  state = monitor().getState(watchFd);
2622  }
2623  Pstream::scatter(state); //, Pstream::msgType(), comm_);
2624  return fileMonitor::fileState(state);
2625 }
2626 
2627 
2630  const label watchFd
2631 ) const
2632 {
2633  if (Pstream::master()) // comm_))
2634  {
2635  monitor().setUnmodified(watchFd);
2636  }
2637 }
2638 
2639 
2640 // ************************************************************************* //
Foam::fileOperations::masterUncollatedFileOperation::setUnmodified
virtual void setUnmodified(const label) const
Set current state of file (using handle) to unmodified.
Definition: masterUncollatedFileOperation.C:2629
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:922
Foam::fileOperations::masterUncollatedFileOperation::getFile
virtual fileName getFile(const label) const
Get name of file being watched (using handle)
Definition: masterUncollatedFileOperation.C:2585
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:1104
Foam::UPstream::commsTypes::nonBlocking
Foam::fileOperations::masterUncollatedFileOperation::setTime
virtual void setTime(const Time &) const
Callback for time change.
Definition: masterUncollatedFileOperation.C:2296
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:495
Foam::UPstream::masterNo
static constexpr int masterNo() noexcept
Process index of the master.
Definition: UPstream.H:433
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:1302
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: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:1086
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:155
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:85
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: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:455
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:906
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:427
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:107
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:415
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:974
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:785
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:977
Foam::fileOperations::masterUncollatedFileOperation::fileSize
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
Definition: masterUncollatedFileOperation.C:991
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:336
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:1139
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:890
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:449
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:830
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:666
Foam::fileOperations::masterUncollatedFileOperation::~masterUncollatedFileOperation
virtual ~masterUncollatedFileOperation()
Destructor.
Definition: masterUncollatedFileOperation.C:862
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:443
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:521
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:1887
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:568
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:436
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::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:1157
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::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: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:513
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:1007
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:2205
Foam::IOobject::caseName
const fileName & caseName() const
Definition: IOobject.C:461
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:2524
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:1426
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:1023
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:2509
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:733
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:2600
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:1070
Foam::fileOperations::masterUncollatedFileOperation::mvBak
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
Definition: masterUncollatedFileOperation.C:1039
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:1675
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:874
Foam::IOobject::headerClassName
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobjectI.H:88
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:445
Foam::fileOperations::masterUncollatedFileOperation::getState
virtual fileMonitor::fileState getState(const label) const
Get current state of file (using handle)
Definition: masterUncollatedFileOperation.C:2614
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:439
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:117
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:68
Foam::fileOperations::masterUncollatedFileOperation::flush
virtual void flush() const
Forcibly wait until all output done. Flush any cached data.
Definition: masterUncollatedFileOperation.C:2486
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:492
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:372
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::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:2494
Foam::fileOperations::masterUncollatedFileOperation::rm
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
Definition: masterUncollatedFileOperation.C:1055
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:87
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: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:2356
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:871
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:1762
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:958
Foam::autoPtr::clear
void clear() noexcept
Same as reset(nullptr)
Definition: autoPtr.H:178
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:335
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:392
registerSwitch.H
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
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:2467
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:475
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:2249
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:1122
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:467
Foam::fileOperations::masterUncollatedFileOperation::addWatches
virtual void addWatches(regIOobject &, const fileNameList &) const
Helper: add watches for list of regIOobjects.
Definition: masterUncollatedFileOperation.C:2548
Foam::fileOperations::masterUncollatedFileOperation::mkDirOp
Definition: masterUncollatedFileOperation.H:102
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:298
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::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: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:484
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:1475