CoreNEURON
nrnmpi.h
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 #pragma once
10 
11 #include <cassert>
12 #include <string>
13 #include <type_traits>
14 #include <vector>
15 
17 
18 #ifndef nrn_spikebuf_size
19 #define nrn_spikebuf_size 0
20 #endif
21 
22 namespace coreneuron {
24  int nspike;
27 };
28 } // namespace coreneuron
29 
30 namespace coreneuron {
31 struct NRNMPI_Spike {
32  int gid;
33  double spiketime;
34 };
35 
36 // Those functions and classes are part of a mechanism to dynamically or statically load mpi
37 // functions
38 struct mpi_function_base;
39 
40 struct mpi_manager_t {
42  m_function_ptrs.push_back(ptr);
43  }
44  void resolve_symbols(void* dlsym_handle);
45 
46  private:
47  std::vector<mpi_function_base*> m_function_ptrs;
48  // true when symbols are resolved
49 };
50 
52  static mpi_manager_t x;
53  return x;
54 }
55 
57  void resolve(void* dlsym_handle);
58  operator bool() const {
59  return m_fptr;
60  }
61  mpi_function_base(const char* name)
62  : m_name{name} {
64  }
65 
66  protected:
67  void* m_fptr{};
68  const char* m_name;
69 };
70 
71 // This could be done with a simpler
72 // template <auto fptr> struct function : function_base { ... };
73 // pattern in C++17...
74 template <typename>
75 struct mpi_function {};
76 
77 #define cnrn_make_integral_constant_t(x) std::integral_constant<std::decay_t<decltype(x)>, x>
78 
79 template <typename function_ptr, function_ptr fptr>
80 struct mpi_function<std::integral_constant<function_ptr, fptr>>: mpi_function_base {
82  template <typename... Args> // in principle deducible from `function_ptr`
83  auto operator()(Args&&... args) const {
84 #ifdef CORENEURON_ENABLE_MPI_DYNAMIC
85  // Dynamic MPI, m_fptr should have been initialised via dlsym.
86  assert(m_fptr);
87  return (*reinterpret_cast<decltype(fptr)>(m_fptr))(std::forward<Args>(args)...);
88 #else
89  // No dynamic MPI, use `fptr` directly. Will produce link errors if libmpi.so is not linked.
90  return (*fptr)(std::forward<Args>(args)...);
91 #endif
92  }
93 };
94 } // namespace coreneuron
coreneuron::NRNMPI_Spike::spiketime
double spiketime
Definition: nrnmpi.h:33
coreneuron::mpi_manager
mpi_manager_t & mpi_manager()
Definition: nrnmpi.h:51
nrn_spikebuf_size
#define nrn_spikebuf_size
Definition: nrnmpi.h:19
coreneuron::mpi_function_base::resolve
void resolve(void *dlsym_handle)
Definition: resolve.cpp:15
coreneuron::mpi_function_base
Definition: nrnmpi.h:56
coreneuron::mpi_manager_t::resolve_symbols
void resolve_symbols(void *dlsym_handle)
Definition: resolve.cpp:7
nrnmpidec.h
coreneuron::NRNMPI_Spike::gid
int gid
Definition: nrnmpi.h:32
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
coreneuron::mpi_manager_t::register_function
void register_function(mpi_function_base *ptr)
Definition: nrnmpi.h:41
coreneuron::mpi_function_base::m_fptr
void * m_fptr
Definition: nrnmpi.h:67
coreneuron::mpi_function_base::mpi_function_base
mpi_function_base(const char *name)
Definition: nrnmpi.h:61
coreneuron::mpi_function_base::m_name
const char * m_name
Definition: nrnmpi.h:68
coreneuron::mpi_function< std::integral_constant< function_ptr, fptr > >::operator()
auto operator()(Args &&... args) const
Definition: nrnmpi.h:83
nrnmpiuse.h
coreneuron::NRNMPI_Spikebuf::nspike
int nspike
Definition: nrnmpi.h:24
coreneuron::NRNMPI_Spikebuf::spiketime
double spiketime[nrn_spikebuf_size]
Definition: nrnmpi.h:26
coreneuron::mpi_function
Definition: nrnmpi.h:75
coreneuron::NRNMPI_Spikebuf::gid
int gid[nrn_spikebuf_size]
Definition: nrnmpi.h:25
coreneuron::NRNMPI_Spikebuf
Definition: nrnmpi.h:23
coreneuron::mpi_manager_t
Definition: nrnmpi.h:40
coreneuron::mpi_manager_t::m_function_ptrs
std::vector< mpi_function_base * > m_function_ptrs
Definition: nrnmpi.h:47
coreneuron::NRNMPI_Spike
Definition: nrnmpi.h:31