NEURON
Memb_list Struct Reference

A view into a set of mechanism instances. More...

#include <nrnoc_ml.h>

Public Member Functions

 Memb_list ()=default
 Construct a null Memb_list that does not refer to any thread/type. More...
 
 Memb_list (int type)
 Construct a Memb_list that knows its type + underlying storage. More...
 
 ~Memb_list () noexcept
 Uninitialize, freeing any allocated mem for nodes. More...
 
 Memb_list (Memb_list &&) noexcept
 
Memb_listoperator= (Memb_list &&) noexcept
 
void nodes_alloc (int node_count, bool also_pdata)
 Allocate memory for node_count nodes. More...
 
void nodes_free ()
 Free memory allocated for nodes (with nodes_alloc) More...
 
std::vector< double * > data ()
 Get a vector of double* representing the model data. More...
 
template<std::size_t variable>
double & fpfield (std::size_t instance)
 
template<std::size_t variable>
double * dptr_field (std::size_t instance)
 
neuron::container::data_handle< double > data_handle (std::size_t instance, neuron::container::field_index field) const
 
int get_array_dims (int variable) const
 Get the array_dims of field variable. More...
 
int const * get_array_dims () const
 Get the array_dims of field variable. More...
 
int get_array_prefix_sums (int variable) const
 Get the array_dims of field variable. More...
 
int const * get_array_prefix_sums () const
 Get the array_dims of field variable. More...
 
std::ptrdiff_t legacy_index (double const *ptr) const
 Calculate a legacy index of the given pointer in this mechanism data. More...
 
std::ptrdiff_t legacy_index (neuron::container::data_handle< double > const &dh) const
 Calculate a legacy index from a data handle. More...
 
std::size_t get_storage_offset () const
 Get the offset of this Memb_list into global storage for this type. More...
 
void set_storage_offset (std::size_t offset)
 Set the offset of this Memb_list into global storage for this type. More...
 
void set_storage_pointer (neuron::container::Mechanism::storage *storage)
 Set the pointer to the underlying data container. More...
 
int type () const
 Get the mechanism type. More...
 
int _type () const
 

Public Attributes

Node ** nodelist {}
 
int * nodeindices {}
 
Datum ** pdata {}
 
Prop ** prop {}
 
Datum_thread {}
 
int nodecount {}
 

Private Member Functions

 Memb_list (const Memb_list &)=delete
 
Memb_listoperator= (const Memb_list &)=default
 

Private Attributes

neuron::container::Mechanism::storagem_storage {}
 Pointer to the global mechanism data structure for this mech type. More...
 
std::size_t m_storage_offset {neuron::container::invalid_row}
 Offset of this thread+mechanism into the global mechanism data. More...
 
bool m_owns_nodes {false}
 Whether this memlist owns its nodes memory or whether we are a view Has implications on memory management. More...
 

Detailed Description

A view into a set of mechanism instances.

This is a view to a set of mechanism instances that are contiguous in the underlying storage. This is inherently something that only makes sense if the underlying data are sorted. In this case, Memb_list essentially contains a pointer to the underlying storage struct and a single offset into it. This covers use-cases like Memb_list inside NrnThread – the data are partitioned by NrnThread in nrn_sort_mech_data so all the instances of a particular mechanism in a particular thread are next to each other in the storage.

Because this type is passed from NEURON library code into code generated from MOD files, it is prone to ABI issues – particularly when dealing with Python wheels.

Definition at line 34 of file nrnoc_ml.h.

Constructor & Destructor Documentation

◆ Memb_list() [1/4]

Memb_list::Memb_list ( )
default

Construct a null Memb_list that does not refer to any thread/type.

◆ Memb_list() [2/4]

Memb_list::Memb_list ( int  type)
explicit

Construct a Memb_list that knows its type + underlying storage.

Defined in .cpp to hide neuron::container::Mechanism::storage layout from translated MOD file code.

Definition at line 14 of file memblist.cpp.

◆ ~Memb_list()

Memb_list::~Memb_list ( )
noexcept

Uninitialize, freeing any allocated mem for nodes.

Definition at line 58 of file memblist.cpp.

◆ Memb_list() [3/4]

Memb_list::Memb_list ( Memb_list &&  other)
noexcept

Other should not be used. But if it is, fine, but not the memory owner anymore

Definition at line 46 of file memblist.cpp.

◆ Memb_list() [4/4]

Memb_list::Memb_list ( const Memb_list )
privatedelete

Member Function Documentation

◆ _type()

int Memb_list::_type ( ) const
inline

Definition at line 233 of file nrnoc_ml.h.

◆ data()

std::vector< double * > Memb_list::data ( )

Get a vector of double* representing the model data.

Calling .data() on the return value yields a double** that is similar to the old _data member, with the key difference that its indices are transposed. Now, the first index corresponds to the variable and the second index corresponds to the instance of the mechanism. This method is useful for interfacing with CoreNEURON but should be deprecated and removed along with the translation layer between NEURON and CoreNEURON.

Defined in .cpp to hide neuron::container::Mechanism::storage layout from translated MOD file code.

Definition at line 64 of file memblist.cpp.

◆ data_handle()

neuron::container::data_handle< double > Memb_list::data_handle ( std::size_t  instance,
neuron::container::field_index  field 
) const

Definition at line 76 of file memblist.cpp.

◆ dptr_field()

template<std::size_t variable>
double * Memb_list::dptr_field ( std::size_t  instance)
inline

Definition at line 100 of file nrnoc_ml.h.

◆ fpfield()

