@@ -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+
4962namespace 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
228242void 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
254269void 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