| 1492 | #endif |
| 1493 | |
| 1494 | void |
| 1495 | ReadAndBcastFile (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 | |
| 1545 | void |
| 1546 | Initialize () |
no test coverage detected