@@ -1511,30 +1511,66 @@ VisMF::readFAB (FabArray<FArrayBox> &mf,
15111511 std::ifstream *infs = VisMF::OpenStream (FullName);
15121512 infs->seekg (hdr.m_fod [idx].m_head , std::ios::beg);
15131513
1514+ Box box = fab.box ();
1515+ if (hdr.m_ngrow != mf.nGrowVect ()) {
1516+ box.grow (hdr.m_ngrow - mf.nGrowVect ());
1517+ }
1518+ std::unique_ptr<FArrayBox> hostfab;
1519+
15141520 if (NoFabHeader (hdr)) {
15151521 Real* fabdata = fab.dataPtr ();
15161522#ifdef AMREX_USE_GPU
1517- std::unique_ptr<FArrayBox> hostfab;
1518- if (fab.arena ()->isManaged () || fab.arena ()->isDevice ()) {
1519- hostfab = std::make_unique<FArrayBox>(fab.box (), fab.nComp (), The_Pinned_Arena ());
1523+ if (fab.arena ()->isManaged () || fab.arena ()->isDevice () || box != fab.box ()) {
1524+ hostfab = std::make_unique<FArrayBox>(box, fab.nComp (), The_Pinned_Arena ());
1525+ fabdata = hostfab->dataPtr ();
1526+ }
1527+ #else
1528+ if (box != fab.box ()) {
1529+ hostfab = std::make_unique<FArrayBox>(box, fab.nComp ());
15201530 fabdata = hostfab->dataPtr ();
15211531 }
15221532#endif
1533+
15231534 if (hdr.m_writtenRD == FPC::NativeRealDescriptor ()) {
1524- infs->read ((char *) fabdata, static_cast <std::streamsize>(fab.nBytes ()));
1535+ auto nbytes = hostfab ? hostfab->nBytes () : fab.nBytes ();
1536+ infs->read ((char *) fabdata, static_cast <std::streamsize>(nbytes));
15251537 } else {
1526- Long readDataItems (fab. box (). numPts () * fab.nComp () );
1527- RealDescriptor::convertToNativeFormat (fabdata, readDataItems,
1528- *infs, hdr.m_writtenRD );
1538+ auto readDataItems = hostfab ? hostfab-> size () : fab.size ( );
1539+ RealDescriptor::convertToNativeFormat (fabdata, readDataItems,
1540+ *infs, hdr.m_writtenRD );
15291541 }
15301542#ifdef AMREX_USE_GPU
15311543 if (hostfab) {
1532- Gpu::htod_memcpy_async (fab.dataPtr (), hostfab->dataPtr (), fab.size ()*sizeof (Real));
1533- Gpu::streamSynchronize ();
1544+ if (fab.arena ()->isManaged () || fab.arena ()->isDevice ()) {
1545+ fab.template copy <RunOn::Device>(*hostfab);
1546+ Gpu::streamSynchronize ();
1547+ } else {
1548+ fab.template copy <RunOn::Host>(*hostfab);
1549+ }
1550+ }
1551+ #else
1552+ if (hostfab) {
1553+ fab.copy (*hostfab);
15341554 }
15351555#endif
15361556 } else {
1537- fab.readFrom (*infs);
1557+ if (box == fab.box ()) {
1558+ fab.readFrom (*infs);
1559+ } else {
1560+ #ifdef AMREX_USE_GPU
1561+ if (fab.arena ()->isManaged () || fab.arena ()->isDevice ()) {
1562+ hostfab = std::make_unique<FArrayBox>(box, fab.nComp (), The_Pinned_Arena ());
1563+ hostfab->readFrom (*infs);
1564+ fab.template copy <RunOn::Device>(*hostfab);
1565+ Gpu::streamSynchronize ();
1566+ } else
1567+ #endif
1568+ {
1569+ hostfab = std::make_unique<FArrayBox>(box, fab.nComp ());
1570+ hostfab->readFrom (*infs);
1571+ fab.template copy <RunOn::Host>(*hostfab);
1572+ }
1573+ }
15381574 }
15391575
15401576 if (!(infs->good ())) { amrex::Error (" VisMF::readFAB failed" ); }
@@ -1598,7 +1634,8 @@ VisMF::Read (FabArray<FArrayBox> &mf,
15981634 DistributionMapping dm = vismf_make_dm (hdr.m_ba );
15991635 mf.define (hdr.m_ba , dm, hdr.m_ncomp , hdr.m_ngrow , MFInfo (), FArrayBoxFactory ());
16001636 } else {
1601- BL_ASSERT (amrex::match (hdr.m_ba ,mf.boxArray ()));
1637+ AMREX_ALWAYS_ASSERT (amrex::match (hdr.m_ba ,mf.boxArray ()) &&
1638+ hdr.m_ncomp == mf.nComp ());
16021639 }
16031640
16041641#ifdef BL_USE_MPI
@@ -1608,7 +1645,7 @@ VisMF::Read (FabArray<FArrayBox> &mf,
16081645 int nProcs (ParallelDescriptor::NProcs ());
16091646 bool noFabHeader (NoFabHeader (hdr));
16101647
1611- if (noFabHeader && useSynchronousReads) {
1648+ if (noFabHeader && useSynchronousReads && mf. nGrowVect () == 0 && hdr. m_ngrow == 0 ) {
16121649
16131650 // ---- This code is only for reading in file order
16141651 bool doConvert (hdr.m_writtenRD != FPC::NativeRealDescriptor ());
0 commit comments