57 #if !defined(DCMFTICK) 59 #define DCMFTIMEBASE 0 75 #define TBUFSIZE (1<<15) 81 static unsigned long tbuf_[
TBUFSIZE];
83 #if USE_RDTSCL // but can have many accuracy problems on recent cpus. 87 static unsigned long t__;
88 #define TBUF {rdtscl(t__); tbuf_[itbuf_++] = t__;} 90 #define TBUF tbuf_[itbuf_++] = (unsigned long)DCMF_Timebase(); 91 #endif // not USE_RDTSCLL 109 #define PHASE2BUFFER_SIZE 2048 // power of 2 110 #define PHASE2BUFFER_MASK (PHASE2BUFFER_SIZE - 1) 120 #define BGP_RECEIVEBUFFER_SIZE 10000 126 void incoming(
int gid,
double spiketime);
152 #define NTARGET_HOSTS_PHASE1 ntarget_hosts_phase1_ 158 void send(
int gid,
double t);
178 #if BGP_INTERVAL == 2 191 psbuf_ =
new PreSyn*[size_];
194 phase2_head_ = phase2_tail_ = 0;
198 for (
int i = 0;
i < count_; ++
i) {
199 pool_->hpfree(buffer_[
i]);
203 if (psbuf_)
delete [] psbuf_;
204 delete [] phase2_buffer_;
209 nsend_cell_ = nsend_ = nrecv_ = busy_ = maxcount_ = 0;
210 for (
int i = 0;
i < count_; ++
i) {
211 pool_->hpfree(buffer_[
i]);
214 phase2_head_ = phase2_tail_ = 0;
215 phase2_nsend_cell_ = phase2_nsend_ = 0;
221 if (count_ >= size_) {
224 for (
int i = 0;
i < count_; ++
i) {
225 newbuf[
i] = buffer_[
i];
231 psbuf_ =
new PreSyn*[size_];
237 buffer_[count_++] = spk;
238 if (maxcount_ < count_) { maxcount_ = count_; }
247 for (
int i=0;
i < count_; ++
i) {
261 assert(phase2_head_ != phase2_tail_);
287 void BGP_ReceiveBuffer::enqueue1() {
291 for (
int i=0;
i < count_; ++
i) {
302 assert(phase2_head_ != phase2_tail_);
312 void BGP_ReceiveBuffer::enqueue2() {
316 for (
int i=0;
i < count_; ++
i) {
328 #endif // ENQUEUE == 1 331 while (phase2_head_ != phase2_tail_) {
351 if (!use_bgpdma_) {
return rt; }
357 if (!use_bgpdma_) {
return rt; }
364 if (
ifarg(2) && use_bgpdma_) {
376 for (
int i=0;
i <= itbuf_; ++
i) {
391 int method = use_bgpdma_ ? 1 : 0;
392 int p = method + 4*(n_bgp_interval == 2 ? 1 : 0)
415 bgp_receive_buffer[
i]->
init(
i);
440 #if BGP_INTERVAL == 2 453 void nrnbgp_messager_advance() {
465 target_hosts_ =
NULL;
466 ntarget_hosts_phase1_ = 0;
471 delete [] target_hosts_;
476 ntarget_hosts_phase2_ = 0;
477 target_hosts_phase2_ = 0;
481 if (target_hosts_phase2_) {
482 delete [] target_hosts_phase2_;
489 static void mymulticast(DCMF_Multicast_t*
arg) {
492 static void myrestart(DCMF_Request_t*
arg) {
502 #if BGP_INTERVAL == 2 506 spk_.gid = ~spk_.gid;
509 bgp_receive_buffer[0]->
nsend_ += ntarget_hosts_;
524 if (ntarget_hosts_phase2_) {
527 #if BGP_INTERVAL == 2 529 spk_.gid = ~spk_.gid;
551 #if ENQUEUE == 2 && TBUFSIZE 552 unsigned long tfind, tsend;
557 nrnbgp_messager_advance();
559 #if ENQUEUE == 2 && TBUFSIZE 569 nrnbgp_messager_advance();
578 tbuf_[itbuf_++] = (
unsigned long)ncons;
579 tbuf_[itbuf_++] = (
unsigned long)bgp_receive_buffer[
current_rbuf]->nsend_cell_;
580 tbuf_[itbuf_++] = (
unsigned long)s;
581 tbuf_[itbuf_++] = (
unsigned long)r;
584 tbuf_[itbuf_++] = (
unsigned long)bgp_receive_buffer[
current_rbuf]->phase2_nsend_cell_;
585 tbuf_[itbuf_++] = (
unsigned long)bgp_receive_buffer[
current_rbuf]->phase2_nsend_;
588 #if (BGPMDA & 2) && MAXNCONS 608 tbuf_[itbuf_++] = tfind;
609 tbuf_[itbuf_++] = tsend;
611 #endif // ENQUEUE == 2 614 #if BGP_INTERVAL == 2 626 if (nrn_use_localgid_) {
627 nrn_outputevent(ps->localgid_, t);
636 if (ps->bgp.dma_send_) {
638 delete ps->bgp.dma_send_;
639 ps->bgp.dma_send_ = 0;
642 delete ps->bgp.dma_send_phase2_;
643 ps->bgp.dma_send_phase2_ = 0;
653 for (
const auto& iter:
gid2in_) {
656 if (!use_bgpdma_ && bgp_receive_buffer[1]) {
657 delete bgp_receive_buffer[0];
658 bgp_receive_buffer[0] =
NULL;
660 #if BGP_INTERVAL == 2 661 if ((!use_bgpdma_ ||
n_bgp_interval != 2) && bgp_receive_buffer[1]) {
662 delete bgp_receive_buffer[1];
663 bgp_receive_buffer[1] =
NULL;
673 static void bgptimeout() {
681 #if WORK_AROUND_RECORD_BUG 688 for (
int i=0;
i < nold; ++
i) {
718 if (!use_bgpdma_) {
return; }
742 #error "FASTSETUP required" 743 #endif // obsolete (not FASTSETUP) 745 if (!bgp_receive_buffer[0]) {
748 #if BGP_INTERVAL == 2 758 int ncs_bgp_sending_info(
int **sendlist2build )
762 if (iter.second->output_index_ >= 0) {
767 *sendlist2build = nsrcgid ?
new int[nsrcgid] : 0;
769 for (
const auto& iter: gid2out) {
772 (*sendlist2build)[
i] = ps->
gid_;
783 int ncs_bgp_target_hosts(
int gid,
int** targetnodes )
788 if( ps->bgp.dma_send_ ) {
789 (*targetnodes) = ps->bgp.dma_send_->ntarget_hosts_?
new int[ps->bgp.dma_send_->ntarget_hosts_] : 0;
790 return ps->bgp.dma_send_->ntarget_hosts_;
797 int ncs_bgp_target_info(
int **presyngids )
806 for (
const auto& iter:
gid2in_) {
809 if( ps->bgp.srchost_ != -1 ) {
815 (*presyngids) = nsrcgid ?
new int[nsrcgid] : 0;
818 for (
const auto& iter: gid2in_) {
821 if( ps->bgp.srchost_ != -1 ) {
822 (*presyngids)[
i] = ps->
gid_;
830 int ncs_bgp_mindelays(
int **srchost,
double **delays )
834 for (
const auto& iter:
gid2in_) {
837 if( ps->bgp.srchost_ != -1 ) {
842 (*delays) = nsrcgid ?
new double[nsrcgid] : 0;
843 (*srchost) = nsrcgid ?
new int[nsrcgid] : 0;
846 for (
const auto& iter: gid2in_) {
849 if( ps->bgp.srchost_ != -1 ) {
851 (*srchost)[
i] = ps->bgp.srchost_;
static unsigned long enq2_find_time_
void send_phase2(int gid, double t, BGP_ReceiveBuffer *)
static BGP_ReceiveBuffer * bgp_receive_buffer[BGP_INTERVAL]
#define PHASE2BUFFER_SIZE
void bgpdma_cleanup_presyn(PreSyn *ps)
static int max_multisend_targets
static Gid2PreSyn gid2out_
static unsigned long enq2_enqueue_time_
static int max_ntarget_host
static void bgp_dma_init()
void vector_resize(IvocVect *, int)
virtual void send(double sendtime, NetCvode *, NrnThread *)
Represent main neuron object computed by single thread.
void bgp_dma_receive(NrnThread *nt)
void(* nrntimeout_call)()
#define BGP_RECEIVEBUFFER_SIZE
void nrnmpi_bgp_multisend(NRNMPI_Spike *, int, int *)
static void setup_presyn_dma_lists()
int ntarget_hosts_phase1_
double nrn_bgp_receive_time(int type)
static void bgpdma_cleanup()
void bgp_dma_send(PreSyn *ps, double t)
virtual ~BGP_DMASend_Phase2()
static void nrnmpi_barrier()
IvocVect * vector_arg(int)
static Gid2PreSyn gid2in_
unsigned long long timebase_
static int n_bgp_interval
static unsigned long long dmasend_time_
#define NTARGET_HOSTS_PHASE1
virtual ~BGP_ReceiveBuffer()
Pool< NRNMPI_Spike > SpkPool
void incoming(int gid, double spiketime)
int nrnmpi_bgp_conserve(int nsend, int nrecv)
Phase2Buffer * phase2_buffer_
#define PHASE2BUFFER_MASK
static double nrnmpi_wtime()
double * vector_vec(Vect *v)
static int n_xtra_cons_check_
void send(int gid, double t)
int * target_hosts_phase2_
int nrnmpi_bgp_single_advance(NRNMPI_Spike *)
NetCvode * net_cvode_instance
int ntarget_hosts_phase2_
static int xtra_cons_hist_[MAXNCONS+1]