| 2343 | } |
| 2344 | |
| 2345 | void |
| 2346 | VisMF::AsyncWriteDoit (const FabArray<FArrayBox>& mf, const std::string& mf_name, |
| 2347 | bool is_rvalue, bool valid_cells_only) |
| 2348 | { |
| 2349 | BL_PROFILE("VisMF::AsyncWrite()"); |
| 2350 | |
| 2351 | AMREX_ASSERT(!mf_name.empty() && mf_name.back() != '/'); |
| 2352 | static_assert(sizeof(int64_t) == sizeof(Real)*2 || sizeof(int64_t) == sizeof(Real), |
| 2353 | "AsyncWrite: unsupported Real size"); |
| 2354 | |
| 2355 | const DistributionMapping& dm = mf.DistributionMap(); |
| 2356 | |
| 2357 | const int myproc = ParallelDescriptor::MyProc(); |
| 2358 | const int nprocs = ParallelDescriptor::NProcs(); |
| 2359 | const int io_proc = nprocs - 1; |
| 2360 | |
| 2361 | RealDescriptor const& whichRD = FPC::NativeRealDescriptor(); |
| 2362 | |
| 2363 | auto hdr = std::make_shared<VisMF::Header>(mf, VisMF::NFiles, VisMF::Header::Version_v1, false); |
| 2364 | if (valid_cells_only) { hdr->m_ngrow = IntVect(0); } |
| 2365 | |
| 2366 | constexpr int sizeof_int64_over_real = sizeof(int64_t) / sizeof(Real); |
| 2367 | const int n_local_fabs = mf.local_size(); |
| 2368 | const int n_global_fabs = mf.size(); |
| 2369 | const int ncomp = mf.nComp(); |
| 2370 | const Long n_fab_reals = 2*ncomp; |
| 2371 | const Long n_fab_int64 = 1; |
| 2372 | const Long n_fab_nums = (n_fab_reals/sizeof_int64_over_real) + n_fab_int64; |
| 2373 | const Long n_local_nums = n_fab_nums * n_local_fabs + 1; |
| 2374 | Vector<int64_t> localdata(n_local_nums); |
| 2375 | |
| 2376 | bool data_on_device = mf.arena()->isManaged() || mf.arena()->isDevice(); |
| 2377 | bool run_on_device = data_on_device && Gpu::inLaunchRegion(); |
| 2378 | amrex::ignore_unused(run_on_device); |
| 2379 | |
| 2380 | bool strip_ghost = valid_cells_only && mf.nGrowVect() != 0; |
| 2381 | |
| 2382 | int64_t total_bytes = 0; |
| 2383 | if (localdata.size() > 1) { |
| 2384 | char* pld = (char*)(&(localdata[1])); |
| 2385 | const FABio& fio = FArrayBox::getFABio(); |
| 2386 | for (MFIter mfi(mf); mfi.isValid(); ++mfi) |
| 2387 | { |
| 2388 | std::memcpy(pld, &total_bytes, sizeof(int64_t)); |
| 2389 | pld += sizeof(int64_t); |
| 2390 | |
| 2391 | const FArrayBox& fab = mf[mfi]; |
| 2392 | const Box& bx = mfi.validbox(); |
| 2393 | |
| 2394 | std::stringstream hss; |
| 2395 | FArrayBox valid_fab(bx, ncomp, false); |
| 2396 | FArrayBox const& header_fab = (strip_ghost) ? valid_fab : fab; |
| 2397 | fio.write_header(hss, header_fab, ncomp); |
| 2398 | total_bytes += static_cast<std::streamoff>(hss.tellp()); |
| 2399 | total_bytes += header_fab.size() * whichRD.numBytes(); |
| 2400 | |
| 2401 | // compute min and max |
| 2402 | for (int icomp = 0; icomp < ncomp; ++icomp) { |
nothing calls this directly
no test coverage detected