A MetaDynamics Package
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SSAGES::ResourceHandler Class Reference

Class that handles SSAGES resources for a simulation. More...

#include <ResourceHandler.h>

Public Member Functions

 ResourceHandler (mxx::comm &&world, mxx::comm &&comm, uint walkerid, const std::vector< class Method * > &methods, class CVManager *cvmanager)
 Constructor. More...
std::string GetInput () const
MPI_Comm GetLocalComm () const
MPI_Comm GetWorldComm () const
const mxx::comm & GetLocalMxxComm () const
const mxx::comm & GetWorldMxxComm () const
uint GetWalkerID () const
uint GetNumWalkers () const
void ConfigureHook (class Hook *hook)
 ~ResourceHandler ()

Static Public Member Functions

static ResourceHandlerBuild (const Json::Value &json, const MPI_Comm &world)
 Build a new ResourceHandler from JSON. More...

Private Attributes

mxx::comm world_
 MPI communicator containing all processors.
mxx::comm comm_
 MPI communicator containing processors for specific walker.
uint walkerid_
 Walker ID for specific driver.
uint nwalkers_
 Number of walkers.
class Snapshotsnapshot_
 Snapshot of system state (pointer).
std::vector< class Method * > methods_
 Vector of advanced sampling methods.
class Loggerlogger_
 CV logger.
class CVManagercvmanager_
 Collective variable manager.
class Hookhook_
 Hook pointer.
std::vector< std::string > inputs_
 Input file vector.

Detailed Description

Class that handles SSAGES resources for a simulation.

ResourceHandler is responsible for intialzing the major components of a simulation including the engine, methods, and collective variables. It is also responsible for the lifetime of the objects it creates.

Each simulation engine must implement a driver which calls this resource handler and passes it the appropriate hook.

Definition at line 44 of file ResourceHandler.h.

Constructor & Destructor Documentation

