A simple input backend MPI implementation. More...
#include <stimulation_backend_mpi.h>
Public Member Functions | |
| StimulationBackendMPI () | |
| InputBackend constructor. | |
| ~StimulationBackendMPI () noexcept override | |
| InputBackend destructor. | |
| void | initialize () override |
| void | finalize () override |
| void | enroll (StimulationDevice &device, const Dictionary ¶ms) override |
Enroll a StimulationDevice with the StimulationBackend. | |
| void | disenroll (StimulationDevice &device) override |
Disenroll a StimulationDevice from the StimulationBackend. | |
| void | cleanup () override |
| Clean up the backend at the end of a user level call to the NEST Simulate function. | |
| void | prepare () override |
| Prepare the backend at the beginning of the NEST Simulate function. | |
| void | pre_run_hook () override |
| Initialize global backend-specific data structures. | |
| void | post_run_hook () override |
| Clean up the backend at the end of a Run. | |
Public Member Functions inherited from nest::StimulationBackend | |
| StimulationBackend ()=default | |
| virtual | ~StimulationBackend () noexcept=default |
| void | clear (const StimulationDevice &) |
Private Types | |
| using | device_map = std::vector< std::map< size_t, std::pair< const MPI_Comm *, StimulationDevice * > > > |
| A map for the enrolled devices. | |
| typedef std::map< std::string, std::tuple< MPI_Comm *, std::vector< int > *, int * > > | comm_map |
| A map of MPI communicators used by the master thread for the MPI communication. | |
Private Member Functions | |
| void | get_port (StimulationDevice *device, std::string *port_name) |
| Getting the port name for the MPI connection. | |
| void | get_port (size_t index_node, const std::string &label, std::string *port_name) |
| void | update_device (int *array_index, std::vector< int > &devices_id, std::pair< int *, double * > data) |
| Update all the devices with the data received. | |
| void | clean_memory_input_data (std::vector< std::pair< int *, double * > > &data) |
| clean all the memory allocated for the updating device. | |
Static Private Member Functions | |
| static std::pair< int *, double * > | receive_spike_train (const MPI_Comm &comm, std::vector< int > &device_id) |
| MPI communication for receiving the data before each run. | |
Private Attributes | |
| bool | enrolled_ |
| bool | prepared_ |
| device_map | devices_ |
| comm_map | commMap_ |
| std::string | mpi_address_ |
A simple input backend MPI implementation.
Communication protocol diagram:
General state machine diagram of NEST:
Example of state machine diagram for the communication with NEST:
|
private |
A map of MPI communicators used by the master thread for the MPI communication.
This map contains also the number of the devices linked to each MPI communicator.
|
private |
A map for the enrolled devices.
We have a vector with one map per local thread. The map associates the node ID of a device on a given thread with its device. Only the master thread has a valid MPI communicator pointer.
| nest::StimulationBackendMPI::StimulationBackendMPI | ( | ) |
InputBackend constructor.
The actual initialization is happening in InputBackend::initialize()
|
overridenoexcept |
InputBackend destructor.
The actual finalization is happening in InputBackend::finalize()
|
private |
clean all the memory allocated for the updating device.
The function is used only by the master thread
| data |
Referenced by pre_run_hook().
|
overridevirtual |
Clean up the backend at the end of a user level call to the NEST Simulate function.
This function is called by SimulationManager::cleanup() and allows the backend to close open files, close network connections, etc.
Implements nest::StimulationBackend.
References commMap_, devices_, nest::VPManager::get_thread_id(), nest::kernel(), and nest::KernelManager::vp_manager.
|
overridevirtual |
Disenroll a StimulationDevice from the StimulationBackend.
This function is considered to be the opposite of enroll() in the sense that it cancels the enrollment of a StimulatinDevice from a StimulationBackend by deleting all device specific data. When setting a new stimulation backend for a stimulation device, this function is called for each backend the device is not enrolled with.
| device | the StimulationDevice to be disenrolled |
Reimplemented from nest::StimulationBackend.
References devices_, nest::Node::get_node_id(), and nest::Node::get_thread().
|
overridevirtual |
Enroll a StimulationDevice with the StimulationBackend.
When this function is called by a StimulationDevice device, the StimulationBackend can set up per-device data structures and properties. Individual device instances can be identified using the thread and node_id of the device.
This function is called from the set_initialized_() function of the device and their set_status() function.
A backend needs to be able to cope with multiple calls to this function, as multiple calls to set_status() may occur on the device. For already enrolled devices this usually means that only the parameters in params have to be set, but no further actions are needed.
Each stimulation backend must ensure that enrollment (including all settings made by the user) is persistent over multiple calls to Prepare, while the enrollment of all devices should end with a call to finalize().
A common implementation of this function will create an entry in a thread-local map, associating the device's node ID with the device-specific backend properties and an input facility of some kind.
| device | the StimulationDevice to be enrolled |
| params | device-specific backend parameters |
Reimplemented from nest::StimulationBackend.
References devices_, enrolled_, nest::Node::get_node_id(), nest::Node::get_thread(), nest::names::mpi_address(), and mpi_address_.
|
overridevirtual |
Implements nest::StimulationBackend.
|
private |
References nest::IOManager::get_data_path(), nest::IOManager::get_data_prefix(), nest::KernelManager::io_manager, and nest::kernel().
|
private |
Getting the port name for the MPI connection.
| device | : input device for finding the file with the port |
| port_name | : result of the port name |
References nest::StimulationDevice::get_label(), nest::Node::get_node_id(), get_port(), and mpi_address_.
Referenced by get_port(), and prepare().
|
overridevirtual |
Implements nest::StimulationBackend.
References devices_, nest::VPManager::get_num_threads(), nest::kernel(), and nest::KernelManager::vp_manager.
|
overridevirtual |
Clean up the backend at the end of a Run.
This is called right before SimulationManager::run() terminates. It allows the backend to indicate that the run is ending.
Implements nest::StimulationBackend.
References commMap_.
|
overridevirtual |
Initialize global backend-specific data structures.
This function is called on each backend right at the very beginning of SimulationManager::run(). It used for getting the data in order to update the stimulation devices. The update of the device are made only if necessary and repeated at the beginning of every single call to run in a prepare-run-run-...-run-run-cleanup sequence.
Implements nest::StimulationBackend.
References clean_memory_input_data(), commMap_, receive_spike_train(), and update_device().
|
overridevirtual |
Prepare the backend at the beginning of the NEST Simulate function.
This function is called by KernelManager::prepare() and allows the backend to open files, establish network connections, etc.
Implements nest::StimulationBackend.
References commMap_, nest::KernelManager::connection_manager, devices_, enrolled_, nest::ConnectionManager::get_device_connected(), nest::VPManager::get_num_threads(), get_port(), nest::VPManager::get_thread_id(), nest::INFO, nest::kernel(), LOG, prepared_, and nest::KernelManager::vp_manager.
|
staticprivate |
MPI communication for receiving the data before each run.
This function is used only by the master thread. The allocation of this function is cleaned by the function clean_memory_input_data
| comm | : the MPI communicator for send and receive message |
| device_id | : the list of IDs which needs to be updated |
Referenced by pre_run_hook().
|
private |
Update all the devices with the data received.
| array_index | : number of devices by thread |
| devices_id | : the devices' ID ordered by thread |
| data | : the data received for updating all the devices |
References devices_, nest::VPManager::get_thread_id(), nest::kernel(), and nest::KernelManager::vp_manager.
Referenced by pre_run_hook().
|
private |
Referenced by cleanup(), finalize(), post_run_hook(), pre_run_hook(), and prepare().
|
private |
Referenced by cleanup(), disenroll(), enroll(), finalize(), initialize(), prepare(), and update_device().
|
private |
Referenced by enroll(), and get_port().
|
private |
Referenced by prepare().