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