MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / ReadAndBcastFile

Function ReadAndBcastFile

Src/Base/AMReX_ParallelDescriptor.cpp:1494–1543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1492#endif
1493
1494void
1495ReadAndBcastFile (const std::string& filename, Vector<char>& charBuf,
1496 bool bExitOnError, const MPI_Comm&comm)
1497{
1498 constexpr int IO_Buffer_Size = 262144 * 8;
1499
1500#ifdef BL_SETBUF_SIGNED_CHAR
1501 using Setbuf_Char_Type = signed char;
1502#else
1503 using Setbuf_Char_Type = char;
1504#endif
1505
1506 Vector<Setbuf_Char_Type> io_buffer(IO_Buffer_Size);
1507
1508 Long fileLength(0), fileLengthPadded(0);
1509
1510 std::ifstream iss;
1511
1512 const int root = ParallelDescriptor::IOProcessorNumber(comm);
1513 if (ParallelDescriptor::IOProcessor(comm)) {
1514 iss.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
1515 iss.open(filename.c_str(), std::ios::in);
1516 if ( ! iss.good()) {
1517 if(bExitOnError) {
1518 amrex::FileOpenFailed(filename);
1519 } else {
1520 fileLength = -1;
1521 }
1522 } else {
1523 iss.seekg(0, std::ios::end);
1524 fileLength = static_cast<std::streamoff>(iss.tellg());
1525 iss.seekg(0, std::ios::beg);
1526 }
1527 }
1528 ParallelDescriptor::Bcast(&fileLength, 1, root, comm);
1529
1530 if(fileLength == -1) {
1531 return;
1532 }
1533
1534 fileLengthPadded = fileLength + 1;
1535// fileLengthPadded += fileLengthPadded % 8;
1536 charBuf.resize(fileLengthPadded);
1537 if (ParallelDescriptor::IOProcessor(comm)) {
1538 iss.read(charBuf.dataPtr(), fileLength);
1539 iss.close();
1540 }
1541 ParallelDescriptor::Bcast(charBuf.dataPtr(), fileLengthPadded, root, comm);
1542 charBuf[fileLength] = '\0';
1543}
1544
1545void
1546Initialize ()

Callers 13

ReadCheckpointFileMethod · 0.85
readBoxListFunction · 0.85
RestartMethod · 0.85
readMethod · 0.85
read_from_chkpt_fileMethod · 0.85
restartMethod · 0.85
ReadFunction · 0.85
InitializeMethod · 0.85
PlotFileDataImplMethod · 0.85
VisMFMethod · 0.85
ReadMethod · 0.85
ReadFAHeaderMethod · 0.85

Calls 7

IOProcessorNumberFunction · 0.85
IOProcessorFunction · 0.85
BcastFunction · 0.70
dataPtrMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected