Commit 3287ff1d authored by Thomas Steinreiter's avatar Thomas Steinreiter
Browse files

* refactoring

parent 6849bfea
......@@ -4,7 +4,7 @@ PointerAlignment: Left
IndentWidth: 4
TabWidth: 4
UseTab: ForIndentation
ColumnLimit: 80
ColumnLimit: 120
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
......
......@@ -22,7 +22,7 @@ if (MPI_FOUND AND Boost_FOUND)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Weverything -Wno-missing-prototypes -Wno-padded -Wno-c++98-compat -Wno-c++98-compat-pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Weverything -Wno-missing-prototypes -Wno-covered-switch-default -Wno-switch-enum -Wno-padded -Wno-c++98-compat -Wno-c++98-compat-pedantic")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost -std=c++14 -Wall")
endif()
......
......@@ -18,10 +18,8 @@ Communicator::MpiRequest::~MpiRequest() {
}
// defines types and graph topology
Communicator::Communicator(const MpiEnvironment& env,
CommunicationMode commMode, const Size& procsSize,
const Size& tileSize)
: commMode_(commMode) {
Communicator::Communicator(const MpiEnvironment& env, const Size& procsSize,
const Size& tileSize) {
// Begin definition of basic types
MPI_Type_contiguous(static_cast<int>(tileSize.Cols), MPI_CHAR,
&haloRowType_);
......@@ -130,7 +128,6 @@ Communicator::~Communicator() {
void Communicator::swap(Communicator& first, Communicator& second) {
using std::swap;
swap(first.commMode_, second.commMode_);
swap(first.neighbors_, second.neighbors_);
swap(first.sizes_, second.sizes_);
swap(first.sendTypes_, second.sendTypes_);
......
......@@ -40,8 +40,6 @@ class Communicator {
};
protected:
CommunicationMode commMode_;
// data members for graph topology
Vector<int> neighbors_;
Vector<int> sizes_;
......@@ -58,7 +56,7 @@ class Communicator {
public:
Communicator() = default;
Communicator(const MpiEnvironment& env, CommunicationMode commMode,
Communicator(const MpiEnvironment& env,
const Size& gridSize, const Size& tileSize);
virtual ~Communicator();
void swap(Communicator& first, Communicator& second);
......
......@@ -10,29 +10,17 @@
#include <boost/format.hpp>
#include <boost/program_options.hpp>
// BEGIN helper functions to parse Communication Mode cmd args
namespace {
using namespace std::string_literals;
std::array<std::pair<std::string, CommunicationMode>, 2>
StringToCommunicationMode{{
std::make_pair("Collective"s, CommunicationMode::Collective), //
std::make_pair("P2P"s, CommunicationMode::P2P) //
}};
}
// helper function to parse Communication Mode cmd args
std::istream& operator>>(std::istream& in, CommunicationMode& comm) {
std::string buf;
in >> buf;
auto r = std::find_if(std::begin(StringToCommunicationMode),
std::end(StringToCommunicationMode),
[&](auto& t) { return t.first == buf; });
if (r == std::end(StringToCommunicationMode))
throw boost::program_options::validation_error(
boost::program_options::validation_error::invalid_option_value);
const auto& str2comm = StringToCommunicationMode();
auto r = std::find_if(std::begin(str2comm), std::end(str2comm), [&](auto& t) { return t.first == buf; });
if (r == std::end(str2comm))
throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
comm = r->second;
return in;
}
// END helper functions
auto Configuration::parseArgs(int argc, char* argv[], const MpiEnvironment& env)
-> Configuration {
......
......@@ -4,13 +4,9 @@
#include <string>
#include "MpiEnvironment.hpp"
#include "CommunicationMode.hpp"
#include "Util.hpp"
enum class CommunicationMode {
Collective, //
P2P //
};
struct Configuration {
Size Procs{};
std::string InputFilePath;
......
......@@ -8,9 +8,8 @@
#include <string>
#include <vector>
#include "CollectiveCommunicator.hpp"
#include "CommunicatorFactory.hpp"
#include "FileIO.hpp"
#include "P2PCommunicator.hpp"
#include "State.hpp"
#include "Tile.hpp"
#include "Util.hpp"
......@@ -56,7 +55,7 @@ void MpiWireworld::processArea(Coord start, Size size) {
? State::ElectronHead
: State::Conductor;
};
case State::Empty:
default:
return currentState;
}
}();
......@@ -65,17 +64,7 @@ void MpiWireworld::processArea(Coord start, Size size) {
}
MpiWireworld::MpiWireworld(const MpiEnvironment& env, const Configuration& cfg)
: tile_(Tile::Read(cfg, env)),
comm_([&]() -> std::unique_ptr<Communicator> {
switch (cfg.CommMode) {
case CommunicationMode::Collective:
return std::make_unique<CollectiveCommunicator>(
env, cfg.CommMode, cfg.Procs, tile_.tileSize());
case CommunicationMode::P2P:
return std::make_unique<P2PCommunicator>(
env, cfg.CommMode, cfg.Procs, tile_.tileSize());
}
}()) {
: tile_(Tile::Read(cfg, env)), comm_(CommunicatorFactory::Create(cfg, tile_, env)) {
comm_->Communicate(tile_.model());
}
......
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