Commit 675569f0 authored by Thomas Steinreiter's avatar Thomas Steinreiter
Browse files

added invalid newline char detection, cleanup

parent 8a205098
#include "FileIO.hpp"
#include <algorithm>
#include <array>
#include <fstream>
#include <iomanip>
#include <array>
#include <iostream>
#include <sstream>
......@@ -17,6 +17,10 @@ HeaderInfo FileIO::ReadHeader(const std::string& path) {
MPI_File_read_all(fh, buf.data(), buf.size(), MPI_CHAR, MPI_STATUS_IGNORE);
MPI_File_close(&fh);
if (std::find(std::begin(buf), std::end(buf), '\r') != std::end(buf)) {
MpiReportErrorAbort("Invalid newline character detected!");
}
// make stream from buf
std::istringstream input;
input.rdbuf()->pubsetbuf(buf.data(), buf.size());
......
......@@ -15,6 +15,8 @@ MpiEnvironment::MpiEnvironment(int& argc, char* argv[]) {
MPI_Comm_rank(MPI_COMM_WORLD, &_worldRank);
MPI_Comm_size(MPI_COMM_WORLD, &_worldSize);
_isMaster = {_worldRank == 0};
// We want the program to stop on I/O errors
MPI_File_set_errhandler(MPI_FILE_NULL, MPI_ERRORS_ARE_FATAL);
}
MpiEnvironment::~MpiEnvironment() {
if (_worldRank != -1) { MPI_Finalize(); }
......
#include <cassert>
#include <chrono>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#include "Configuration.hpp"
#include "MpiEnvironment.hpp"
......@@ -16,12 +11,12 @@ using namespace std::string_literals;
int main(int argc, char* argv[]) {
const auto& starttime = std::chrono::system_clock::now();
// we rely on the MPI implementation to correctly forward the arguments
MpiEnvironment env(argc, argv);
const auto& cfg = Configuration::parseArgs(argc, argv, env);
const auto cfg = Configuration::parseArgs(argc, argv, env);
MpiWireworld ww(env, cfg);
for (std::size_t i{0}; i < cfg.Generations; ++i) {
ww.simulateStep();
......@@ -29,6 +24,7 @@ int main(int argc, char* argv[]) {
std::cout << "iteration:" << i << '\n';
}
}
// write output file if needed
if (!cfg.OutputFilePath.empty()) { ww.write(); }
if (env.isMaster()) {
......
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