Commit 71ae80c3 authored by Thomas Steinreiter's avatar Thomas Steinreiter
Browse files

fixed bug: write correct line endings

parent cf6ca9b8
......@@ -59,8 +59,8 @@ void FileIO::WriteHeader(const HeaderInfo& header, const std::string& path,
MPI_File_close(&fh);
}
SizeCoord FileIO::GetTileSizeCoord(Size globalSize, Size procsSize,
std::size_t rank) {
TileInfo FileIO::GetTileInfo(Size globalSize, Size procsSize,
std::size_t rank) {
const auto tileX = rank % procsSize.Cols;
const auto tileY = rank / procsSize.Cols;
......@@ -72,16 +72,16 @@ SizeCoord FileIO::GetTileSizeCoord(Size globalSize, Size procsSize,
const auto tileSizeCols = xEnd - xBeg;
const auto tileSizeRows = yEnd - yBeg;
return {{tileSizeCols, tileSizeRows}, {xBeg, yBeg}};
return {{tileSizeCols, tileSizeRows}, {xBeg, yBeg}, {tileX, tileY}};
}
FileIO::Tile::Tile(const std::string& path, HeaderInfo header, Size procsSize,
std::size_t rank, State* buf)
: _path(path), _headerLength(header.HeaderLength),
_srcSize(header.GlobalSize), _procsSize(procsSize), _rank(rank), _buf(buf),
_tileSizeCoord(
FileIO::GetTileSizeCoord(header.GlobalSize, procsSize, rank)),
_tileSize(_tileSizeCoord.Size), _tileCoord(_tileSizeCoord.Coord),
_srcSize(header.GlobalSize), _procsSize(procsSize), _rank(rank),
_buf(buf),
_tileInfo(FileIO::GetTileInfo(header.GlobalSize, procsSize, rank)),
_tileSize(_tileInfo.Size), _tileCoord(_tileInfo.GlobalCoord),
_tileType(
MpiSubarray({{header.GlobalSize.Rows, _tileSize.Rows, 0},
{header.GlobalSize.Cols + LF, _tileSize.Cols, 0}})),
......@@ -116,15 +116,16 @@ void FileIO::Tile::Write() const {
// ranks actually write line feeds
// are we a rightMost tile?
const auto rightMost = _tileCoord.X == _procsSize.Cols - 1;
const auto rightMost = _tileInfo.ProcCoord.X == _procsSize.Cols - 1;
const auto noLfNeeded = rightMost ? _tileSize.Rows : 0;
const auto lfType = MpiSubarray( // subsize must be > 0
{{_srcSize.Rows, std::max<std::size_t>(noLfNeeded, 1), 0},
{_srcSize.Cols + LF, 1, 0}});
const std::vector<char> lfs(noLfNeeded, '\n');
const auto lfDisp = _headerLength + (_srcSize.Cols + LF) * _tileCoord.Y +
_tileCoord.X + _tileSize.Cols;
const auto lfDisp = _headerLength +
_tileInfo.GlobalCoord.Y * (_srcSize.Cols + LF) +
_srcSize.Cols;
MPI_File_set_view(file, lfDisp, MPI_CHAR, lfType.type(), "native",
MPI_INFO_NULL);
......
......@@ -20,7 +20,8 @@ struct FileIO {
static void WriteHeader(const HeaderInfo& header, const std::string& path,
const MpiEnvironment& env);
static SizeCoord GetTileSizeCoord(Size globalSize, Size procsSize, std::size_t rank);
static TileInfo GetTileInfo(Size globalSize, Size procsSize,
std::size_t rank);
// helper class to share commonly used data for reading and writing
class Tile {
......@@ -32,7 +33,7 @@ struct FileIO {
const std::size_t _rank;
State* _buf;
const SizeCoord _tileSizeCoord;
const TileInfo _tileInfo;
const Size _tileSize;
const Coord _tileCoord;
const MpiSubarray _tileType;
......
......@@ -11,7 +11,7 @@
Tile::Tile(const Configuration& cfg, const MpiEnvironment& env)
: _env(env), _cfg(cfg), _header(FileIO::ReadHeader(cfg.InputFilePath)), //
_tileSize(FileIO::GetTileSizeCoord(_header.GlobalSize, cfg.Procs, env.worldRank()).Size),
_tileSize(FileIO::GetTileInfo(_header.GlobalSize, cfg.Procs, env.worldRank()).Size),
_modelWidth(_tileSize.Cols + 2) {
const auto bufsize = (_tileSize.Cols + 2) * (_tileSize.Rows + 2);
_memoryA.resize(bufsize);
......
......@@ -14,9 +14,10 @@ struct Coord {
Coord(std::size_t x, std::size_t y) : X(x), Y(y) {}
};
struct SizeCoord {
struct TileInfo {
::Size Size;
::Coord Coord;
::Coord GlobalCoord;
::Coord ProcCoord;
};
[[noreturn]] void MpiReportErrorAbort(const std::string& err);
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment