RoadRunnerMap
-
class RoadRunnerMap
Hash table designed for storing RoadRunner models.
Expensive operations like building models are done in parallel.
Loading RoadRunner models requires expensive builds, which can be prohibitive when loading many models. RoadRunnerMap is a container for RoadRunner objects which abstracts the process of loading or simulating in parallel.
Public Functions
-
RoadRunnerMap() = default
Default construct a RoadRunnerMap.
The default number of threads is 1, which can be changed with RoadRunnerMap::setNumThreads.
-
explicit RoadRunnerMap(const std::vector<std::string> &sbmlStringsOrFiles, unsigned int numThreads)
Instantiate a RoadRunnerMap from a.
- Parameters:
sbmlStringsOrFiles – vector of sbml files, sbml strings or a mix thereof.
numThreads – How many threads to use, if 1, the overhead of setting up multithreading pool is avoided.
-
std::vector<std::string> getKeys() const
Returns the keys of the map in order of insertion.
Does a linear search over hashmap to build a vector of keys O(N).
-
std::vector<RoadRunner*> getValues() const
return values of the map as a RoadRunnervector.
the RoadRunner* instances are still owned by the RoadRunnerMap Linear complexity in the size of the map.
-
std::vector<std::pair<std::string, RoadRunner*>> getItems() const
get items of this map as vector of std::pair<std::string, RoadRuner*> types.
pointers are owned by the RoadRunnerMap — so do not delete. O(N).
-
void insert(std::unique_ptr<RoadRunner> roadRunner)
Insert a.
The model must already be a unique pointer. The key for accessing the map will be the model name. Loading another model with the same name will overwrite the original.
See also
See also
void insert(const std::vector<std::string> &sbmlStringsOrFiles);
- Parameters:
roadRunner – roadrunner model into the map.
-
void insert(const std::string &key, std::unique_ptr<RoadRunner> roadRunner)
The same as the std::unique_ptr<RoadRunner> overload but with a user provided key.
See also
See also
See also
void insert(const std::vector<std::string> &sbmlStringsOrFiles);
-
void insert(const std::string &sbmlOrFile)
insert a roadrunner model into the map using the model name as key.
See also
See also
void insert(const std::vector<std::string> &sbmlStringsOrFiles);
- Parameters:
sbmlOrFile – either a sbml string or a valid file path to a sbml file.
-
void insert(const std::string &key, const std::string &sbmlOrFile)
insert a roadrunner model into the map using a user define key.
See also
See also
See also
void insert(const std::vector<std::string> &sbmlStringsOrFiles);
- Parameters:
key – The string to use for the key to the roadrunner model you are inserting.
sbmlOrFile – either a sbml string or a valid file path to a sbml file.
-
void insert(const std::vector<std::string> &sbmlStringsOrFiles)
Like the “insert(const std::string &sbmlOrFile);” overload, but pass in a vector of sbml file or sbml strings.
See also
See also
-
void erase(const std::string &key)
remove an element with
- Parameters:
key – from the map
-
ThreadSafeUnorderedMap::iterator begin()
map iterator
for (auto&[modelName, rr]: rrm) { ... }
or
for (auto& [modelName, rr] : rrm) { actual[i] = rr->getInstanceID(); i++; }
-
ThreadSafeUnorderedMap::const_iterator begin() const
-
ThreadSafeUnorderedMap::iterator end()
for (auto it = rrm.begin(); it != rrm.end(); ++it) { auto&[modelName, rr] = *it; i++; }
-
ThreadSafeUnorderedMap::const_iterator end() const
-
ThreadSafeUnorderedMap::iterator find(const std::string &key)
find item with key equal to
- Parameters:
key – .
- Returns:
iterator to item if found or end if not found
-
ThreadSafeUnorderedMap::const_iterator find(const std::string &key) const
find item with key equal to
- Parameters:
key – . Const version.
- Returns:
iterator to item if found or end if not found
-
bool empty() const
return true if the map is empty
-
unsigned int size() const
returns the number of elements in the map
-
void clear()
empty the map so that there are 0 elements left
-
RoadRunner *operator[](const std::string &key)
Getter operator.
Returns a borrowed reference to a roadruner model that is owned by the RoadRunnerMap.
-
RoadRunner *at(const std::string &key)
get borrowed reference from map for roadrunner model with key equal to
returned pointer is owned by the RoadRunnerMap object.
- Parameters:
key – .
-
RoadRunner *at(const std::string &key) const
-
void wait_for_tasks()
wait for all tasks to finish before allowing program execution to continue
-
size_t count(const std::string &key)
count the number of keys with value
Because there can be only 1 element with a particular key in the map, the return value of count is guarenteed to be either 0 for not found, or 1 for found.
- Parameters:
key – .
-
void setNumThreads(unsigned int n)
Reset the number of threads in the pool.
If we are asked for more than 0 threads and we have an existing thread pool, the pool will wait for current tasks to finish before resetting the pool with the new number of threads
If we are asked for more than 0 threads and we do not have an existing thread pool, creates one with the requested number of threads
If we are asked for 0 threads and we have an existing thread pool, the thread pool is destroyed.
If we are asked for 0 threads and we do not have an existing thread pool, does nothing
-
unsigned int getNumThreads() const
get the number of threds in the thread_pool
Private Functions
-
void loadParallel(const std::vector<std::string> &sbmlFilesOrStrings)
Load models in parallel, using numThread_ threads.
Private.
Uses a thread_pool under the hood to manage workloads.
-
void loadSerial(const std::vector<std::string> &sbmlFilesOrStrings)
loads models in serial, without the overhead of having thread_pool
Private Members
-
unsigned int numThreads_ = 1
Variable to hold the number of threads int the pool.
See also
See also
-
ThreadSafeUnorderedMap rrMap_ = {}
a map type that does all the heavy lifting in this class.
-
std::unique_ptr<thread_pool> pool = nullptr
manages workloads using numThreads_ threads.
-
RoadRunnerMap() = default