void LocalScalar3D<real>::CalcStats(BlockManager& blockManager) { BlockBase* block0 = blockManager.getBlock(0); ::Vec3i size = block0->getSize(); real* pData0 = GetBlockData(block0); int m0 = vc + (size.x+2*vc)*(vc + (size.y+2*vc)*vc); sum_l = 0.0; max_l = pData0[m0]; min_l = pData0[m0]; absmax_l = abs(pData0[m0]); absmin_l = abs(pData0[m0]); for (int id = 0; id < blockManager.getNumBlock(); ++id) { BlockBase* block = blockManager.getBlock(id); ::Vec3i size = block->getSize(); ::Vec3d origin = block->getOrigin(); ::Vec3d blockSize = block->getBlockSize(); ::Vec3d cellSize = block->getCellSize(); int sz[3] = {size.x, size.y, size.z}; int g[1] = {vc}; real dx = cellSize.x; real* pData = GetBlockData(block); real sum_b = 0.0; real max_b = 0.0; real min_b = 0.0; real absmax_b = 0.0; real absmin_b = 0.0; sf3d_calc_stats_( &sum_b, &max_b, &min_b, &absmax_b, &absmin_b, pData, sz, g); sum_l += sum_b; if( max_b > max_l ) { max_l = max_b; } if( min_b < min_l ) { min_l = min_b; } if( absmax_b > absmax_l ) { absmax_l = absmax_b; } if( absmin_b < absmin_l ) { absmin_l = absmin_b; } } allreduce_(&sum_g, &sum_l); allreduce_max_(&max_g, &max_l); allreduce_min_(&min_g, &min_l); allreduce_max_(&absmax_g, &absmax_l); allreduce_min_(&absmin_g, &absmin_l); }
bool SectorReader::Read(u64 offset, u64 size, u8* out_ptr) { u64 startingBlock = offset / m_blocksize; u64 remain = size; int positionInBlock = (int)(offset % m_blocksize); u64 block = startingBlock; while (remain > 0) { // Check if we are ready to do a large block read. > instead of >= so we don't bother if remain is only one block. if (positionInBlock == 0 && remain > (u64)m_blocksize) { u64 num_blocks = remain / m_blocksize; ReadMultipleAlignedBlocks(block, num_blocks, out_ptr); block += num_blocks; out_ptr += num_blocks * m_blocksize; remain -= num_blocks * m_blocksize; continue; } u32 toCopy = m_blocksize - positionInBlock; if (toCopy >= remain) { const u8* data = GetBlockData(block); if (!data) return false; // Yay, we are done! memcpy(out_ptr, data + positionInBlock, (size_t)remain); return true; } else { const u8* data = GetBlockData(block); if (!data) return false; memcpy(out_ptr, data + positionInBlock, toCopy); out_ptr += toCopy; remain -= toCopy; positionInBlock = 0; block++; } } return true; }
void LocalScalar3D<real>::Dump(BlockManager& blockManager, const int step, const char* label) { ImposeBoundaryCondition(blockManager); MPI::Intracomm comm = blockManager.getCommunicator(); ostringstream ossFileNameTime; ossFileNameTime << "./BIN/"; mkdir(ossFileNameTime.str().c_str(), 0755); #ifdef _BLOCK_IS_LARGE_ #else #endif for (int id = 0; id < blockManager.getNumBlock(); ++id) { BlockBase* block = blockManager.getBlock(id); ::Vec3i size = block->getSize(); Vec3d origin = block->getOrigin(); Vec3d blockSize = block->getBlockSize(); Vec3d cellSize = block->getCellSize(); int level = block->getLevel(); ostringstream ossFileName; ossFileName << "./BIN/"; ossFileName << "dump-"; ossFileName << label; ossFileName << "-"; ossFileName.width(5); ossFileName.setf(ios::fixed); ossFileName.fill('0'); ossFileName << comm.Get_rank(); ossFileName << "-"; ossFileName.width(5); ossFileName.setf(ios::fixed); ossFileName.fill('0'); ossFileName << id; ossFileName << "-"; ossFileName.width(10); ossFileName.setf(ios::fixed); ossFileName.fill('0'); ossFileName << step; ossFileName << ".bin"; int cx = size.x + 2*vc; int cy = size.y + 2*vc; int cz = size.z + 2*vc; int iNE = 1; real* pData = GetBlockData(block); ofstream ofs; ofs.open(ossFileName.str().c_str(), ios::out | ios::binary); ofs.write((char*)&size.x, sizeof(int)); ofs.write((char*)&size.y, sizeof(int)); ofs.write((char*)&size.z, sizeof(int)); ofs.write((char*)&vc , sizeof(int)); ofs.write((char*)&iNE , sizeof(int)); ofs.write((char*)pData , sizeof(real)*cx*cy*cz); ofs.close(); } }
bool SectorReader::ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 *out_ptr) { for (u64 i = 0; i < num_blocks; i++) { const u8 *data = GetBlockData(block_num + i); if (!data) return false; memcpy(out_ptr + i * m_blocksize, data, m_blocksize); } return true; }
void LocalScalar3D<real>::Load3(BlockManager& blockManager, const int step, const char* label, Partition* partition, int myrank) { MPI::Intracomm comm = blockManager.getCommunicator(); #ifdef _BLOCK_IS_LARGE_ #else #endif for (int id = 0; id < blockManager.getNumBlock(); ++id) { ostringstream ossFileName; ossFileName << "./BIN/"; ossFileName << "dump-"; ossFileName << label; ossFileName << "-"; ossFileName.width(5); ossFileName.setf(ios::fixed); ossFileName.fill('0'); ossFileName << id + partition->getStart(myrank); ossFileName << "-"; ossFileName.width(10); ossFileName.setf(ios::fixed); ossFileName.fill('0'); ossFileName << step; ossFileName << ".bin"; int nx = 0; int ny = 0; int nz = 0; int nv = 0; int ne = 0; int nb = 0; ifstream ifs; ifs.open(ossFileName.str().c_str(), ios::in | ios::binary); ifs.read((char*)&nx, sizeof(int)); ifs.read((char*)&ny, sizeof(int)); ifs.read((char*)&nz, sizeof(int)); ifs.read((char*)&nv, sizeof(int)); ifs.read((char*)&ne, sizeof(int)); ifs.read((char*)&nb, sizeof(int)); int cx = nx + 2*nv; int cy = ny + 2*nv; int cz = nz + 2*nv; BlockBase* block = blockManager.getBlock(id); ::Vec3i size = block->getSize(); real* pData = GetBlockData(block); real *pDataS = new real [cx*cy*cz]; if( nx == size.x && ny == size.y && nz == size.z && nv == vc && ne == 1 && nb == blockManager.getNumBlock() ) { ifs.read((char*)pData, sizeof(real)*cx*cy*cz); } else if( 2*nx == size.x && 2*ny == size.y && 2*nz == size.z && nv == vc && ne == 1 && nb == blockManager.getNumBlock() ) { ifs.read((char*)pDataS, sizeof(real)*cx*cy*cz); int sz[3] = {2*nx, 2*ny, 2*nz}; sf3d_copy_x2_( (real*)pData, (real*)pDataS, (int*)sz, (int*)&vc); } else { Exit(0); } ifs.close(); delete [] pDataS; } ImposeBoundaryCondition(blockManager); }