Commit 3b77dee3 authored by Thomas Steinreiter's avatar Thomas Steinreiter
Browse files

removed restriction that the world dimensions must be even divisible by the grid dimensions

parent 49b735c2
...@@ -59,27 +59,37 @@ void FileIO::WriteHeader(const HeaderInfo& header, const std::string& path, ...@@ -59,27 +59,37 @@ void FileIO::WriteHeader(const HeaderInfo& header, const std::string& path,
MPI_File_close(&fh); MPI_File_close(&fh);
} }
Size FileIO::GetTileSize(Size globalSize, Size gridSize) { SizeCoord FileIO::GetTileSizeCoord(Size globalSize, Size gridSize,
const auto tileSizeCols = globalSize.Cols / gridSize.Cols; std::size_t rank) {
const auto tileSizeRows = globalSize.Rows / gridSize.Rows; const auto tileX = rank % gridSize.Cols;
return {tileSizeCols, tileSizeRows}; const auto tileY = rank / gridSize.Cols;
const auto xBeg = (tileX + 0) * globalSize.Cols / gridSize.Cols;
const auto xEnd = (tileX + 1) * globalSize.Cols / gridSize.Cols;
const auto yBeg = (tileY + 0) * globalSize.Rows / gridSize.Rows;
const auto yEnd = (tileY + 1) * globalSize.Rows / gridSize.Rows;
const auto tileSizeCols = xEnd - xBeg;
const auto tileSizeRows = yEnd - yBeg;
return {{tileSizeCols, tileSizeRows}, {xBeg, yBeg}};
} }
FileIO::Tile::Tile(const std::string& path, HeaderInfo header, Size gridSize, FileIO::Tile::Tile(const std::string& path, HeaderInfo header, Size gridSize,
std::size_t rank, State* buf) std::size_t rank, State* buf)
: _path(path), _headerLength(header.HeaderLength), : _path(path), _headerLength(header.HeaderLength),
_srcSize(header.GlobalSize), _gridSize(gridSize), _rank(rank), _buf(buf), _srcSize(header.GlobalSize), _gridSize(gridSize), _rank(rank), _buf(buf),
_tileSize(FileIO::GetTileSize(header.GlobalSize, gridSize)), // _tileSizeCoord(
_tileX(rank % gridSize.Cols), // FileIO::GetTileSizeCoord(header.GlobalSize, gridSize, rank)),
_tileY(rank / gridSize.Cols), // _tileSize(_tileSizeCoord.Size), _tileCoord(_tileSizeCoord.Coord),
_tileType( _tileType(
MpiSubarray({{header.GlobalSize.Rows, _tileSize.Rows, 0}, MpiSubarray({{header.GlobalSize.Rows, _tileSize.Rows, 0},
{header.GlobalSize.Cols + LF, _tileSize.Cols, 0}})), {header.GlobalSize.Cols + LF, _tileSize.Cols, 0}})),
_bufType(MpiSubarray({{_tileSize.Rows + 2, _tileSize.Rows, 1}, _bufType(MpiSubarray({{_tileSize.Rows + 2, _tileSize.Rows, 1},
{_tileSize.Cols + 2, _tileSize.Cols, 1}})), {_tileSize.Cols + 2, _tileSize.Cols, 1}})),
_displ(header.HeaderLength + _displ(header.HeaderLength +
(header.GlobalSize.Cols + LF) * _tileSize.Rows * _tileY +
_tileSize.Cols * _tileX) {} (header.GlobalSize.Cols + LF) * _tileCoord.Y + _tileCoord.X) {}
void FileIO::Tile::Read() { void FileIO::Tile::Read() {
MPI_File file; MPI_File file;
...@@ -106,21 +116,15 @@ void FileIO::Tile::Write() const { ...@@ -106,21 +116,15 @@ void FileIO::Tile::Write() const {
// ranks actually write line feeds // ranks actually write line feeds
// are we a rightMost tile? // are we a rightMost tile?
const auto rightMost = _tileX == _gridSize.Cols - 1; const auto rightMost = _tileCoord.X == _gridSize.Cols - 1;
const auto bottomMost = _tileY == _gridSize.Rows - 1; const auto noLfNeeded = rightMost ? _tileSize.Rows : 0;
const auto noLfNeeded = rightMost ? //
(bottomMost ? //
_tileSize.Rows - 1 //
: _tileSize.Rows) //
: 0; //
const auto lfType = MpiSubarray( // subsize must be > 0 const auto lfType = MpiSubarray( // subsize must be > 0
{{_srcSize.Rows, std::max<std::size_t>(noLfNeeded, 1), 0}, {{_srcSize.Rows, std::max<std::size_t>(noLfNeeded, 1), 0},
{_srcSize.Cols + LF, 1, 0}}); {_srcSize.Cols + LF, 1, 0}});
const std::vector<char> lfs(noLfNeeded, '\n'); const std::vector<char> lfs(noLfNeeded, '\n');
const auto lfDisp = _headerLength + const auto lfDisp = _headerLength + (_srcSize.Cols + LF) * _tileCoord.Y +
(_srcSize.Cols + LF) * _tileSize.Rows * _tileY + _tileCoord.X + _tileSize.Cols;
_srcSize.Cols;
MPI_File_set_view(file, lfDisp, MPI_CHAR, lfType.type(), "native", MPI_File_set_view(file, lfDisp, MPI_CHAR, lfType.type(), "native",
MPI_INFO_NULL); MPI_INFO_NULL);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#include <tuple>
#include "MpiEnvironment.hpp" #include "MpiEnvironment.hpp"
#include "MpiSubarray.hpp" #include "MpiSubarray.hpp"
...@@ -19,7 +20,7 @@ struct FileIO { ...@@ -19,7 +20,7 @@ struct FileIO {
static void WriteHeader(const HeaderInfo& header, const std::string& path, static void WriteHeader(const HeaderInfo& header, const std::string& path,
const MpiEnvironment& env); const MpiEnvironment& env);
static Size GetTileSize(Size globalSize, Size gridSize); static SizeCoord GetTileSizeCoord(Size globalSize, Size gridSize, std::size_t rank);
// helper class to share commonly used data for reading and writing // helper class to share commonly used data for reading and writing
class Tile { class Tile {
...@@ -31,9 +32,9 @@ struct FileIO { ...@@ -31,9 +32,9 @@ struct FileIO {
const std::size_t _rank; const std::size_t _rank;
State* _buf; State* _buf;
const SizeCoord _tileSizeCoord;
const Size _tileSize; const Size _tileSize;
const std::size_t _tileX; const Coord _tileCoord;
const std::size_t _tileY;
const MpiSubarray _tileType; const MpiSubarray _tileType;
const MpiSubarray _bufType; const MpiSubarray _bufType;
const std::size_t _displ; const std::size_t _displ;
......
...@@ -11,13 +11,8 @@ ...@@ -11,13 +11,8 @@
Tile::Tile(const Configuration& cfg, const MpiEnvironment& env) Tile::Tile(const Configuration& cfg, const MpiEnvironment& env)
: _env(env), _cfg(cfg), _header(FileIO::ReadHeader(cfg.InputFilePath)), // : _env(env), _cfg(cfg), _header(FileIO::ReadHeader(cfg.InputFilePath)), //
_tileSize(FileIO::GetTileSize(_header.GlobalSize, cfg.Grid)), _tileSize(FileIO::GetTileSizeCoord(_header.GlobalSize, cfg.Grid, env.worldRank()).Size),
_modelWidth(_tileSize.Cols + 2) { _modelWidth(_tileSize.Cols + 2) {
if ((_header.GlobalSize.Cols % _tileSize.Cols) != 0 ||
(_header.GlobalSize.Rows % _tileSize.Rows) != 0) {
MpiReportErrorAbort(
"Wireworld size is not even divisible by the grid size.");
}
const auto bufsize = (_tileSize.Cols + 2) * (_tileSize.Rows + 2); const auto bufsize = (_tileSize.Cols + 2) * (_tileSize.Rows + 2);
_memoryA.resize(bufsize); _memoryA.resize(bufsize);
_memoryB.resize(bufsize); _memoryB.resize(bufsize);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <cstddef> #include <cstddef>
#include <string> #include <string>
struct Size { struct Size {
std::size_t Cols{}; std::size_t Cols{};
std::size_t Rows{}; std::size_t Rows{};
...@@ -10,6 +11,12 @@ struct Size { ...@@ -10,6 +11,12 @@ struct Size {
struct Coord { struct Coord {
std::size_t X{}; std::size_t X{};
std::size_t Y{}; std::size_t Y{};
Coord(std::size_t x, std::size_t y) : X(x), Y(y) {}
};
struct SizeCoord {
::Size Size;
::Coord Coord;
}; };
[[noreturn]] void MpiReportErrorAbort(const std::string& err); [[noreturn]] void MpiReportErrorAbort(const std::string& err);
\ No newline at end of file
This diff is collapsed.
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