Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coreneuron/io/nrn2core_direct.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ extern void (*nrn2core_trajectory_values_)(int tid, int n_pr, void** vpr, double

/* Filled the Vector data arrays and send back the sizes at end of run */
extern void (*nrn2core_trajectory_return_)(int tid, int n_pr, int vecsz, void** vpr, double t);

/* send all spikes vectors to NEURON */
extern int (*nrn2core_all_spike_vectors_return_)(std::vector<double>& spikevec, std::vector<int>& gidvec);
}

#endif /* nrn2core_direct_h */
2 changes: 2 additions & 0 deletions coreneuron/io/nrn_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void (*nrn2core_trajectory_values_)(int tid, int n_pr, void** vpr, double t);

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

int (*nrn2core_all_spike_vectors_return_)(std::vector<double>& spikevec, std::vector<int>& gidvec);

// file format defined in cooperation with nrncore/src/nrniv/nrnbbcore_write.cpp
// single integers are ascii one per line. arrays are binary int or double
// Note that regardless of the gid contents of a group, since all gids are
Expand Down
18 changes: 18 additions & 0 deletions coreneuron/io/output_spikes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ THE POSSIBILITY OF SUCH DAMAGE.

#include "coreneuron/nrnconf.h"
#include "coreneuron/nrniv/nrniv_decl.h"
#include "coreneuron/io/nrn2core_direct.h"
#include "coreneuron/io/output_spikes.hpp"
#include "coreneuron/mpi/nrnmpi.h"
#include "coreneuron/utils/nrnmutdec.h"
Expand All @@ -46,6 +47,18 @@ THE POSSIBILITY OF SUCH DAMAGE.
#include "bbp/sonata/reports.h"
#endif // ENABLE_SONATA_REPORTS

/**
* @brief Return all spike vectors to NEURON
*
* @param spiketvec - vector of spikes at the end of CORENEURON simulation
* @param spikegidvec - vector of gids at the end of CORENEURON simulation
* @return true if we are in embedded_run and NEURON has successfully retrieved the vectors
*/
static bool all_spikes_return(std::vector<double>& spiketvec, std::vector<int>& spikegidvec) {
return corenrn_embedded && nrn2core_all_spike_vectors_return_ &&
(*nrn2core_all_spike_vectors_return_)(spiketvec, spikegidvec);
}

namespace coreneuron {

/// --> Coreneuron as SpikeBuffer class
Expand Down Expand Up @@ -168,6 +181,7 @@ void output_spikes_parallel(const char* outpath, const std::string& population_n
sonata_write_spikes(population_name.data(), spikevec_time.data(), spikevec_time.size(), spikevec_gid.data(),
spikevec_gid.size(), outpath);
#endif // ENABLE_SONATA_REPORTS

sort_spikes(spikevec_time, spikevec_gid);
nrnmpi_barrier();

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

void output_spikes_serial(const char* outpath) {

std::stringstream ss;
ss << outpath << "/out.dat";
std::string fname = ss.str();
Expand All @@ -252,6 +267,9 @@ void output_spikes_serial(const char* outpath) {
}

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