CoreNEURON
fast_imem.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================
7 */
8 
9 #include "coreneuron/nrnconf.h"
12 #include "coreneuron/mpi/nrnmpi.h"
14 
15 namespace coreneuron {
16 
17 extern int nrn_nthread;
18 extern NrnThread* nrn_threads;
20 
22  for (auto nt = nrn_threads; nt < nrn_threads + nrn_nthread; ++nt) {
23  if (nt->nrn_fast_imem) {
24  free_memory(nt->nrn_fast_imem->nrn_sav_rhs);
25  free_memory(nt->nrn_fast_imem->nrn_sav_d);
26  free_memory(nt->nrn_fast_imem);
27  nt->nrn_fast_imem = nullptr;
28  }
29  }
30 }
31 
33  if (nrn_use_fast_imem) {
35  for (auto nt = nrn_threads; nt < nrn_threads + nrn_nthread; ++nt) {
36  int n = nt->end;
37  nt->nrn_fast_imem = (NrnFastImem*) ecalloc_align(1, sizeof(NrnFastImem));
38  nt->nrn_fast_imem->nrn_sav_rhs = (double*) ecalloc_align(n, sizeof(double));
39  nt->nrn_fast_imem->nrn_sav_d = (double*) ecalloc_align(n, sizeof(double));
40  }
41  }
42 }
43 
45  int i1 = 0;
46  int i3 = nt->end;
47 
48  double* vec_rhs = nt->_actual_rhs;
49  double* vec_area = nt->_actual_area;
50 
51  double* fast_imem_d = nt->nrn_fast_imem->nrn_sav_d;
52  double* fast_imem_rhs = nt->nrn_fast_imem->nrn_sav_rhs;
54  parallel loop present(vec_rhs, vec_area, fast_imem_d, fast_imem_rhs) if (nt->compute_gpu)
55  async(nt->stream_id))
56  nrn_pragma_omp(target teams distribute parallel for simd if(nt->compute_gpu))
57  for (int i = i1; i < i3; ++i) {
58  fast_imem_rhs[i] = (fast_imem_d[i] * vec_rhs[i] + fast_imem_rhs[i]) * vec_area[i] * 0.01;
59  }
60 }
61 
63  // See the corresponding NEURON nrn_calc_fast_imem_fixedstep_init
64  int i1 = 0;
65  int i3 = nt->end;
66 
67  double* vec_rhs = nt->_actual_rhs;
68  double* vec_area = nt->_actual_area;
69 
70  double* fast_imem_rhs = nt->nrn_fast_imem->nrn_sav_rhs;
71  nrn_pragma_acc(parallel loop present(vec_rhs, vec_area, fast_imem_rhs) if (nt->compute_gpu)
72  async(nt->stream_id))
73  nrn_pragma_omp(target teams distribute parallel for simd if(nt->compute_gpu))
74  for (int i = i1; i < i3; ++i) {
75  fast_imem_rhs[i] = (vec_rhs[i] + fast_imem_rhs[i]) * vec_area[i] * 0.01;
76  }
77 }
78 
79 } // namespace coreneuron
coreneuron::NrnThread::nrn_fast_imem
NrnFastImem * nrn_fast_imem
Definition: multicore.hpp:124
coreneuron::nrn_calc_fast_imem
void nrn_calc_fast_imem(NrnThread *nt)
Definition: fast_imem.cpp:44
free_memory
void free_memory(void *pointer)
Definition: memory.h:196
coreneuron::nrn_nthread
int nrn_nthread
Definition: multicore.cpp:55
coreneuron::NrnFastImem::nrn_sav_d
double * nrn_sav_d
Definition: multicore.hpp:54
coreneuron::nrn_use_fast_imem
bool nrn_use_fast_imem
Definition: fast_imem.cpp:19
nrnoc_aux.hpp
nrn_pragma_omp
nrn_pragma_acc(routine seq) nrn_pragma_omp(declare target) philox4x32_ctr_t coreneuron_random123_philox4x32_helper(coreneuron nrn_pragma_omp(end declare target) namespace coreneuron
Provide a helper function in global namespace that is declared target for OpenMP offloading to functi...
Definition: nrnran123.h:69
coreneuron::NrnThread::_actual_rhs
double * _actual_rhs
Definition: multicore.hpp:111
coreneuron::NrnThread::compute_gpu
int compute_gpu
Definition: multicore.hpp:136
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
fast_imem.hpp
coreneuron::i
int i
Definition: cellorder.cpp:485
coreneuron::nrn_calc_fast_imem_init
void nrn_calc_fast_imem_init(NrnThread *nt)
Definition: fast_imem.cpp:62
coreneuron::NrnThread
Definition: multicore.hpp:75
coreneuron::NrnThread::stream_id
int stream_id
Definition: multicore.hpp:137
coreneuron::nrn_threads
NrnThread * nrn_threads
Definition: multicore.cpp:56
coreneuron::nrn_fast_imem_alloc
void nrn_fast_imem_alloc()
Definition: fast_imem.cpp:32
nrnconf.h
coreneuron::NrnFastImem::nrn_sav_rhs
double * nrn_sav_rhs
Definition: multicore.hpp:53
coreneuron::NrnFastImem
Definition: multicore.hpp:52
coreneuron::fast_imem_free
void fast_imem_free()
Definition: fast_imem.cpp:21
coreneuron::NrnThread::end
int end
Definition: multicore.hpp:98
coreneuron::nrn_pragma_acc
nrn_pragma_acc(routine vector) static void triang_interleaved2(NrnThread *nt
Definition: ivocvect.cpp:30
coreneuron::NrnThread::_actual_area
double * _actual_area
Definition: multicore.hpp:116
coreneuron::ecalloc_align
void * ecalloc_align(size_t n, size_t size, size_t alignment)
memory.h
nrnmpi.h