decomposedBlockData.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) 2020-2022 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 
29 #include "decomposedBlockData.H"
30 #include "OPstream.H"
31 #include "IPstream.H"
32 #include "PstreamBuffers.H"
33 #include "Fstream.H"
34 #include "dictionary.H"
35 #include "objectRegistry.H"
36 #include "SubList.H"
37 #include "charList.H"
38 #include "labelPair.H"
40 #include "ListStream.H"
41 #include "StringStream.H"
42 
43 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
48 }
49 
50 
51 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
52 
54 (
55  const word& objectType
56 )
57 {
58  return
59  (
60  objectType == decomposedBlockData::typeName
61  );
62 }
63 
64 
66 (
67  const IOobject& io
68 )
69 {
71 }
72 
73 
74 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 
77 (
78  const label comm,
79  const IOobject& io,
80  const UPstream::commsTypes commsType
81 )
82 :
83  regIOobject(io),
84  commsType_(commsType),
85  comm_(comm),
86  contentData_()
87 {
88  // Temporary warning
90  {
92  << "decomposedBlockData " << name()
93  << " constructed with IOobject::MUST_READ_IF_MODIFIED"
94  " but decomposedBlockData does not support automatic rereading."
95  << endl;
96  }
97  if (isReadRequired() || (isReadOptional() && headerOk()))
98  {
99  read();
100  }
101 }
102 
103 
104 // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
105 
107 (
108  Istream& is,
109  List<char>& charData
110 )
111 {
112  // Handle any of these:
113 
114  // 0. NCHARS (...)
115  // 1. List<char> NCHARS (...)
116  // 2. processorN List<char> NCHARS (...) ;
117 
118  is.fatalCheck(FUNCTION_NAME);
119  token tok(is);
120  is.fatalCheck(FUNCTION_NAME);
121 
122  // Dictionary format has primitiveEntry keyword:
123  const bool isDictFormat = (tok.isWord() && !tok.isCompound());
124 
125  if (!isDictFormat && tok.good())
126  {
127  is.putBack(tok);
128  }
129  charData.readList(is);
130 
131  if (isDictFormat)
132  {
133  is.fatalCheck(FUNCTION_NAME);
134  is >> tok;
135  is.fatalCheck(FUNCTION_NAME);
136 
137  // Swallow trailing ';'
138  if (tok.good() && !tok.isPunctuation(token::END_STATEMENT))
139  {
140  is.putBack(tok);
141  }
142  }
143 
144  return true;
145 }
146 
147 
149 (
150  OSstream& os,
151  const label blocki,
152  const UList<char>& charData
153 )
154 {
155  // Offset to the beginning of this output
156 
157  std::streamoff blockOffset = os.stdStream().tellp();
158 
159  const word procName("processor" + Foam::name(blocki));
160 
161  {
162  os << nl << "// " << procName << nl;
163  charData.writeList(os) << nl;
164  }
165 
166  return blockOffset;
167 }
168 
169 
171 (
172  OSstream& os,
173  IOstreamOption streamOptData,
174  const regIOobject& io,
175  const label blocki,
176  const bool withLocalHeader
177 )
178 {
179  // String(s) from all data to write
180  string contentChars;
181  {
182  OStringStream os(streamOptData);
183 
184  bool ok = true;
185 
186  // Generate FoamFile header on master, without comment banner
187  if (withLocalHeader)
188  {
189  const bool old = IOobject::bannerEnabled(false);
190 
191  ok = io.writeHeader(os);
192 
194  }
195 
196  // Write the data to the Ostream
197  ok = ok && io.writeData(os);
198 
199  if (!ok)
200  {
201  return std::streamoff(-1);
202  }
203 
204  contentChars = os.str();
205  }
206 
207  // The character data
208  UList<char> charData
209  (
210  const_cast<char*>(contentChars.data()),
211  label(contentChars.size())
212  );
214  return decomposedBlockData::writeBlockEntry(os, blocki, charData);
215 }
216 
217 
220 (
221  const label blocki,
222  ISstream& is,
223  IOobject& headerIO
224 )
225 {
226  if (debug)
227  {
228  Pout<< "decomposedBlockData::readBlock:"
229  << " stream:" << is.name() << " attempt to read block " << blocki
230  << endl;
231  }
232 
233  // Extracted header information
234  IOstreamOption streamOptData;
235  unsigned labelWidth = is.labelByteSize();
236  unsigned scalarWidth = is.scalarByteSize();
237 
238  autoPtr<ISstream> realIsPtr;
239 
240  // Read master for header
241  List<char> data;
243 
244  if (blocki == 0)
245  {
246  realIsPtr.reset(new IListStream(std::move(data)));
247  realIsPtr->name() = is.name();
248 
249  {
250  // Read header from first block,
251  // advancing the stream position
252  if (!headerIO.readHeader(*realIsPtr))
253  {
254  FatalIOErrorInFunction(*realIsPtr)
255  << "Problem while reading object header "
256  << is.relativeName() << nl
257  << exit(FatalIOError);
258  }
259  }
260  }
261  else
262  {
263  {
264  // Read header from first block
265  UIListStream headerStream(data);
266  if (!headerIO.readHeader(headerStream))
267  {
268  FatalIOErrorInFunction(headerStream)
269  << "Problem while reading object header "
270  << is.relativeName() << nl
271  << exit(FatalIOError);
272  }
273  streamOptData = static_cast<IOstreamOption>(headerStream);
274  labelWidth = headerStream.labelByteSize();
275  scalarWidth = headerStream.scalarByteSize();
276  }
277 
278  for (label i = 1; i < blocki+1; i++)
279  {
280  // Read and discard data, only retain the last one
282  }
283  realIsPtr.reset(new IListStream(std::move(data)));
284  realIsPtr->name() = is.name();
285 
286  // Apply stream settings
287  realIsPtr().format(streamOptData.format());
288  realIsPtr().version(streamOptData.version());
289  realIsPtr().setLabelByteSize(labelWidth);
290  realIsPtr().setScalarByteSize(scalarWidth);
291  }
292 
293  return realIsPtr;
294 }
295 
296 
298 (
299  const label comm,
300  autoPtr<ISstream>& isPtr,
301  List<char>& data,
302  const UPstream::commsTypes commsType
303 )
304 {
305  if (debug)
306  {
307  Pout<< "decomposedBlockData::readBlocks:"
308  << " stream:" << (isPtr ? isPtr->name() : "invalid")
309  << " commsType:" << Pstream::commsTypeNames[commsType]
310  << " comm:" << comm << endl;
311  }
312 
313  bool ok = false;
314 
315  if (UPstream::master(comm))
316  {
317  auto& is = *isPtr;
319 
320  // Read master data
322  }
323 
324  if (commsType == UPstream::commsTypes::scheduled)
325  {
326  if (UPstream::master(comm))
327  {
328  // Master data already read ...
329  auto& is = *isPtr;
331 
332  // Read and transmit slave data
333  for (const int proci : UPstream::subProcs(comm))
334  {
335  List<char> elems;
337 
338  OPstream os
339  (
341  proci,
342  0,
344  comm
345  );
346  os << elems;
347  }
348 
349  ok = is.good();
350  }
351  else
352  {
353  IPstream is
354  (
357  0,
359  comm
360  );
361  is >> data;
362  }
363  }
364  else
365  {
366  PstreamBuffers pBufs(comm, UPstream::commsTypes::nonBlocking);
367 
368  if (UPstream::master(comm))
369  {
370  // Master data already read ...
371  auto& is = *isPtr;
373 
374  // Read and transmit slave data
375  for (const int proci : UPstream::subProcs(comm))
376  {
377  List<char> elems;
379 
380  UOPstream os(proci, pBufs);
381  os << elems;
382  }
383  }
384 
385  pBufs.finishedScatters();
386 
387  if (!UPstream::master(comm))
388  {
389  UIPstream is(UPstream::masterNo(), pBufs);
390  is >> data;
391  }
392  }
393 
395 
396  return ok;
397 }
398 
399 
401 (
402  const label comm,
403  const fileName& fName,
404  autoPtr<ISstream>& isPtr,
405  IOobject& headerIO,
406  const UPstream::commsTypes commsType
407 )
408 {
409  if (debug)
410  {
411  Pout<< "decomposedBlockData::readBlocks:"
412  << " stream:" << (isPtr ? isPtr->name() : "invalid")
413  << " commsType:" << Pstream::commsTypeNames[commsType] << endl;
414  }
415 
416  bool ok = false;
417  List<char> data;
418  autoPtr<ISstream> realIsPtr;
419 
420  if (UPstream::master(comm))
421  {
422  auto& is = *isPtr;
424 
425  // Read master data
427 
428  realIsPtr.reset(new IListStream(std::move(data)));
429  realIsPtr->name() = fName;
430 
431  {
432  // Read header from first block,
433  // advancing the stream position
434  if (!headerIO.readHeader(*realIsPtr))
435  {
436  FatalIOErrorInFunction(*realIsPtr)
437  << "Problem while reading object header "
438  << is.relativeName() << nl
439  << exit(FatalIOError);
440  }
441  }
442  }
443 
444  if (commsType == UPstream::commsTypes::scheduled)
445  {
446  if (UPstream::master(comm))
447  {
448  // Master data already read ...
449  auto& is = *isPtr;
451 
452  // Read and transmit slave data
453  for (const int proci : UPstream::subProcs(comm))
454  {
456 
457  OPstream os
458  (
460  proci,
461  0,
463  comm
464  );
465  os << data;
466  }
467 
468  ok = is.good();
469  }
470  else
471  {
472  IPstream is
473  (
476  0,
478  comm
479  );
480  is >> data;
481 
482  realIsPtr.reset(new IListStream(std::move(data)));
483  realIsPtr->name() = fName;
484  }
485  }
486  else
487  {
488  PstreamBuffers pBufs(comm, UPstream::commsTypes::nonBlocking);
489 
490  if (UPstream::master(comm))
491  {
492  // Master data already read ...
493  auto& is = *isPtr;
495 
496  // Read and transmit slave data
497  for (const int proci : UPstream::subProcs(comm))
498  {
499  List<char> elems;
501 
502  UOPstream os(proci, pBufs);
503  os << elems;
504  }
505 
506  ok = is.good();
507  }
508 
509  pBufs.finishedScatters();
510 
511  if (!UPstream::master(comm))
512  {
513  UIPstream is(UPstream::masterNo(), pBufs);
514  is >> data;
515 
516  realIsPtr.reset(new IListStream(std::move(data)));
517  realIsPtr->name() = fName;
518  }
519  }
520 
521  Pstream::broadcast(ok, comm);
522 
523  // Broadcast master header info,
524  // set stream properties from realIsPtr on master
525 
526  int verValue;
527  int fmtValue;
528  unsigned labelWidth;
529  unsigned scalarWidth;
530  word headerName(headerIO.name());
531 
532  if (UPstream::master(comm))
533  {
534  verValue = realIsPtr().version().canonical();
535  fmtValue = static_cast<int>(realIsPtr().format());
536  labelWidth = realIsPtr().labelByteSize();
537  scalarWidth = realIsPtr().scalarByteSize();
538  }
539 
541  (
542  UPstream::worldComm, // Future? comm,
543  verValue,
544  fmtValue,
545  labelWidth,
546  scalarWidth,
547  headerName,
548  headerIO.headerClassName(),
549  headerIO.note()
550  // Unneeded: headerIO.instance()
551  // Unneeded: headerIO.local()
552  );
553 
554  realIsPtr().version(IOstreamOption::versionNumber::canonical(verValue));
555  realIsPtr().format(IOstreamOption::streamFormat(fmtValue));
556  realIsPtr().setLabelByteSize(labelWidth);
557  realIsPtr().setScalarByteSize(scalarWidth);
558 
559  headerIO.rename(headerName);
560 
561  return realIsPtr;
562 }
563 
564 
566 (
567  const label comm,
568  const label data,
569  labelList& datas
570 )
571 {
572  const label nProcs = UPstream::nProcs(comm);
573  datas.resize(nProcs);
574 
575  char* data0Ptr = datas.data_bytes();
576 
577  List<int> recvOffsets;
578  List<int> recvSizes;
579  if (UPstream::master(comm))
580  {
581  recvOffsets.setSize(nProcs);
582  forAll(recvOffsets, proci)
583  {
584  // Note: truncating long int to int since UPstream::gather limited
585  // to ints
586  recvOffsets[proci] =
587  int(reinterpret_cast<char*>(&datas[proci]) - data0Ptr);
588  }
589  recvSizes.setSize(nProcs, sizeof(label));
590  }
591 
593  (
594  reinterpret_cast<const char*>(&data),
595  sizeof(label),
596  data0Ptr,
597  recvSizes,
598  recvOffsets,
599  comm
600  );
601 }
602 
603 
605 (
606  const label comm,
607  const UList<char>& data,
608  const labelUList& recvSizes,
609 
610  const label startProc,
611  const label nProcs,
612 
613  List<int>& sliceOffsets,
614  List<char>& recvData
615 )
616 {
617  // Calculate master data
618  List<int> sliceSizes;
619  if (UPstream::master(comm))
620  {
621  const label numProcs = UPstream::nProcs(comm);
622 
623  sliceSizes.resize(numProcs, 0);
624  sliceOffsets.resize(numProcs+1, 0);
625 
626  int totalSize = 0;
627  label proci = startProc;
628  for (label i = 0; i < nProcs; i++)
629  {
630  sliceSizes[proci] = int(recvSizes[proci]);
631  sliceOffsets[proci] = totalSize;
632  totalSize += sliceSizes[proci];
633  ++proci;
634  }
635  sliceOffsets[proci] = totalSize;
636  recvData.setSize(totalSize);
637  }
638 
639  int nSend = 0;
640  if
641  (
642  !UPstream::master(comm)
643  && (UPstream::myProcNo(comm) >= startProc)
644  && (UPstream::myProcNo(comm) < startProc+nProcs)
645  )
646  {
647  // Note: UPstream::gather limited to int
648  nSend = int(data.size_bytes());
649  }
650 
652  (
653  data.cdata(),
654  nSend,
655 
656  recvData.data(),
657  sliceSizes,
658  sliceOffsets,
659  comm
660  );
661 }
662 
663 
665 (
666  const label comm,
667  const off_t maxBufferSize,
668  const labelUList& recvSizes,
669  const label startProci
670 )
671 {
672  const label nProcs = UPstream::nProcs(comm);
673 
674  label nSendProcs = -1;
675  if (UPstream::master(comm))
676  {
677  off_t totalSize = recvSizes[startProci];
678  label proci = startProci+1;
679  while (proci < nProcs && (totalSize+recvSizes[proci] < maxBufferSize))
680  {
681  totalSize += recvSizes[proci];
682  proci++;
683  }
684 
685  nSendProcs = proci-startProci;
686  }
687 
688  // Scatter nSendProcs
689  label n;
691  (
692  reinterpret_cast<const char*>(&nSendProcs),
693  List<int>(nProcs, sizeof(nSendProcs)),
694  List<int>(nProcs, Zero),
695  reinterpret_cast<char*>(&n),
696  sizeof(n),
697  comm
698  );
699 
700  return n;
701 }
702 
703 
705 (
706  const label comm,
707  autoPtr<OSstream>& osPtr,
708  List<std::streamoff>& blockOffset,
709  const UList<char>& masterData,
710 
711  const labelUList& recvSizes,
712  const PtrList<SubList<char>>& slaveData,
713 
714  const UPstream::commsTypes commsType,
715  const bool syncReturnState
716 )
717 {
718  if (debug)
719  {
720  Pout<< "decomposedBlockData::writeBlocks:"
721  << " stream:" << (osPtr ? osPtr->name() : "invalid")
722  << " data:" << masterData.size()
723  << " (master only) slaveData:" << slaveData.size()
724  << " commsType:" << Pstream::commsTypeNames[commsType] << endl;
725  }
726 
727  const label nProcs = UPstream::nProcs(comm);
728 
729  bool ok = true;
730 
731  // Write master data
732  if (UPstream::master(comm))
733  {
734  blockOffset.resize(nProcs);
735 
736  OSstream& os = *osPtr;
737 
738  blockOffset[UPstream::masterNo()] =
740  (
741  os,
743  masterData
744  );
745 
746  ok = os.good();
747  }
748 
749  if (slaveData.size())
750  {
751  // Already have gathered the slave data.
752 
753  if (UPstream::master(comm))
754  {
755  // Master data already written ...
756  OSstream& os = *osPtr;
757 
758  // Write slaves
759  for (label proci = 1; proci < nProcs; ++proci)
760  {
761  blockOffset[proci] =
763  (
764  os,
765  proci,
766  slaveData[proci]
767  );
768  }
769 
770  ok = os.good();
771  }
772  }
773  else if (commsType == UPstream::commsTypes::scheduled)
774  {
775  if (UPstream::master(comm))
776  {
777  // Master data already written ...
778  OSstream& os = *osPtr;
779 
780  // Receive and write slaves
781  DynamicList<char> elems;
782  for (label proci = 1; proci < nProcs; ++proci)
783  {
784  elems.resize(recvSizes[proci]);
786  (
788  proci,
789  elems.data(),
790  elems.size_bytes(),
792  comm
793  );
794 
795  blockOffset[proci] =
797  (
798  os,
799  proci,
800  elems
801  );
802  }
803 
804  ok = os.good();
805  }
806  else
807  {
809  (
812  masterData.cdata(),
813  masterData.size_bytes(),
815  comm
816  );
817  }
818  }
819  else
820  {
821  // Master data already written ...
822 
823  // Find out how many processor can be received into
824  // maxMasterFileBufferSize
825 
826  // Starting slave processor and number of processors
827  label startProc = 1;
828  label nSendProcs = nProcs-1;
829 
830  while (nSendProcs > 0 && startProc < nProcs)
831  {
832  nSendProcs = calcNumProcs
833  (
834  comm,
835  off_t
836  (
837  fileOperations::masterUncollatedFileOperation::
838  maxMasterFileBufferSize
839  ),
840  recvSizes,
841  startProc
842  );
843 
844  if (nSendProcs == 0)
845  {
846  break;
847  }
848 
849 
850  // Gather data from (a slice of) the slaves
851  List<int> sliceOffsets;
852  List<char> recvData;
853  gatherSlaveData
854  (
855  comm,
856  masterData,
857  recvSizes,
858 
859  startProc, // startProc,
860  nSendProcs, // nProcs,
861 
862  sliceOffsets,
863  recvData
864  );
865 
866  if (UPstream::master(comm))
867  {
868  OSstream& os = *osPtr;
869 
870  // Write slaves
871  for
872  (
873  label proci = startProc;
874  proci < startProc+nSendProcs;
875  ++proci
876  )
877  {
878  SubList<char> dataSlice
879  (
880  recvData,
881  sliceOffsets[proci+1]-sliceOffsets[proci],
882  sliceOffsets[proci]
883  );
884 
885  blockOffset[proci] =
887  (
888  os,
889  proci,
890  dataSlice
891  );
892  }
893  }
894 
895  startProc += nSendProcs;
896  }
897 
898  if (UPstream::master(comm))
899  {
900  ok = osPtr->good();
901  }
902  }
903 
904  if (syncReturnState)
905  {
906  //- Enable to get synchronised error checking. Is the one that keeps
907  // slaves as slow as the master (which does all the writing)
908  Pstream::broadcast(ok, comm);
909  }
910 
911  return ok;
912 }
913 
914 
916 {
917  autoPtr<ISstream> isPtr;
918  fileName objPath(fileHandler().filePath(false, *this, word::null));
919  if (UPstream::master(comm_))
920  {
921  isPtr.reset(new IFstream(objPath));
922  IOobject::readHeader(*isPtr);
923  }
924 
925  return readBlocks(comm_, isPtr, contentData_, commsType_);
926 }
927 
928 
930 {
931  IOobject io(*this);
932  IOstreamOption streamOpt(os);
933 
934  int verValue;
935  int fmtValue;
936  // Unneeded: word masterName(name());
937  fileName masterLocation(instance()/db().dbDir()/local());
938 
939  // Re-read my own data to find out the header information
940  if (Pstream::master(comm_))
941  {
942  UIListStream headerStream(contentData_);
943  io.readHeader(headerStream);
944 
945  verValue = headerStream.version().canonical();
946  fmtValue = static_cast<int>(headerStream.format());
947  }
948 
949  // Broadcast header information
951  (
952  comm_,
953  verValue,
954  fmtValue,
955  // Unneeded: masterName
957  io.note(),
958  // Unneeded: io.instance()
959  // Unneeded: io.local()
960  masterLocation
961  );
962 
964  streamOpt.format(IOstreamOption::streamFormat(fmtValue));
965 
966  if (!Pstream::master(comm_))
967  {
969  (
970  os,
971  streamOpt, // streamOpt for data
973  io.note(),
974  masterLocation,
975  name(),
976  dictionary()
977  );
978  }
979 
980  // Write the character data
981  if (isA<OFstream>(os))
982  {
983  // Serial file output - can use writeRaw()
984  os.writeRaw(contentData_.cdata(), contentData_.size_bytes());
985  }
986  else
987  {
988  // Other cases are less fortunate, and no std::string_view
989  std::string str(contentData_.cdata(), contentData_.size_bytes());
990  os.writeQuoted(str, false);
991  }
992 
993  if (!Pstream::master(comm_))
994  {
996  }
997 
998  return os.good();
999 }
1000 
1001 
1003 (
1004  IOstreamOption streamOpt,
1005  const bool valid
1006 ) const
1007 {
1008  autoPtr<OSstream> osPtr;
1009  if (UPstream::master(comm_))
1010  {
1011  // Note: always write binary. These are strings so readable anyway.
1012  // They have already be tokenised on the sending side.
1013 
1014  osPtr.reset(new OFstream(objectPath(), IOstreamOption::BINARY));
1015 
1016  // Update meta-data for current state
1017  const_cast<regIOobject&>
1018  (
1019  static_cast<const regIOobject&>(*this)
1020  ).updateMetaData();
1021 
1023  (
1024  *osPtr,
1025  streamOpt, // streamOpt for data
1026  static_cast<const IOobject&>(*this)
1027  );
1028  }
1029 
1030  labelList recvSizes;
1031  gather(comm_, label(contentData_.size_bytes()), recvSizes);
1032 
1033  List<std::streamoff> blockOffsets;
1034  PtrList<SubList<char>> slaveData; // dummy slave data
1035  return writeBlocks
1036  (
1037  comm_,
1038  osPtr,
1039  blockOffsets,
1040  contentData_,
1041  recvSizes,
1042  slaveData,
1043  commsType_
1044  );
1045 }
1046 
1047 
1048 // ************************************************************************* //
static bool writeBlocks(const label comm, autoPtr< OSstream > &osPtr, List< std::streamoff > &blockOffset, 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.
virtual const fileName & name() const
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
Definition: OSstream.H:128
static bool write(const UPstream::commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Write buffer contents to given processor.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
fileName relativeName() const
Return the name of the stream relative to the current case.
Definition: IOstream.C:39
virtual bool read()
Read object.
A class for handling file names.
Definition: fileName.H:71
readOption readOpt() const noexcept
Get the read option.
static const Enum< commsTypes > commsTypeNames
Enumerated names for the communication types.
Definition: UPstream.H:76
virtual const fileName & name() const
The name of the input serial stream. (eg, the name of the Fstream file name)
Definition: ISstream.H:136
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:132
commsTypes
Types of communications.
Definition: UPstream.H:66
Input/output from string buffers.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:150
static autoPtr< ISstream > readBlock(const label blocki, ISstream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
Output to file stream, using an OSstream.
Definition: OFstream.H:49
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
virtual void rename(const word &newName)
Rename the object.
Definition: IOobject.H:626
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:230
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:434
const string & note() const noexcept
Return the optional note.
Definition: IOobjectI.H:180
autoPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler.
static bool readBlocks(const label comm, autoPtr< ISstream > &isPtr, List< char > &contentChars, const UPstream::commsTypes commsType)
Read data into *this. ISstream is only valid on master.
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:806
A simple container for options an IOstream can normally have.
virtual std::ostream & stdStream()
Access to underlying std::ostream.
Definition: OFstream.C:110
End entry [isseparator].
Definition: token.H:157
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:688
static label worldComm
Default world communicator (all processors). May differ from globalComm if local worlds are in use...
Definition: UPstream.H:361
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes associated with the stream.
Definition: IOstream.H:333
bool writeHeader(Ostream &os) const
Write header with current type()
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OBJstream.C:101
bool isReadOptional() const noexcept
True if (READ_IF_PRESENT) bits are set.
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:244
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all processes in communicator.
static void scatter(const char *sendData, const UList< int > &sendCounts, const UList< int > &sendOffsets, char *recvData, int recvCount, const label communicator=worldComm)
Send variable length char data to all ranks.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
int canonical() const noexcept
From version to canonical integer value.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:37
A List obtained as a section of another List.
Definition: SubList.H:50
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator) is 1 for serial run.
Definition: UPstream.H:656
void setSize(const label n)
Alias for resize()
Definition: List.H:289
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
"scheduled" : (MPI_Send, MPI_Recv)
A class for handling words, derived from Foam::string.
Definition: word.H:63
Reading required, file watched for runTime modification.
static bool readBlockEntry(Istream &is, List< char > &charData)
Helper: read block of (binary) character data.
static void gather(const char *sendData, int sendCount, char *recvData, const UList< int > &recvCounts, const UList< int > &recvOffsets, const label communicator=worldComm)
Receive variable length char data from all ranks.
static constexpr int masterNo() noexcept
Process index of the master (always 0)
Definition: UPstream.H:664
The decomposedBlockData comprise a List<char> for each output processor, typically with IO on the mas...
void gather(const Type *sendData, int sendCount, Type *recvData, int recvCount, MPI_Datatype datatype, const label comm, label *requestID=nullptr)
static std::streamoff writeBlockEntry(OSstream &os, const label blocki, const UList< char > &charData)
Helper: write block of (binary) character data.
static const word null
An empty word.
Definition: word.H:84
bool local
Definition: EEqn.H:20
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:99
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
Definition: UIListStream.H:224
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
defineTypeNameAndDebug(combustionModel, 0)
Database for solution data, solver performance and other reduced data.
Definition: data.H:51
Input from file stream, using an ISstream.
Definition: IFstream.H:49
bool isReadRequired() const noexcept
True if (MUST_READ | MUST_READ_IF_MODIFIED) bits are set.
static bool bannerEnabled() noexcept
Status of output file banner.
Definition: IOobject.H:331
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.
static void broadcasts(const label comm, Type &arg1, Args &&... args)
Broadcast multiple items to all processes in communicator.
decomposedBlockData(const label comm, const IOobject &io, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
static label calcNumProcs(const label comm, const off_t maxBufferSize, const labelUList &recvSizes, const label startProci)
Helper: determine number of processors whose recvSizes fits into maxBufferSize.
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:168
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:51
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:607
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:274
static bool master(const label communicator=worldComm)
Am I the master rank.
Definition: UPstream.H:672
versionNumber version() const noexcept
Get the stream version.
streamFormat
Data format (ascii | binary)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:69
"nonBlocking" : (MPI_Isend, MPI_Irecv)
label n
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:223
List< label > labelList
A List of labels.
Definition: List.H:62
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
Definition: UPstream.H:757
Input/output streams with managed List storage.
virtual Ostream & writeRaw(const char *data, std::streamsize count)
Low-level raw binary output.
Definition: OSstream.C:242
static label read(const commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Read buffer contents from given processor.
Definition: UIPstreamRead.C:35
bool readHeader(Istream &is)
Read header (&#39;FoamFile&#39; dictionary) and set the IOobject and stream characteristics.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
virtual bool writeData(Ostream &os) const
Write separated content (assumes content is the serialised data)
unsigned labelByteSize() const noexcept
The sizeof (label) in bytes associated with the stream.
Definition: IOstream.H:325
streamFormat format() const noexcept
Get the current stream format.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
Definition: UListI.H:251
static void writeHeader(Ostream &os, IOstreamOption streamOptContainer, const word &objectType, const string &note, const fileName &location, const word &objectName, const dictionary &extraEntries)
Helper: write FoamFile IOobject header.
Namespace for OpenFOAM.
static void gather(const label comm, const label data, labelList &datas)
Helper: gather single label. Note: using native Pstream.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:157