NEST main@caf0ae8
 
Loading...
Searching...
No Matches
recording_backend_mpi.h
Go to the documentation of this file.
1/*
2 * recording_backend_mpi.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef RECORDING_BACKEND_MPI_H
24#define RECORDING_BACKEND_MPI_H
25
26#include "recording_backend.h"
27#include <arpa/inet.h>
28#include <mpi.h>
29#include <netinet/in.h>
30#include <set>
31#include <sys/socket.h>
32#include <unistd.h>
33
34/* BeginUserDocs: NOINDEX
35
36Short description
37+++++++++++++++++
38
39Recording backend `mpi` - Send data with MPI
40
41Description
42~~~~~~~~~~~
43
44.. admonition:: Availability
45
46 This stimulation backend is only available if NEST was compiled with
47 :ref:`support for MPI <compile-with-mpi>`.
48
49The `mpi` recording backend sends collected data to a remote process
50using MPI.
51
52There are two ways to set the MPI port. If both are set, option A has precedence
53
541. The address is supplied via the recording backends "mpi_address" status property.
55
562. The name of the MPI port to send data to is read from a file for each
57 device configured to use this backend. The file needs to be named
58 according to the following pattern:
59
60::
61
62 {data_path}/{data_prefix}{label}/{node_id}.txt
63
64The ``data_path`` and ``data_prefix`` are global kernel properties,
65while `label` is a property of the device in question and `node_id`
66its node ID. This path can only be set outside of a `Run` context
67(i.e. after ``Prepare()`` has been called, but ``Cleanup()`` has not).
68
69Communication Protocol
70~~~~~~~~~~~~~~~~~~~~~~
71
72The following protocol is used to exchange information between both
73MPI processes. The protocol is described using the following format
74for the MPI messages: (value, number, type, source/destination, tag)
75
761) ``Prepare`` : Connection of MPI port included in the port_file (see below)
772) ``Run`` begin: Send at each beginning of the run (true, 1, CXX_BOOL, 0, 0)
783) ``Run`` end : Receive at each ending of the run (true, 1, CXX_BOOL, 0, 0)
794) ``Run`` end : Send shape of the data of the run (shape, 1,INT, 0, 0)
805) ``Run`` end : Send data of the data of the run (data, shape, DOUBLE, 0, 0)
816) ``Run`` end : Send at each ending of the run (true, 1, CXX_BOOL, 0, 1)
827) ``Cleanup`` : Send at this en of the simulation (true, 1, CXX_BOOL, 0, 2)
83
84Data format
85~~~~~~~~~~~
86
87The format of the data sent is an array consisting of (id device, id node, time
88is ms).
89
90EndUserDocs */
91
92namespace nest
93{
94
106{
107public:
109 ~RecordingBackendMPI() throw();
110
111 void initialize() override;
112 void finalize() override;
113
114 void enroll( const RecordingDevice& device, const Dictionary& params ) override;
115
116 void disenroll( const RecordingDevice& device ) override;
117
118 void set_value_names( const RecordingDevice& device,
119 const std::vector< std::string >& double_value_names,
120 const std::vector< std::string >& long_value_names ) override;
121
122 void cleanup() override;
123
124 void prepare() override;
125
126 void write( const RecordingDevice&, const Event&, const std::vector< double >&, const std::vector< long >& ) override;
127
128 void set_status( const Dictionary& ) override;
129
130 void get_status( Dictionary& ) const override;
131
132 void pre_run_hook() override;
133
134 void post_run_hook() override;
135
136 void post_step_hook() override;
137
138 void check_device_status( const Dictionary& ) const override;
139 void get_device_defaults( Dictionary& ) const override;
140 void get_device_status( const RecordingDevice& device, Dictionary& params_dictionary ) const override;
141
142private:
145
154 std::vector< std::vector< std::vector< std::array< double, 3 > > > > buffer_;
155
164 typedef std::vector< std::map< size_t, std::tuple< int, MPI_Comm*, const RecordingDevice* > > > device_map;
166
175 typedef std::map< std::string, std::tuple< int, MPI_Comm*, int > > comm_map;
177
178 std::string mpi_address_;
179
180 void get_port( const RecordingDevice* device, std::string* port_name );
181 void get_port( size_t index_node, const std::string& label, std::string* port_name );
182 void send_data( const MPI_Comm* comm, const double data[], int size );
183};
184
185
186} // namespace
187
188#endif /* #ifndef RECORDING_BACKEND_MPI_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Encapsulate information sent between nodes.
Definition event.h:103
A recording backend for sending information with MPI.
Definition recording_backend_mpi.h:106
device_map devices_
Definition recording_backend_mpi.h:165
bool prepared_
Definition recording_backend_mpi.h:144
void set_status(const Dictionary &) override
Set the status of the recording backend using the key-value pairs contained in the params dictionary.
Definition recording_backend_mpi.cpp:359
void initialize() override
Definition recording_backend_mpi.cpp:47
void set_value_names(const RecordingDevice &device, const std::vector< std::string > &double_value_names, const std::vector< std::string > &long_value_names) override
To make the names of recorded quantities known to the RecordingBackend, the vectors double_value_name...
Definition recording_backend_mpi.cpp:114
void prepare() override
Prepare the backend at begin of the NEST Simulate function.
Definition recording_backend_mpi.cpp:122
void get_port(const RecordingDevice *device, std::string *port_name)
Definition recording_backend_mpi.cpp:365
RecordingBackendMPI()
Definition recording_backend_mpi.cpp:35
void get_device_status(const RecordingDevice &device, Dictionary &params_dictionary) const override
Return the per-device status of the given recording device by writing it to the given params dictiona...
Definition recording_backend_mpi.cpp:319
std::vector< std::vector< std::vector< std::array< double, 3 > > > > buffer_
Buffer for saving events before they are sent.
Definition recording_backend_mpi.h:154
void check_device_status(const Dictionary &) const override
Check if the given per-device properties are valid and usable by the backend.
Definition recording_backend_mpi.cpp:307
std::map< std::string, std::tuple< int, MPI_Comm *, int > > comm_map
A map of MPI communicators used by the master thread for the MPI communication.
Definition recording_backend_mpi.h:175
void write(const RecordingDevice &, const Event &, const std::vector< double > &, const std::vector< long > &) override
Write the data from the event to the backend specific channel together with the values given.
Definition recording_backend_mpi.cpp:326
bool enrolled_
Definition recording_backend_mpi.h:143
void pre_run_hook() override
Initialize global backend-specific data structures.
Definition recording_backend_mpi.cpp:210
~RecordingBackendMPI()
Definition recording_backend_mpi.cpp:41
void get_status(Dictionary &) const override
Return the status of the recording backend by writing it to the given params dictionary.
Definition recording_backend_mpi.cpp:353
void send_data(const MPI_Comm *comm, const double data[], int size)
Definition recording_backend_mpi.cpp:421
void disenroll(const RecordingDevice &device) override
Disenroll a RecordingDevice from the RecordingBackend.
Definition recording_backend_mpi.cpp:101
void post_run_hook() override
Clean up the backend at the end of a Run.
Definition recording_backend_mpi.cpp:231
std::vector< std::map< size_t, std::tuple< int, MPI_Comm *, const RecordingDevice * > > > device_map
A map for the enrolled devices.
Definition recording_backend_mpi.h:164
void finalize() override
Definition recording_backend_mpi.cpp:57
void post_step_hook() override
Do work required at the end of each simulation step.
Definition recording_backend_mpi.cpp:225
void cleanup() override
Clean up the backend at the end of a user level call to the NEST Simulate function.
Definition recording_backend_mpi.cpp:275
comm_map commMap_
Definition recording_backend_mpi.h:176
std::string mpi_address_
Definition recording_backend_mpi.h:178
void get_device_defaults(Dictionary &) const override
Return the per-device defaults by writing it to the given params dictionary.
Definition recording_backend_mpi.cpp:313
void enroll(const RecordingDevice &device, const Dictionary &params) override
Enroll a RecordingDevice with the RecordingBackend.
Definition recording_backend_mpi.cpp:75
Abstract base class for all NESTio recording backends.
Definition recording_backend.h:67
Base class for all recording devices.
Definition recording_device.h:157
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33