Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit f2e0f01

Browse files
Return all spikes vectors to NEURON (#354)
* Return all spikes vectors to NEURON * don't write out.dat if NEURON gets spike vectors
1 parent bf3c823 commit f2e0f01

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

coreneuron/io/nrn2core_direct.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ extern void (*nrn2core_trajectory_values_)(int tid, int n_pr, void** vpr, double
106106

107107
/* Filled the Vector data arrays and send back the sizes at end of run */
108108
extern void (*nrn2core_trajectory_return_)(int tid, int n_pr, int vecsz, void** vpr, double t);
109+
110+
/* send all spikes vectors to NEURON */
111+
extern int (*nrn2core_all_spike_vectors_return_)(std::vector<double>& spikevec, std::vector<int>& gidvec);
109112
}
110113

111114
#endif /* nrn2core_direct_h */

coreneuron/io/nrn_setup.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ void (*nrn2core_trajectory_values_)(int tid, int n_pr, void** vpr, double t);
146146

147147
void (*nrn2core_trajectory_return_)(int tid, int n_pr, int vecsz, void** vpr, double t);
148148

149+
int (*nrn2core_all_spike_vectors_return_)(std::vector<double>& spikevec, std::vector<int>& gidvec);
150+
149151
// file format defined in cooperation with nrncore/src/nrniv/nrnbbcore_write.cpp
150152
// single integers are ascii one per line. arrays are binary int or double
151153
// Note that regardless of the gid contents of a group, since all gids are

coreneuron/io/output_spikes.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
3636

3737
#include "coreneuron/nrnconf.h"
3838
#include "coreneuron/nrniv/nrniv_decl.h"
39+
#include "coreneuron/io/nrn2core_direct.h"
3940
#include "coreneuron/io/output_spikes.hpp"
4041
#include "coreneuron/mpi/nrnmpi.h"
4142
#include "coreneuron/utils/nrnmutdec.h"
@@ -46,6 +47,18 @@ THE POSSIBILITY OF SUCH DAMAGE.
4647
#include "bbp/sonata/reports.h"
4748
#endif // ENABLE_SONATA_REPORTS
4849

50+
/**
51+
* @brief Return all spike vectors to NEURON
52+
*
53+
* @param spiketvec - vector of spikes at the end of CORENEURON simulation
54+
* @param spikegidvec - vector of gids at the end of CORENEURON simulation
55+
* @return true if we are in embedded_run and NEURON has successfully retrieved the vectors
56+
*/
57+
static bool all_spikes_return(std::vector<double>& spiketvec, std::vector<int>& spikegidvec) {
58+
return corenrn_embedded && nrn2core_all_spike_vectors_return_ &&
59+
(*nrn2core_all_spike_vectors_return_)(spiketvec, spikegidvec);
60+
}
61+
4962
namespace coreneuron {
5063

5164
/// --> Coreneuron as SpikeBuffer class
@@ -168,6 +181,7 @@ void output_spikes_parallel(const char* outpath, const std::string& population_n
168181
sonata_write_spikes(population_name.data(), spikevec_time.data(), spikevec_time.size(), spikevec_gid.data(),
169182
spikevec_gid.size(), outpath);
170183
#endif // ENABLE_SONATA_REPORTS
184+
171185
sort_spikes(spikevec_time, spikevec_gid);
172186
nrnmpi_barrier();
173187

@@ -226,6 +240,7 @@ void output_spikes_parallel(const char* outpath, const std::string& population_n
226240
#endif
227241

228242
void output_spikes_serial(const char* outpath) {
243+
229244
std::stringstream ss;
230245
ss << outpath << "/out.dat";
231246
std::string fname = ss.str();
@@ -252,6 +267,9 @@ void output_spikes_serial(const char* outpath) {
252267
}
253268

254269
void output_spikes(const char* outpath, const std::string& population_name) {
270+
// try to transfer spikes to NEURON. If successfull, don't write out.dat
271+
if (all_spikes_return(spikevec_time, spikevec_gid))
272+
return;
255273
#if NRNMPI
256274
if (nrnmpi_initialized()) {
257275
output_spikes_parallel(outpath, population_name);

0 commit comments

Comments
 (0)