SSAGES::ResourceHandler::ResourceHandler ( mxx::comm &&  world,
mxx::comm &&  comm,
uint  walkerid,
const std::vector< class Method * > &  methods,
class CVManager cvmanager 


worldMPI communicator containing all processors.
commMPI communicator containing walker-specific processors.
walkeridID of the walker for the current processor.
methodsVector of pointers to methods.
CVManagerPointer to CV manager.
ResourceHandler will be responsible for lifetime of methods and CV manager.

Definition at line 35 of file ResourceHandler.cpp.

References SSAGES::Hook::AddListener(), comm_, cvmanager_, hook_, logger_, methods_, SSAGES::Hook::SetCVManager(), SSAGES::Hook::SetSnapshot(), and snapshot_.

Referenced by Build().

37  :
38  world_(std::move(world)), comm_(std::move(comm)), walkerid_(walkerid), nwalkers_(1),
39  methods_(methods), cvmanager_(cvmanager), hook_(nullptr), inputs_(0)
40  {
41  snapshot_ = new Snapshot(comm_, walkerid);
42  }
std::vector< std::string > inputs_
Input file vector.
class CVManager * cvmanager_
Collective variable manager.
uint walkerid_
Walker ID for specific driver.
mxx::comm comm_
MPI communicator containing processors for specific walker.
class Snapshot * snapshot_
Snapshot of system state (pointer).
class Hook * hook_
Hook pointer.
mxx::comm world_
MPI communicator containing all processors.
std::vector< class Method * > methods_
Vector of advanced sampling methods.
uint nwalkers_
Number of walkers.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Function Documentation

ResourceHandler * SSAGES::ResourceHandler::Build ( const Json::Value &  json,
const MPI_Comm &  world 

Build a new ResourceHandler from JSON.

jsonJSON root node containing driver (and children) specifications.
worldMPI communicator containing all processors.
Pointer to newly created driver.
Object lifetime is caller's responsibility!

Definition at line 54 of file ResourceHandler.cpp.

References SSAGES::CVManager::AddCVtoMap(), SSAGES::Logger::Build(), SSAGES::CollectiveVariable::BuildCV(), SSAGES::Method::BuildMethod(), Json::Requirement::GetErrors(), Json::Requirement::HasErrors(), Json::ObjectRequirement::Parse(), ResourceHandler(), and Json::ObjectRequirement::Validate().

55  {
56  ObjectRequirement validator;
57  Value schema;
58  Reader reader;
60  // Parse and validate top level schema. This just
61  // makes sure the proper fields exist and the correct
62  // types are specified in the input files.
63  reader.parse(JsonSchema::Simulation, schema);
64  validator.Parse(schema, "#");
65  validator.Validate(json, "#");
66  if(validator.HasErrors())
67  throw BuildException(validator.GetErrors());
69  // Get number of desired walkers and create array of input files.
70  auto nwalkers = json.get("walkers", 1).asInt();
71  if(json["input"].isArray() && json["input"].size() != nwalkers)
72  throw BuildException({"#/input: Number of inputs do not match requested walkers."});
74  std::vector<std::string> inputs;
75  for(int i = 0; i < nwalkers; ++i)
76  {
77  if(json["input"].isArray())
78  inputs.push_back(json["input"][i].asString());
79  else
80  inputs.push_back(json["input"].asString());
81  }
83  // Get basic MPI info and verify that the total number of
84  // cores are divisble by number of walkers.
85  auto wcomm = mxx::comm(world);
86  if(wcomm.size() % nwalkers != 0)
87  throw BuildException({"#/walkers: Allocated processors not divisible by number of walkers."});
89  // Split communicators.
90  int ppw = wcomm.size()/nwalkers;
91  int walkerid = wcomm.rank()/ppw;
92  auto comm = wcomm.split(walkerid);
94  // Build collective variables.
95  auto* cvmanager = new CVManager();
96  int icv = 0;
97  for(auto& cv : json["CVs"])
98  {
99  // Register name with CV manager if it exists.
100  if(cv.isMember("name"))
101  CVManager::AddCVtoMap(cv["name"].asString(), icv);
103  // Build CV and add to manager.
104  cvmanager->AddCV(CollectiveVariable::BuildCV(cv, "#/CVs"));
105  ++icv;
106  }
108  // Build methods.
109  std::vector<Method*> methods;
110  for(auto& m : json["methods"])
111  methods.push_back(Method::BuildMethod(m, world, comm, "#/methods"));
113  // Build logger.
114  Logger* l = nullptr;
115  if(json.isMember("logger"))
116  l = Logger::Build(json["logger"], world, comm, "#/logger");
118  auto* rh = new ResourceHandler(std::move(world), std::move(comm), walkerid, methods, cvmanager);
119  rh->inputs_ = inputs;
120  rh->nwalkers_ = nwalkers;
121  rh->logger_ = l;
122  return rh;
123  }
bool HasErrors()
Check if errors have occured.
Definition: Requirement.h:86
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
std::vector< std::string > GetErrors()
Get list of error messages.
Definition: Requirement.h:92
Requirements on an object.
static Method * BuildMethod(const Json::Value &json, const MPI_Comm &world, const MPI_Comm &comm, const std::string &path)
Build a derived method from JSON node.
Definition: Method.cpp:39
static Logger * Build(const Json::Value &json, const MPI_Comm &world, const MPI_Comm &comm, const std::string &path)
Build a Logger from JSON node.
Definition: Logger.cpp:75
static void AddCVtoMap(const std::string &name, uint id)
Register CV name with map.
Definition: CVManager.h:100
ResourceHandler(mxx::comm &&world, mxx::comm &&comm, uint walkerid, const std::vector< class Method * > &methods, class CVManager *cvmanager)
static CollectiveVariable * BuildCV(const Json::Value &json, const std::string &path)
Set up collective variable.
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.

Here is the call graph for this function:

The documentation for this class was generated from the following files: