decomposedBlockData.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2017-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "decomposedBlockData.H"
27 #include "OPstream.H"
28 #include "IPstream.H"
29 #include "PstreamBuffers.H"
30 #include "OFstream.H"
31 #include "IFstream.H"
32 #include "IStringStream.H"
33 #include "dictionary.H"
34 #include "objectRegistry.H"
35 #include "SubList.H"
36 #include "labelPair.H"
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
44 }
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 (
50  const label comm,
51  const IOobject& io,
52  const UPstream::commsTypes commsType
53 )
54 :
55  regIOobject(io),
56  commsType_(commsType),
57  comm_(comm)
58 {
59  // Temporary warning
61  {
63  << "decomposedBlockData " << name()
64  << " constructed with IOobject::MUST_READ_IF_MODIFIED"
65  " but decomposedBlockData does not support automatic rereading."
66  << endl;
67  }
68  if
69  (
70  (
73  )
75  )
76  {
77  read();
78  }
79 }
80 
81 
83 (
84  const label comm,
85  const IOobject& io,
86  const UList<char>& list,
87  const UPstream::commsTypes commsType
88 )
89 :
90  regIOobject(io),
91  commsType_(commsType),
92  comm_(comm)
93 {
94  // Temporary warning
96  {
98  << "decomposedBlockData " << name()
99  << " constructed with IOobject::MUST_READ_IF_MODIFIED"
100  " but decomposedBlockData does not support automatic rereading."
101  << endl;
102  }
103 
104  if
105  (
106  (
109  )
110  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
111  )
112  {
113  read();
114  }
115  else
116  {
117  List<char>::operator=(list);
118  }
119 }
120 
121 
123 (
124  const label comm,
125  const IOobject& io,
126  List<char>&& list,
127  const UPstream::commsTypes commsType
128 )
129 :
130  regIOobject(io),
131  List<char>(move(list)),
132  commsType_(commsType),
133  comm_(comm)
134 {
135  // Temporary warning
137  {
139  << "decomposedBlockData " << name()
140  << " constructed with IOobject::MUST_READ_IF_MODIFIED"
141  " but decomposedBlockData does not support automatic rereading."
142  << endl;
143  }
144 
145  if
146  (
147  (
150  )
151  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
152  )
153  {
154  read();
155  }
156 }
157 
158 
159 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
160 
162 {}
163 
164 
165 // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
166 
168 {
169  if (debug)
170  {
171  Pout<< "decomposedBlockData::readMasterHeader:"
172  << " stream:" << is.name() << endl;
173  }
174 
175  // Master-only reading of header
176  is.fatalCheck("read(Istream&)");
177 
178  List<char> data(is);
179  is.fatalCheck("read(Istream&) : reading entry");
180  string buf(data.begin(), data.size());
181  IStringStream str(is.name(), buf);
182 
183  return io.readHeader(str);
184 }
185 
186 
188 (
189  const label blocki,
190  Istream& is,
191  IOobject& headerIO
192 )
193 {
194  if (debug)
195  {
196  Pout<< "decomposedBlockData::readBlock:"
197  << " stream:" << is.name() << " attempt to read block " << blocki
198  << endl;
199  }
200 
201  is.fatalCheck("read(Istream&)");
202 
203  List<char> data;
204  autoPtr<ISstream> realIsPtr;
205 
206  if (blocki == 0)
207  {
208  is >> data;
209  is.fatalCheck("read(Istream&) : reading entry");
210 
211  string buf(data.begin(), data.size());
212  realIsPtr = new IStringStream(is.name(), buf);
213 
214  // Read header
215  if (!headerIO.readHeader(realIsPtr()))
216  {
217  FatalIOErrorInFunction(realIsPtr())
218  << "problem while reading header for object "
219  << is.name() << exit(FatalIOError);
220  }
221  }
222  else
223  {
224  // Read master for header
225  is >> data;
226  is.fatalCheck("read(Istream&) : reading entry");
227 
230  {
231  string buf(data.begin(), data.size());
232  IStringStream headerStream(is.name(), buf);
233 
234  // Read header
235  if (!headerIO.readHeader(headerStream))
236  {
237  FatalIOErrorInFunction(headerStream)
238  << "problem while reading header for object "
239  << is.name() << exit(FatalIOError);
240  }
241  ver = headerStream.version();
242  fmt = headerStream.format();
243  }
244 
245  for (label i = 1; i < blocki+1; i++)
246  {
247  // Read data, override old data
248  is >> data;
249  is.fatalCheck("read(Istream&) : reading entry");
250  }
251  string buf(data.begin(), data.size());
252  realIsPtr = new IStringStream(is.name(), buf);
253 
254  // Apply master stream settings to realIsPtr
255  realIsPtr().format(fmt);
256  realIsPtr().version(ver);
257  }
258  return realIsPtr;
259 }
260 
261 
263 (
264  const label comm,
265  autoPtr<ISstream>& isPtr,
266  List<char>& data,
267  const UPstream::commsTypes commsType
268 )
269 {
270  if (debug)
271  {
272  Pout<< "decomposedBlockData::readBlocks:"
273  << " stream:" << (isPtr.valid() ? isPtr().name() : "invalid")
274  << " commsType:" << Pstream::commsTypeNames[commsType]
275  << " comm:" << comm << endl;
276  }
277 
278  bool ok = false;
279 
280  if (commsType == UPstream::commsTypes::scheduled)
281  {
282  if (UPstream::master(comm))
283  {
284  Istream& is = isPtr();
285  is.fatalCheck("read(Istream&)");
286 
287  // Read master data
288  {
289  is >> data;
290  is.fatalCheck("read(Istream&) : reading entry");
291  }
292 
293  // Read slave data
294  for
295  (
296  label proci = 1;
297  proci < UPstream::nProcs(comm);
298  proci++
299  )
300  {
301  List<char> elems(is);
302  is.fatalCheck("read(Istream&) : reading entry");
303 
304  OPstream os
305  (
307  proci,
308  0,
310  comm
311  );
312  os << elems;
313  }
314 
315  ok = is.good();
316  }
317  else
318  {
319  IPstream is
320  (
323  0,
325  comm
326  );
327  is >> data;
328  }
329  }
330  else
331  {
332  PstreamBuffers pBufs
333  (
336  comm
337  );
338 
339  if (UPstream::master(comm))
340  {
341  Istream& is = isPtr();
342  is.fatalCheck("read(Istream&)");
343 
344  // Read master data
345  {
346  is >> data;
347  is.fatalCheck("read(Istream&) : reading entry");
348  }
349 
350  // Read slave data
351  for
352  (
353  label proci = 1;
354  proci < UPstream::nProcs(comm);
355  proci++
356  )
357  {
358  List<char> elems(is);
359  is.fatalCheck("read(Istream&) : reading entry");
360 
361  UOPstream os(proci, pBufs);
362  os << elems;
363  }
364  }
365 
366  labelList recvSizes;
367  pBufs.finishedSends(recvSizes);
368 
369  if (!UPstream::master(comm))
370  {
371  UIPstream is(UPstream::masterNo(), pBufs);
372  is >> data;
373  }
374  }
375 
376  Pstream::scatter(ok, Pstream::msgType(), comm);
377 
378  return ok;
379 }
380 
381 
383 (
384  const label comm,
385  const fileName& fName,
386  autoPtr<ISstream>& isPtr,
387  IOobject& headerIO,
388  const UPstream::commsTypes commsType
389 )
390 {
391  if (debug)
392  {
393  Pout<< "decomposedBlockData::readBlocks:"
394  << " stream:" << (isPtr.valid() ? isPtr().name() : "invalid")
395  << " commsType:" << Pstream::commsTypeNames[commsType] << endl;
396  }
397 
398  bool ok = false;
399 
400  List<char> data;
401  autoPtr<ISstream> realIsPtr;
402 
403  if (commsType == UPstream::commsTypes::scheduled)
404  {
405  if (UPstream::master(comm))
406  {
407  Istream& is = isPtr();
408  is.fatalCheck("read(Istream&)");
409 
410  // Read master data
411  {
412  is >> data;
413  is.fatalCheck("read(Istream&) : reading entry");
414 
415  string buf(data.begin(), data.size());
416  realIsPtr = new IStringStream(fName, buf);
417 
418  // Read header
419  if (!headerIO.readHeader(realIsPtr()))
420  {
421  FatalIOErrorInFunction(realIsPtr())
422  << "problem while reading header for object "
423  << is.name() << exit(FatalIOError);
424  }
425  }
426 
427  // Read slave data
428  for
429  (
430  label proci = 1;
431  proci < UPstream::nProcs(comm);
432  proci++
433  )
434  {
435  is >> data;
436  is.fatalCheck("read(Istream&) : reading entry");
437 
438  OPstream os
439  (
441  proci,
442  0,
444  comm
445  );
446  os << data;
447  }
448 
449  ok = is.good();
450  }
451  else
452  {
453  IPstream is
454  (
457  0,
459  comm
460  );
461  is >> data;
462 
463  string buf(data.begin(), data.size());
464  realIsPtr = new IStringStream(fName, buf);
465  }
466  }
467  else
468  {
469  PstreamBuffers pBufs
470  (
473  comm
474  );
475 
476  if (UPstream::master(comm))
477  {
478  Istream& is = isPtr();
479  is.fatalCheck("read(Istream&)");
480 
481  // Read master data
482  {
483  is >> data;
484  is.fatalCheck("read(Istream&) : reading entry");
485 
486  string buf(data.begin(), data.size());
487  realIsPtr = new IStringStream(fName, buf);
488 
489  // Read header
490  if (!headerIO.readHeader(realIsPtr()))
491  {
492  FatalIOErrorInFunction(realIsPtr())
493  << "problem while reading header for object "
494  << is.name() << exit(FatalIOError);
495  }
496  }
497 
498  // Read slave data
499  for
500  (
501  label proci = 1;
502  proci < UPstream::nProcs(comm);
503  proci++
504  )
505  {
506  List<char> elems(is);
507  is.fatalCheck("read(Istream&) : reading entry");
508 
509  UOPstream os(proci, pBufs);
510  os << elems;
511  }
512 
513  ok = is.good();
514  }
515 
516  labelList recvSizes;
517  pBufs.finishedSends(recvSizes);
518 
519  if (!UPstream::master(comm))
520  {
521  UIPstream is(UPstream::masterNo(), pBufs);
522  is >> data;
523 
524  string buf(data.begin(), data.size());
525  realIsPtr = new IStringStream(fName, buf);
526  }
527  }
528 
529  Pstream::scatter(ok, Pstream::msgType(), comm);
530 
531  // version
532  string versionString(realIsPtr().version().str());
533  Pstream::scatter(versionString, Pstream::msgType(), comm);
534  realIsPtr().version(IStringStream(versionString)());
535 
536  // stream
537  {
538  OStringStream os;
539  os << realIsPtr().format();
540  string formatString(os.str());
541  Pstream::scatter(formatString, Pstream::msgType(), comm);
542  realIsPtr().format(formatString);
543  }
544 
545  word name(headerIO.name());
547  headerIO.rename(name);
549  Pstream::scatter(headerIO.note(), Pstream::msgType(), comm);
550  // Pstream::scatter(headerIO.instance(), Pstream::msgType(), comm);
551  // Pstream::scatter(headerIO.local(), Pstream::msgType(), comm);
552 
553  return realIsPtr;
554 }
555 
556 
558 (
559  const label comm,
560  const label data,
561  labelList& datas
562 )
563 {
564  const label nProcs = UPstream::nProcs(comm);
565  datas.setSize(nProcs);
566 
567  char* data0Ptr = reinterpret_cast<char*>(datas.begin());
568 
569  List<int> recvOffsets;
570  List<int> recvSizes;
571  if (UPstream::master(comm))
572  {
573  recvOffsets.setSize(nProcs);
574  forAll(recvOffsets, proci)
575  {
576  // Note: truncating long int to int since UPstream::gather limited
577  // to ints
578  recvOffsets[proci] =
579  int(reinterpret_cast<char*>(&datas[proci]) - data0Ptr);
580  }
581  recvSizes.setSize(nProcs, sizeof(label));
582  }
583 
585  (
586  reinterpret_cast<const char*>(&data),
587  sizeof(label),
588  data0Ptr,
589  recvSizes,
590  recvOffsets,
591  comm
592  );
593 }
594 
595 
597 (
598  const label comm,
599  const UList<char>& data,
600  const labelUList& recvSizes,
601 
602  const label startProc,
603  const label nProcs,
604 
605  List<int>& sliceOffsets,
606  List<char>& recvData
607 )
608 {
609  // Calculate master data
610  List<int> sliceSizes;
611  if (UPstream::master(comm))
612  {
613  const label numProcs = UPstream::nProcs(comm);
614 
615  sliceSizes.setSize(numProcs, 0);
616  sliceOffsets.setSize(numProcs+1, 0);
617 
618  int totalSize = 0;
619  label proci = startProc;
620  for (label i = 0; i < nProcs; i++)
621  {
622  sliceSizes[proci] = int(recvSizes[proci]);
623  sliceOffsets[proci] = totalSize;
624  totalSize += sliceSizes[proci];
625  proci++;
626  }
627  sliceOffsets[proci] = totalSize;
628  recvData.setSize(totalSize);
629  }
630 
631  int nSend = 0;
632  if
633  (
634  !UPstream::master(comm)
635  && (UPstream::myProcNo(comm) >= startProc)
636  && (UPstream::myProcNo(comm) < startProc+nProcs)
637  )
638  {
639  // Note: UPstream::gather limited to int
640  nSend = int(data.byteSize());
641  }
642 
644  (
645  data.begin(),
646  nSend,
647 
648  recvData.begin(),
649  sliceSizes,
650  sliceOffsets,
651  comm
652  );
653 }
654 
655 
657 (
658  const label comm,
659  const off_t maxBufferSize,
660  const labelUList& recvSizes,
661  const label startProci
662 )
663 {
664  const label nProcs = UPstream::nProcs(comm);
665 
666  label nSendProcs = -1;
667  if (UPstream::master(comm))
668  {
669  off_t totalSize = recvSizes[startProci];
670  label proci = startProci+1;
671  while (proci < nProcs && (totalSize+recvSizes[proci] < maxBufferSize))
672  {
673  totalSize += recvSizes[proci];
674  proci++;
675  }
676 
677  nSendProcs = proci-startProci;
678  }
679 
680  // Scatter nSendProcs
681  label n;
683  (
684  reinterpret_cast<const char*>(&nSendProcs),
685  List<int>(nProcs, sizeof(nSendProcs)),
686  List<int>(nProcs, 0),
687  reinterpret_cast<char*>(&n),
688  sizeof(n),
689  comm
690  );
691 
692  return n;
693 }
694 
695 
697 (
698  const label comm,
699  autoPtr<OSstream>& osPtr,
700  List<std::streamoff>& start,
701  const UList<char>& data,
702 
703  const labelUList& recvSizes,
704  const PtrList<SubList<char>>& slaveData,
705 
706  const UPstream::commsTypes commsType,
707  const bool syncReturnState
708 )
709 {
710  if (debug)
711  {
712  Pout<< "decomposedBlockData::writeBlocks:"
713  << " stream:" << (osPtr.valid() ? osPtr().name() : "invalid")
714  << " data:" << data.size()
715  << " (master only) slaveData:" << slaveData.size()
716  << " commsType:" << Pstream::commsTypeNames[commsType] << endl;
717  }
718 
719  const label nProcs = UPstream::nProcs(comm);
720 
721  bool ok = true;
722 
723  if (slaveData.size())
724  {
725  // Already have gathered the slave data. communicator only used to
726  // check who is the master
727 
728  if (UPstream::master(comm))
729  {
730  OSstream& os = osPtr();
731 
732  start.setSize(nProcs);
733 
734  // Write master data
735  {
736  os << nl << "// Processor" << UPstream::masterNo() << nl;
737  start[UPstream::masterNo()] = os.stdStream().tellp();
738  os << data;
739  }
740 
741  // Write slaves
742  for (label proci = 1; proci < nProcs; proci++)
743  {
744  os << nl << nl << "// Processor" << proci << nl;
745  start[proci] = os.stdStream().tellp();
746 
747  os << slaveData[proci];
748  }
749 
750  ok = os.good();
751  }
752  }
753  else if (commsType == UPstream::commsTypes::scheduled)
754  {
755  if (UPstream::master(comm))
756  {
757  start.setSize(nProcs);
758 
759  OSstream& os = osPtr();
760 
761  // Write master data
762  {
763  os << nl << "// Processor" << UPstream::masterNo() << nl;
764  start[UPstream::masterNo()] = os.stdStream().tellp();
765  os << data;
766  }
767  // Write slaves
768  List<char> elems;
769  for (label proci = 1; proci < nProcs; proci++)
770  {
771  elems.setSize(recvSizes[proci]);
773  (
775  proci,
776  elems.begin(),
777  elems.size(),
779  comm
780  );
781 
782  os << nl << nl << "// Processor" << proci << nl;
783  start[proci] = os.stdStream().tellp();
784  os << elems;
785  }
786 
787  ok = os.good();
788  }
789  else
790  {
792  (
795  data.begin(),
796  data.byteSize(),
798  comm
799  );
800  }
801  }
802  else
803  {
804  // Write master data
805  if (UPstream::master(comm))
806  {
807  start.setSize(nProcs);
808 
809  OSstream& os = osPtr();
810 
811  os << nl << "// Processor" << UPstream::masterNo() << nl;
812  start[UPstream::masterNo()] = os.stdStream().tellp();
813  os << data;
814  }
815 
816 
817  // Find out how many processor can be received into
818  // maxMasterFileBufferSize
819 
820  // Starting slave processor and number of processors
821  label startProc = 1;
822  label nSendProcs = nProcs-1;
823 
824  while (nSendProcs > 0 && startProc < nProcs)
825  {
826  nSendProcs = calcNumProcs
827  (
828  comm,
829  off_t
830  (
832  maxMasterFileBufferSize
833  ),
834  recvSizes,
835  startProc
836  );
837 
838  if (nSendProcs == 0)
839  {
840  break;
841  }
842 
843 
844  // Gather data from (a slice of) the slaves
845  List<int> sliceOffsets;
846  List<char> recvData;
847  gatherSlaveData
848  (
849  comm,
850  data,
851  recvSizes,
852 
853  startProc, // startProc,
854  nSendProcs, // nProcs,
855 
856  sliceOffsets,
857  recvData
858  );
859 
860  if (UPstream::master(comm))
861  {
862  OSstream& os = osPtr();
863 
864  // Write slaves
865  for
866  (
867  label proci = startProc;
868  proci < startProc+nSendProcs;
869  proci++
870  )
871  {
872  os << nl << nl << "// Processor" << proci << nl;
873  start[proci] = os.stdStream().tellp();
874 
875  os <<
877  (
878  recvData,
879  sliceOffsets[proci+1]-sliceOffsets[proci],
880  sliceOffsets[proci]
881  );
882  }
883  }
884 
885  startProc += nSendProcs;
886  }
887 
888  if (UPstream::master(comm))
889  {
890  ok = osPtr().good();
891  }
892  }
893 
894  if (syncReturnState)
895  {
896  //- Enable to get synchronised error checking. Is the one that keeps
897  // slaves as slow as the master (which does all the writing)
898  Pstream::scatter(ok, Pstream::msgType(), comm);
899  }
900 
901  return ok;
902 }
903 
904 
906 {
907  autoPtr<ISstream> isPtr;
908  fileName objPath(fileHandler().filePath(false, *this));
909  if (UPstream::master(comm_))
910  {
911  isPtr.reset(new IFstream(objPath));
912  IOobject::readHeader(isPtr());
913  }
914 
915  List<char>& data = *this;
916  return readBlocks(comm_, isPtr, data, commsType_);
917 }
918 
919 
921 {
922  const List<char>& data = *this;
923 
924  string str
925  (
926  reinterpret_cast<const char*>(data.cbegin()),
927  data.byteSize()
928  );
929 
930  IOobject io(*this);
931  if (Pstream::master(comm_))
932  {
933  IStringStream is(name(), str);
934  io.readHeader(is);
935  }
936 
937  // Scatter header information
938 
939  // version
940  string versionString(os.version().str());
941  Pstream::scatter(versionString, Pstream::msgType(), comm_);
942 
943  // stream
944  string formatString;
945  {
946  OStringStream os;
947  os << os.format();
948  formatString = os.str();
949  Pstream::scatter(formatString, Pstream::msgType(), comm_);
950  }
951 
952  // word masterName(name());
953  // Pstream::scatter(masterName, Pstream::msgType(), comm_);
954 
956  Pstream::scatter(io.note(), Pstream::msgType(), comm_);
957  // Pstream::scatter(io.instance(), Pstream::msgType(), comm);
958  // Pstream::scatter(io.local(), Pstream::msgType(), comm);
959 
960  fileName masterLocation(instance()/db().dbDir()/local());
961  Pstream::scatter(masterLocation, Pstream::msgType(), comm_);
962 
963  if (!Pstream::master(comm_))
964  {
966  (
967  os,
968  IOstream::versionNumber(IStringStream(versionString)()),
969  IOstream::formatEnum(formatString),
970  io.headerClassName(),
971  io.note(),
972  masterLocation,
973  name()
974  );
975  }
976 
977  os.writeQuoted(str, false);
978 
979  if (!Pstream::master(comm_))
980  {
982  }
983 
984  return os.good();
985 }
986 
987 
989 (
993  const bool write
994 ) const
995 {
996  autoPtr<OSstream> osPtr;
997  if (UPstream::master(comm_))
998  {
999  // Note: always write binary. These are strings so readable
1000  // anyway. They have already be tokenised on the sending side.
1001  osPtr.reset(new OFstream(objectPath(), IOstream::BINARY, ver, cmp));
1002  IOobject::writeHeader(osPtr());
1003  }
1004 
1005  labelList recvSizes;
1006  gather(comm_, label(this->byteSize()), recvSizes);
1007 
1008  List<std::streamoff> start;
1009  PtrList<SubList<char>> slaveData; // dummy slave data
1010  return writeBlocks
1011  (
1012  comm_,
1013  osPtr,
1014  start,
1015  *this,
1016  recvSizes,
1017  slaveData,
1018  commsType_
1019  );
1020 }
1021 
1022 
1024 {
1025  label nBlocks = 0;
1026 
1027  IFstream is(fName);
1028  is.fatalCheck("decomposedBlockData::numBlocks(const fileName&)");
1029 
1030  if (!is.good())
1031  {
1032  return nBlocks;
1033  }
1034 
1035  // Skip header
1036  token firstToken(is);
1037 
1038  if
1039  (
1040  is.good()
1041  && firstToken.isWord()
1042  && firstToken.wordToken() == IOobject::foamFile
1043  )
1044  {
1045  dictionary headerDict(is);
1046  is.version(headerDict.lookup("version"));
1047  is.format(headerDict.lookup("format"));
1048  }
1049 
1050  List<char> data;
1051  while (is.good())
1052  {
1053  token sizeToken(is);
1054  if (!sizeToken.isLabel())
1055  {
1056  return nBlocks;
1057  }
1058  is.putBack(sizeToken);
1059 
1060  is >> data;
1061  nBlocks++;
1062  }
1063 
1064  return nBlocks;
1065 }
1066 
1067 
1068 // ************************************************************************* //
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Input from file stream.
Definition: IFstream.H:85
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:119
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
Definition: IOobjectI.H:103
string & note()
Return non-constant access to the optional note.
Definition: IOobject.H:325
readOption readOpt() const
Definition: IOobject.H:357
static constexpr const char * foamFile
Keyword for the FoamFile header sub-dictionary.
Definition: IOobject.H:104
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobject.H:313
virtual void rename(const word &newName)
Rename.
Definition: IOobject.H:337
bool readHeader(Istream &)
Read header.
const word & name() const
Return name.
Definition: IOobject.H:307
static bool writeHeader(Ostream &os, const IOstream::versionNumber version, const IOstream::streamFormat format, const word &type, const string &note, const fileName &location, const word &name)
Write header.
Version number type.
Definition: IOstream.H:97
string str() const
Return the versionNumber as a character string.
Definition: IOstream.C:132
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:297
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:121
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
static streamFormat formatEnum(const word &)
Return stream format of given format name.
Definition: IOstream.C:39
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Input inter-processor communications stream.
Definition: IPstream.H:54
Input from memory buffer stream.
Definition: IStringStream.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
bool good() const
Return true if next operation might succeed.
Definition: Istream.H:101
void putBack(const token &)
Put back token.
Definition: Istream.C:30
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void operator=(const UList< T > &)
Assignment to UList operator. Takes linear time.
Definition: List.C:376
void setSize(const label)
Reset size of List.
Definition: List.C:281
Output to file stream.
Definition: OFstream.H:87
Output inter-processor communications stream.
Definition: OPstream.H:54
Generic output stream.
Definition: OSstream.H:54
virtual ostream & stdStream()
Access to underlying std::ostream.
Definition: OSstream.H:183
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)=0
Write std::string surrounded by quotes.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
A List obtained as a section of another List.
Definition: SubList.H:56
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:57
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:80
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
const_iterator cbegin() const
Return const_iterator to begin traversing the constant UList.
Definition: UListI.H:232
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
std::streamsize byteSize() const
Return the binary size in number of characters of the UList.
Definition: UList.C:100
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:58
virtual Ostream & write(const token &)
Write token.
Definition: Ostream.C:51
commsTypes
Types of communications.
Definition: UPstream.H:65
static int masterNo()
Process index of the master.
Definition: UPstream.H:417
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
static const NamedEnum< commsTypes, 3 > commsTypeNames
Definition: UPstream.H:71
static void gather(const char *sendData, int sendSize, char *recvData, const UList< int > &recvSizes, const UList< int > &recvOffsets, const label communicator=0)
Receive data from all processors on the master.
Definition: UPstream.C:96
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
static void scatter(const char *sendData, const UList< int > &sendSizes, const UList< int > &sendOffsets, char *recvData, int recvSize, const label communicator=0)
Send data to all processors from the root of the communicator.
Definition: UPstream.C:111
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:476
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
Definition: autoPtrI.H:83
void reset(T *=nullptr)
If object pointer already set, delete object and set to given.
Definition: autoPtrI.H:114
decomposedBlockData is a List<char> with IO on the master processor only.
static bool writeBlocks(const label comm, autoPtr< OSstream > &osPtr, List< std::streamoff > &start, const UList< char > &masterData, const labelUList &recvSizes, const PtrList< SubList< char >> &slaveData, const UPstream::commsTypes, const bool syncReturnState=true)
Write *this. Ostream only valid on master. Returns starts of.
static void gatherSlaveData(const label comm, const UList< char > &data, const labelUList &recvSizes, const label startProc, const label nProcs, List< int > &recvOffsets, List< char > &recvData)
Helper: gather data from (subset of) slaves. Returns.
virtual bool writeData(Ostream &) const
Write separated content. Assumes content is the serialised data.
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
Write using given format, version and compression.
static void gather(const label comm, const label data, labelList &datas)
Helper: gather single label. Note: using native Pstream.
static label numBlocks(const fileName &)
Detect number of blocks in a file.
decomposedBlockData(const label comm, const IOobject &, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
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.
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
static label calcNumProcs(const label comm, const off_t maxBufferSize, const labelUList &recvSizes, const label startProci)
Helper: determine number of processors whose recvSizes fits.
virtual bool read()
Read object.
virtual ~decomposedBlockData()
Destructor.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
A class for handling file names.
Definition: fileName.H:82
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
bool headerOk()
Read and check header info.
Definition: regIOobject.C:429
A token holds items read from Istream.
Definition: token.H:74
bool isLabel() const
Definition: tokenI.H:615
bool isWord() const
Definition: tokenI.H:342
const word & wordToken() const
Definition: tokenI.H:347
A class for handling words, derived from string.
Definition: word.H:63
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define WarningInFunction
Report a warning using Foam::Warning.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
Namespace for OpenFOAM.
const fileOperation & fileHandler()
Get current file handler.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
static const char nl
Definition: Ostream.H:297