NEST main@caf0ae8
 
Loading...
Searching...
No Matches
nest::StimulationBackendMPI Class Reference

A simple input backend MPI implementation. More...

#include <stimulation_backend_mpi.h>

Inheritance diagram for nest::StimulationBackendMPI:
[legend]
Collaboration diagram for nest::StimulationBackendMPI:
[legend]

Public Member Functions

 StimulationBackendMPI ()
 InputBackend constructor.
 
 ~StimulationBackendMPI () noexcept override
 InputBackend destructor.
 
void initialize () override
 
void finalize () override
 
void enroll (StimulationDevice &device, const Dictionary &params) 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_
 

Detailed Description

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:

Member Typedef Documentation

◆ comm_map

typedef std::map< std::string, std::tuple< MPI_Comm*, std::vector< int >*, int* > > nest::StimulationBackendMPI::comm_map
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.

◆ device_map

using nest::StimulationBackendMPI::device_map = std::vector< std::map< size_t, std::pair< const MPI_Comm*, StimulationDevice* > > >
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.

Constructor & Destructor Documentation

◆ StimulationBackendMPI()

nest::StimulationBackendMPI::StimulationBackendMPI ( )

InputBackend constructor.

The actual initialization is happening in InputBackend::initialize()

◆ ~StimulationBackendMPI()

nest::StimulationBackendMPI::~StimulationBackendMPI ( )
overridenoexcept

InputBackend destructor.

The actual finalization is happening in InputBackend::finalize()

Member Function Documentation

◆ clean_memory_input_data()

void nest::StimulationBackendMPI::clean_memory_input_data ( std::vector< std::pair< int *, double * > > &  data)
private

clean all the memory allocated for the updating device.

The function is used only by the master thread

Parameters
data

Referenced by pre_run_hook().

Here is the caller graph for this function:

◆ cleanup()

void nest::StimulationBackendMPI::cleanup ( )
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.

See also
prepare()

Implements nest::StimulationBackend.

References commMap_, devices_, nest::VPManager::get_thread_id(), nest::kernel(), and nest::KernelManager::vp_manager.

Here is the call graph for this function:

◆ disenroll()

void nest::StimulationBackendMPI::disenroll ( StimulationDevice &  )
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.

Parameters
devicethe StimulationDevice to be disenrolled
See also
enroll()

Reimplemented from nest::StimulationBackend.

References devices_, nest::Node::get_node_id(), and nest::Node::get_thread().

Here is the call graph for this function:

◆ enroll()

void nest::StimulationBackendMPI::enroll ( StimulationDevice &  ,
const Dictionary &   
)
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.

Parameters
devicethe StimulationDevice to be enrolled
paramsdevice-specific backend parameters
See also
disenroll()

Reimplemented from nest::StimulationBackend.

References devices_, enrolled_, nest::Node::get_node_id(), nest::Node::get_thread(), nest::names::mpi_address(), and mpi_address_.

Here is the call graph for this function:

◆ finalize()

void nest::StimulationBackendMPI::finalize ( )
overridevirtual

Implements nest::StimulationBackend.

References commMap_, and devices_.

◆ get_port() [1/2]

void nest::StimulationBackendMPI::get_port ( size_t  index_node,
const std::string &  label,
std::string *  port_name 
)
private

References nest::IOManager::get_data_path(), nest::IOManager::get_data_prefix(), nest::KernelManager::io_manager, and nest::kernel().

Here is the call graph for this function:

◆ get_port() [2/2]

void nest::StimulationBackendMPI::get_port ( StimulationDevice *  device,
std::string *  port_name 
)
private

Getting the port name for the MPI connection.

Parameters
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize()

void nest::StimulationBackendMPI::initialize ( )
overridevirtual

Implements nest::StimulationBackend.

References devices_, nest::VPManager::get_num_threads(), nest::kernel(), and nest::KernelManager::vp_manager.

Here is the call graph for this function:

◆ post_run_hook()

void nest::StimulationBackendMPI::post_run_hook ( )
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.

See also
pre_run_hook()

Implements nest::StimulationBackend.

References commMap_.

◆ pre_run_hook()

void nest::StimulationBackendMPI::pre_run_hook ( )
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.

See also
post_run_hook()

Implements nest::StimulationBackend.

References clean_memory_input_data(), commMap_, receive_spike_train(), and update_device().

Here is the call graph for this function:

◆ prepare()

void nest::StimulationBackendMPI::prepare ( )
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.

See also
cleanup()

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.

Here is the call graph for this function:

◆ receive_spike_train()

std::pair< int *, double * > nest::StimulationBackendMPI::receive_spike_train ( const MPI_Comm &  comm,
std::vector< int > &  device_id 
)
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

Parameters
comm: the MPI communicator for send and receive message
device_id: the list of IDs which needs to be updated
Returns
pair( size of data by device, the continuous array with all the data for the device )

Referenced by pre_run_hook().

Here is the caller graph for this function:

◆ update_device()

void nest::StimulationBackendMPI::update_device ( int *  array_index,
std::vector< int > &  devices_id,
std::pair< int *, double * >  data 
)
private

Update all the devices with the data received.

Parameters
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().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ commMap_

comm_map nest::StimulationBackendMPI::commMap_
private

◆ devices_

device_map nest::StimulationBackendMPI::devices_
private

◆ enrolled_

bool nest::StimulationBackendMPI::enrolled_
private

Referenced by enroll(), and prepare().

◆ mpi_address_

std::string nest::StimulationBackendMPI::mpi_address_
private

Referenced by enroll(), and get_port().

◆ prepared_

bool nest::StimulationBackendMPI::prepared_
private

Referenced by prepare().


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