template<std::size_t variable>
double& Memb_list::fpfield ( std::size_t  instance)
inline

Definition at line 95 of file nrnoc_ml.h.

◆ get_array_dims() [1/2]

int const * Memb_list::get_array_dims ( ) const

Get the array_dims of field variable.

Definition at line 115 of file memblist.cpp.

◆ get_array_dims() [2/2]

int Memb_list::get_array_dims ( int  variable) const

Get the array_dims of field variable.

Definition at line 110 of file memblist.cpp.

◆ get_array_prefix_sums() [1/2]

int const * Memb_list::get_array_prefix_sums ( ) const

Get the array_dims of field variable.

Definition at line 125 of file memblist.cpp.

◆ get_array_prefix_sums() [2/2]

int Memb_list::get_array_prefix_sums ( int  variable) const

Get the array_dims of field variable.

Definition at line 120 of file memblist.cpp.

◆ get_storage_offset()

std::size_t Memb_list::get_storage_offset ( ) const
inline

Get the offset of this Memb_list into global storage for this type.

In the simplest case then this Memb_list represents all instances of a particular type in a particular thread, which are contiguous because the data have been sorted by a call like auto const cache_token = nrn_ensure_model_data_are_sorted() and this offset has been set to be cache_token.thread_cache(thread_id).mechanism_offset.at(mechanism_type) so that the first argument to data(i, j) is an offset inside this thread, not the global structure.

Definition at line 195 of file nrnoc_ml.h.

◆ legacy_index() [1/2]

std::ptrdiff_t Memb_list::legacy_index ( double const *  ptr) const

Calculate a legacy index of the given pointer in this mechanism data.

This used to be defined as ptr - ml->_data[0] if ptr belonged to the given mechanism, i.e. an offset from the zeroth element of the zeroth mechanism. This is useful when interfacing with CoreNEURON and for parameter exchange with other MPI ranks.

Defined in .cpp to hide neuron::container::Mechanism::storage layout from translated MOD file code.

Definition at line 131 of file memblist.cpp.

◆ legacy_index() [2/2]

std::ptrdiff_t Memb_list::legacy_index ( neuron::container::data_handle< double > const &  dh) const
inline

Calculate a legacy index from a data handle.

Definition at line 178 of file nrnoc_ml.h.

◆ nodes_alloc()

void Memb_list::nodes_alloc ( int  node_count,
bool  also_pdata 
)

Allocate memory for node_count nodes.

Parameters
also_pdataAllocate also pdata Datum's

Definition at line 19 of file memblist.cpp.

◆ nodes_free()

void Memb_list::nodes_free ( )

Free memory allocated for nodes (with nodes_alloc)

Definition at line 36 of file memblist.cpp.

◆ operator=() [1/2]

Memb_list& Memb_list::operator= ( const Memb_list )
privatedefault

◆ operator=() [2/2]

Memb_list & Memb_list::operator= ( Memb_list &&  rhs)
noexcept

Definition at line 52 of file memblist.cpp.

◆ set_storage_offset()

void Memb_list::set_storage_offset ( std::size_t  offset)
inline

Set the offset of this Memb_list into global storage for this type.

See the documentation for get_storage_offset.

Todo:
At the moment this is set as part of sorting/permuting data, but it is not automatically invalidated when the cache / sorted status is reset. Consider if these offsets can be more explicitly tied to the lifetime of the cache data.

Definition at line 210 of file nrnoc_ml.h.

◆ set_storage_pointer()

void Memb_list::set_storage_pointer ( neuron::container::Mechanism::storage storage)
inline

Set the pointer to the underlying data container.

This is a quasi-private method that you should think twice before calling. Normally m_storage would automatically be set by the constructor taking an integer mechanism type.

Definition at line 221 of file nrnoc_ml.h.

◆ type()

int Memb_list::type ( ) const

Get the mechanism type.

Defined in .cpp to hide neuron::container::Mechanism::storage layout from translated MOD file code.

Definition at line 177 of file memblist.cpp.

Member Data Documentation

◆ _thread

Datum* Memb_list::_thread {}

Definition at line 77 of file nrnoc_ml.h.

◆ m_owns_nodes

bool Memb_list::m_owns_nodes {false}
private

Whether this memlist owns its nodes memory or whether we are a view Has implications on memory management.

Definition at line 257 of file nrnoc_ml.h.

◆ m_storage

neuron::container::Mechanism::storage* Memb_list::m_storage {}
private

Pointer to the global mechanism data structure for this mech type.

Definition at line 241 of file nrnoc_ml.h.

◆ m_storage_offset

std::size_t Memb_list::m_storage_offset {neuron::container::invalid_row}
private

Offset of this thread+mechanism into the global mechanism data.

This is locally a piece of "cache" information like node_data_offset – the question is whether Memb_list itself is also considered a transient/cache type, in which case this is fine, or if it's considered permanent...in which case this value should probably not live here.

Definition at line 251 of file nrnoc_ml.h.

◆ nodecount

int Memb_list::nodecount {}

Definition at line 78 of file nrnoc_ml.h.

◆ nodeindices

int* Memb_list::nodeindices {}

Definition at line 74 of file nrnoc_ml.h.

◆ nodelist

Node** Memb_list::nodelist {}

Definition at line 68 of file nrnoc_ml.h.

◆ pdata

Datum** Memb_list::pdata {}

Definition at line 75 of file nrnoc_ml.h.

◆ prop

Prop** Memb_list::prop {}

Definition at line 76 of file nrnoc_ml.h.


The documentation for this struct was generated from the following files: