Skip to content

Commit

Permalink
Finish de-templating sim master, make RBC cope and move path manager …
Browse files Browse the repository at this point in the history
…into config where it belongs
  • Loading branch information
rupertnash committed Jun 4, 2024
1 parent 1475365 commit aa88ca3
Show file tree
Hide file tree
Showing 46 changed files with 193 additions and 261 deletions.
4 changes: 3 additions & 1 deletion Code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ if (HEMELB_USE_DEBUGGER)
set(CMAKE_BUILD_TYPE Debug)
endif()

add_executable(${HEMELB_EXECUTABLE} SimulationMaster.cc main.cc)
add_library(hemelb_sim OBJECT SimulationMaster.cc)
list(APPEND heme_libraries hemelb_sim)
add_executable(${HEMELB_EXECUTABLE} main.cc)
codesign(${HEMELB_EXECUTABLE})

include_directories(${PROJECT_SOURCE_DIR})
Expand Down
16 changes: 1 addition & 15 deletions Code/SimulationMaster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,9 @@ namespace hemelb
* Initialises member variables including the network topology
* object.
*/
SimulationMaster::SimulationMaster(configuration::CommandLine & options,
const net::IOCommunicator& ioComm) :
SimulationMaster::SimulationMaster(const net::IOCommunicator& ioComm) :
build_info(), ioComms(ioComm.Duplicate()), communicationNet(ioComms)
{
// Start the main timer!
timings.total().Start();

fileManager = std::make_shared<io::PathManager>(options,
IsCurrentProcTheIOProc(),
GetProcessorCount());
log::Logger::Log<log::Info, log::Singleton>("Reading configuration from %s", fileManager->GetInputFile().c_str());
// Convert XML to configuration
simConfig = configuration::SimConfig::New(fileManager->GetInputFile());
// Use it to initialise self
auto builder = configuration::SimBuilder(simConfig);
log::Logger::Log<log::Info, log::Singleton>("Beginning Initialisation.");
builder.build<>(*this);
}

/// Destructor for the SimulationMaster class.
Expand Down
7 changes: 3 additions & 4 deletions Code/SimulationMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "util/UnitConverter.h"
#include "configuration/SimConfig.h"
#include "configuration/CommandLine.h"
#include "io/PathManager.h"
#include "configuration/PathManager.h"
#include "reporting/Reporter.h"
#include "reporting/Timers.h"
#include "reporting/BuildInfo.h"
Expand Down Expand Up @@ -53,7 +53,7 @@ namespace hemelb
std::shared_ptr<lb::LBMBase> latticeBoltzmannModel;
std::shared_ptr<geometry::neighbouring::NeighbouringDataManager> neighbouringDataManager;

std::shared_ptr<io::PathManager> fileManager;
std::shared_ptr<configuration::PathManager> fileManager;
std::shared_ptr<reporting::Reporter> reporter;

std::shared_ptr<lb::SimulationState> simulationState;
Expand All @@ -77,9 +77,8 @@ namespace hemelb
std::shared_ptr<net::phased::StepManager> stepManager;
std::shared_ptr<net::phased::NetConcern> netConcern;

SimulationMaster(const net::IOCommunicator& ioComm);
public:
SimulationMaster(configuration::CommandLine &options,
const net::IOCommunicator& ioComms);
virtual ~SimulationMaster();

void Abort();
Expand Down
1 change: 1 addition & 0 deletions Code/configuration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

add_library(hemelb_configuration OBJECT
CommandLine.cc
PathManager.cc
SimConfig.cc
SimBuilder.cc
SimConfigReader.cc
Expand Down
4 changes: 2 additions & 2 deletions Code/io/PathManager.cc → Code/configuration/PathManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// file AUTHORS. This software is provided under the terms of the
// license in the file LICENSE.

#include "io/PathManager.h"
#include "configuration/PathManager.h"

#include "Exception.h"
#include "configuration/CommandLine.h"

namespace fs = std::filesystem;
namespace hemelb::io
namespace hemelb::configuration
{

PathManager::PathManager(const configuration::CommandLine & commandLine, const bool & io,
Expand Down
12 changes: 3 additions & 9 deletions Code/io/PathManager.h → Code/configuration/PathManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// file AUTHORS. This software is provided under the terms of the
// license in the file LICENSE.

#ifndef HEMELB_IO_PATHMANAGER_H
#define HEMELB_IO_PATHMANAGER_H
#ifndef HEMELB_CONFIGURATION_PATHMANAGER_H
#define HEMELB_CONFIGURATION_PATHMANAGER_H

#include <filesystem>
#include <string>
Expand All @@ -14,12 +14,6 @@ namespace hemelb::configuration
{
class CommandLine;
class SimConfig;
}

namespace hemelb::io
{
// Forward declare the Writer
namespace writers { class Writer; }

/**
* Manage the input and output file system locations for HemeLB reports, extracted data, and input xml.
Expand Down Expand Up @@ -82,4 +76,4 @@ namespace hemelb::io

}

#endif //HEMELB_IO_PATHMANAGER_H
#endif //HEMELB_CONFIGURATION_PATHMANAGER_H
2 changes: 1 addition & 1 deletion Code/configuration/SimBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ namespace hemelb::configuration {
}

std::shared_ptr<reporting::Reporter> SimBuilder::BuildReporter(
io::PathManager const& fileManager,
PathManager const& fileManager,
std::vector<reporting::Reportable*>const& reps
) const {
auto reporter = std::make_shared<reporting::Reporter>(fileManager.GetReportPath(),
Expand Down
31 changes: 27 additions & 4 deletions Code/configuration/SimBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ namespace hemelb::configuration {
std::shared_ptr<util::UnitConverter> unit_converter;

public:
template <typename TraitsT>
static std::unique_ptr<SimulationMaster> CreateSim(
CommandLine const& options,
net::IOCommunicator const& ioComms
) {
auto ans = std::unique_ptr<SimulationMaster>(new SimulationMaster(ioComms));
// Start the main timer!
ans->timings.total().Start();

ans->fileManager = std::make_shared<configuration::PathManager>(
options,
ioComms.OnIORank(),
ioComms.Size()
);
auto&& infile = ans->fileManager->GetInputFile();
log::Logger::Log<log::Info, log::Singleton>("Reading configuration from %s", infile.c_str());
// Convert XML to configuration
ans->simConfig = configuration::SimConfig::New(infile);
// Use it to initialise self
auto builder = configuration::SimBuilder(ans->simConfig);
log::Logger::Log<log::Info, log::Singleton>("Beginning Initialisation.");
builder.build<TraitsT>(*ans);
return ans;
}

explicit SimBuilder(SimConfig const& conf, bool construct_unit_converter = true);
virtual ~SimBuilder() = default;

Expand Down Expand Up @@ -111,7 +136,7 @@ namespace hemelb::configuration {
) const;

[[nodiscard]] std::shared_ptr<reporting::Reporter> BuildReporter(
io::PathManager const& fileManager,
PathManager const& fileManager,
std::vector<reporting::Reportable*> const & reps
) const;
};
Expand Down Expand Up @@ -299,8 +324,6 @@ namespace hemelb::configuration {
[[nodiscard]] std::shared_ptr<net::IteratedAction> SimBuilder::BuildCellController(SimulationMaster const& control, reporting::Timers& timings) const {
if (config.HasRBCSection()) {
#ifdef HEMELB_BUILD_RBC
using traitsType = typename T::Traits;

auto ccb = redblood::CellControllerBuilder(unit_converter);

auto& ioComms = control.ioComms;
Expand All @@ -324,4 +347,4 @@ namespace hemelb::configuration {
return {};
}
}
#endif
#endif
1 change: 0 additions & 1 deletion Code/extraction/PropertyActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#define HEMELB_EXTRACTION_PROPERTYACTOR_H

#include "extraction/PropertyWriter.h"
#include "io/PathManager.h"
#include "lb/MacroscopicPropertyCache.h"
#include "lb/SimulationState.h"
#include "net/IteratedAction.h"
Expand Down
1 change: 0 additions & 1 deletion Code/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ endif()

add_library(hemelb_io OBJECT
FILE.cc
PathManager.cc
writers/AsciiFileWriter.cc writers/AsciiStreamWriter.cc
readers/XdrFileReader.cc
readers/XdrMemReader.cc
Expand Down
2 changes: 1 addition & 1 deletion Code/io/Checkpointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <filesystem>
#include <memory>

#include "io/PathManager.h"
#include "configuration/SimConfig.h"
#include "io/TimePattern.h"
#include "lb/SimulationState.h"
#include "net/IteratedAction.h"
Expand Down
6 changes: 3 additions & 3 deletions Code/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "net/mpi.h"
#include "net/IOCommunicator.h"
#include "configuration/CommandLine.h"
#include "configuration/SimBuilder.h"
#include "io/ensure_hexfloat.h"
#include "debug.h"
#include "SimulationMaster.h"

int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -40,10 +40,10 @@ int main(int argc, char *argv[])
debug::Init(options.GetDebug(), argv[0], commWorld);

// Prepare main simulation object...
SimulationMaster master(options, hemelbCommunicator);
auto master = configuration::SimBuilder::CreateSim<Traits<>>(options, hemelbCommunicator);

// ..and run it.
master.RunSimulation();
master->RunSimulation();
}

// Interpose this catch to print usage before propagating the error.
Expand Down
2 changes: 1 addition & 1 deletion Code/multiscale/MultiscaleSimulationMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ namespace hemelb::multiscale
}
}

void DoTimeStep()
void DoTimeStep() override
{
bool advance = intercomms.DoMultiscale(GetState().GetTime());
log::Logger::Log<log::Info, log::Singleton>("At time step %i, should advance %i, time %f",
Expand Down
1 change: 1 addition & 0 deletions Code/net/IOCommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace hemelb::net {
public:
static constexpr int IO_RANK = 0;

IOCommunicator() = default;
explicit IOCommunicator(const MpiCommunicator& comm);

inline bool OnIORank() const {
Expand Down
2 changes: 1 addition & 1 deletion Code/redblood/CellArmy.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ namespace hemelb
log::Logger::Log<log::Info, log::OnePerCore>(message.str());

cellDnC.remove(*i_current);
cells.erase(i_current);
auto const numErased = nodeDistributions.erase((*i_current)->GetTag());
cells.erase(i_current);
assert(numErased == 1);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Code/redblood/CellControllerBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "redblood/CellControllerBuilder.h"

#include "io/PathManager.h"
#include "configuration/PathManager.h"
#include "redblood/CellIO.h"
#include "redblood/FaderCell.h"
#include "redblood/MeshIO.h"
Expand Down Expand Up @@ -350,7 +350,7 @@ namespace hemelb::redblood {
CellChangeListener CellControllerBuilder::build_full_cell_output(
configuration::CellOutputConfig const& conf,
std::shared_ptr<lb::SimulationState const> simState,
std::shared_ptr<io::PathManager const> fileManager,
std::shared_ptr<configuration::PathManager const> fileManager,
net::IOCommunicator const& ioComms
) const {
auto conv = conf.physical_units ? unit_converter : nullptr;
Expand All @@ -360,7 +360,7 @@ namespace hemelb::redblood {
CellChangeListener CellControllerBuilder::build_summary_cell_output(
configuration::CellOutputConfig const& conf,
std::shared_ptr<lb::SimulationState const> simState,
std::shared_ptr<io::PathManager const> fileManager,
std::shared_ptr<configuration::PathManager const> fileManager,
net::IOCommunicator const& ioComms
) const {
auto conv = conf.physical_units ? unit_converter : nullptr;
Expand Down
8 changes: 4 additions & 4 deletions Code/redblood/CellControllerBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "redblood/CellController.h"
#include "redblood/RBCInserter.h"

namespace hemelb::io { class PathManager; }
namespace hemelb::configuration { class PathManager; }

namespace hemelb::redblood {

Expand Down Expand Up @@ -86,13 +86,13 @@ namespace hemelb::redblood {
CellChangeListener build_full_cell_output(
configuration::CellOutputConfig const& conf,
std::shared_ptr<lb::SimulationState const> simState,
std::shared_ptr<io::PathManager const> fileManager,
std::shared_ptr<configuration::PathManager const> fileManager,
net::IOCommunicator const& ioComms
) const;
CellChangeListener build_summary_cell_output(
configuration::CellOutputConfig const& conf,
std::shared_ptr<lb::SimulationState const> simState,
std::shared_ptr<io::PathManager const> fileManager,
std::shared_ptr<configuration::PathManager const> fileManager,
net::IOCommunicator const& ioComms
) const;

Expand All @@ -104,7 +104,7 @@ namespace hemelb::redblood {
CountedIoletView const& inlets,
CountedIoletView const& outlets,
std::shared_ptr<lb::SimulationState const> simState,
std::shared_ptr<io::PathManager const> fileManager
std::shared_ptr<configuration::PathManager const> fileManager
) {
log::Logger::Log<log::Info, log::Singleton>("Initialising RBCs.");
timings.cellInitialisation().Start();
Expand Down
9 changes: 5 additions & 4 deletions Code/redblood/CellIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <cstring>
#include <boost/uuid/uuid_io.hpp>

#include "configuration/PathManager.h"
#include "io/formats/rbc.h"
#include "io/PathManager.h"
#include "io/writers/XdrWriter.h"
#include "io/readers/XdrFileReader.h"
#include "io/readers/XdrMemReader.h"
Expand All @@ -21,6 +21,7 @@
#include "redblood/FaderCell.h"
#include "redblood/MeshIO.h"
#include "util/Iterator.h"
#include "util/span.h"

namespace hemelb::redblood {

Expand Down Expand Up @@ -74,7 +75,7 @@ namespace hemelb::redblood {
CellBarycentreOutput::CellBarycentreOutput(hemelb::LatticeTimeStep period,
std::shared_ptr<const util::UnitConverter> unitConverter,
std::shared_ptr<const lb::SimulationState> simState,
std::shared_ptr<const io::PathManager> fileManager,
std::shared_ptr<const configuration::PathManager> fileManager,
net::IOCommunicator comms) :
CellOutputBase{
period, std::move(unitConverter), std::move(simState), std::move(fileManager), comms
Expand Down Expand Up @@ -134,7 +135,7 @@ namespace hemelb::redblood {
const std::size_t local_write_start = ioComms.OnIORank() ? 0 : (fmt::rbc::header_size + n_cells_before_me * fmt::rbc::row_size);

auto bary_file = net::MpiFile::Open(ioComms, bary_filename, MPI_MODE_WRONLY | MPI_MODE_CREATE | MPI_MODE_EXCL);
bary_file.WriteAt(local_write_start, buffer);
bary_file.WriteAt(local_write_start, to_const_span(buffer));
bary_file.Close();
}

Expand Down Expand Up @@ -172,7 +173,7 @@ namespace hemelb::redblood {
auto read_size = n * fmt::rbc::row_size;

std::vector<std::byte> read_buf(read_size);
inputFile.ReadAt(read_start, read_buf);
inputFile.ReadAt(read_start, to_span(read_buf));
auto reader = io::XdrMemReader(read_buf);
std::vector<row> ans(n);
boost::uuids::string_generator gen;
Expand Down
6 changes: 3 additions & 3 deletions Code/redblood/CellIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "net/IOCommunicator.h"
#include "redblood/types_fwd.h"

namespace hemelb::io { class PathManager; }
namespace hemelb::configuration { class PathManager; }
namespace hemelb::lb { class SimulationState; }
namespace hemelb::util { class UnitConverter; }

Expand All @@ -30,7 +30,7 @@ namespace hemelb::redblood {
// nullptr => use lattice units
std::shared_ptr<util::UnitConverter const> unitConverter;
std::shared_ptr<lb::SimulationState const> simState;
std::shared_ptr<io::PathManager const> fileManager;
std::shared_ptr<configuration::PathManager const> fileManager;
net::IOCommunicator ioComms;
};

Expand All @@ -46,7 +46,7 @@ namespace hemelb::redblood {
LatticeTimeStep period,
std::shared_ptr<util::UnitConverter const> unitConverter,
std::shared_ptr<lb::SimulationState const> simState,
std::shared_ptr<io::PathManager const> fileManager,
std::shared_ptr<configuration::PathManager const> fileManager,
net::IOCommunicator comms
);

Expand Down
Loading

0 comments on commit aa88ca3

Please sign in to comment.