OpenLB 1.7
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
olb::cpu::simd::CyclicColumn< T > Class Template Referencefinal

Virtual memory based cyclic column for usage in ColumnVector. More...

#include <column.h>

+ Inheritance diagram for olb::cpu::simd::CyclicColumn< T >:
+ Collaboration diagram for olb::cpu::simd::CyclicColumn< T >:

Public Types

using value_t = T
 
- Public Types inherited from olb::AbstractCyclicColumn< T >
using value_type = T
 

Public Member Functions

 CyclicColumn (std::size_t count)
 
 ~CyclicColumn ()
 
const T & operator[] (std::size_t i) const override
 
T & operator[] (std::size_t i) override
 
std::size_t size () const
 
void refresh ()
 
void rotate (std::ptrdiff_t offset)
 
void resize (std::size_t count)
 
void setProcessingContext (ProcessingContext)
 
std::size_t getNblock () const override
 Number of data blocks for the serializable interface.
 
std::size_t getSerializableSize () const override
 Binary size for the serializer.
 
bool * getBlock (std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
 Return a pointer to the memory of the current block and its size for the serializable interface.
 
void postLoad () override
 
- Public Member Functions inherited from olb::Serializable
virtual ~Serializable ()=default
 
template<bool includeLogOutputDir = true>
bool save (std::string fileName="", const bool enforceUint=false)
 Save Serializable into file fileName
 
template<bool includeLogOutputDir = true>
bool load (std::string fileName="", const bool enforceUint=false)
 Load Serializable from file fileName
 
bool save (std::uint8_t *buffer)
 Save Serializable into buffer of length getSerializableSize
 
bool load (const std::uint8_t *buffer)
 Load Serializable from buffer of length getSerializableSize
 

Additional Inherited Members

- Protected Member Functions inherited from olb::Serializable
template<typename DataType >
void registerVar (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, const DataType &data, const size_t arrayLength=1) const
 Register primitive data types (int, double, ...) or arrays of those.
 
template<typename DataType >
void registerSerializableOfConstSize (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, DataType &data, const bool loadingMode=false)
 Register Serializable object of constant size.
 
template<typename DataType >
void registerSerializablesOfConstSize (const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, DataType *data, const size_t arrayLength, const bool loadingMode=false)
 Register an array of Serializable objects of constant size.
 

Detailed Description

template<typename T>
class olb::cpu::simd::CyclicColumn< T >

Virtual memory based cyclic column for usage in ColumnVector.

Column type used for propagatable population storage using the virtual memory PS pattern.

Definition at line 153 of file column.h.

Member Typedef Documentation

◆ value_t

template<typename T >
using olb::cpu::simd::CyclicColumn< T >::value_t = T

Definition at line 167 of file column.h.

Constructor & Destructor Documentation

◆ CyclicColumn()

template<typename T >
olb::cpu::simd::CyclicColumn< T >::CyclicColumn ( std::size_t count)
inline

Definition at line 169 of file column.h.

169 :
170 _count(getPageAlignedCount<T>(count)),
171 _size(_count * sizeof(T)),
172 _shift(0)
173 {
174 #ifdef __NR_memfd_create
175 // Open anonymous file for physical lattice memory
176 // Manual call of "memfd_create("openlb", MFD_CLOEXEC)" in case GLIB is old
177 const int shm_file = syscall(__NR_memfd_create, "openlb", MFD_CLOEXEC);
178 #else
179 std::string shm_path = "/openlb_block_XXXXXX";
180 const int shm_name = mkstemp(const_cast<char*>(shm_path.data()));
181 if (shm_name != -1) {
182 throw std::runtime_error("Could not generate unique shared memory object name");
183 }
184 // Open shared memory object as physical lattice memory
185 const int shm_file = shm_open(shm_path.c_str(), O_CREAT | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
186 shm_unlink(shm_path.c_str());
187 #endif
188 if (shm_file == -1) {
189 throw std::runtime_error("Failed to create shared memory object");
190 }
191
192 // Resize to fit lattice populations
193 if (ftruncate(shm_file, _size) == -1) {
194 throw std::runtime_error("Failed to resize shared memory object");
195 }
196
197 // Allocate virtual address space for q times two consecutive lattices
198 _buffer = static_cast<std::uint8_t*>(
199 mmap(NULL, 2 * _size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
200
201 // Map single physical lattice into virtual address space
202 mmap(_buffer, _size, PROT_RW, MAP_SHARED | MAP_FIXED, shm_file, 0);
203 mmap(_buffer + _size, _size, PROT_RW, MAP_SHARED | MAP_FIXED, shm_file, 0);
204
205 // Store base pointer for reference
206 _base = reinterpret_cast<T*>(_buffer);
207 // Initialize shiftable f pointer to be used for lattice access
208 _f = _base;
209 }
const int PROT_RW
Definition column.h:131

References olb::cpu::simd::PROT_RW.

◆ ~CyclicColumn()

template<typename T >
olb::cpu::simd::CyclicColumn< T >::~CyclicColumn ( )
inline

Definition at line 211 of file column.h.

211 {
212 munmap(_buffer, 2 * _size);
213 }

Member Function Documentation

◆ getBlock()

template<typename T >
bool * olb::cpu::simd::CyclicColumn< T >::getBlock ( std::size_t iBlock,
std::size_t & sizeBlock,
bool loadingMode )
overridevirtual

Return a pointer to the memory of the current block and its size for the serializable interface.

Implements olb::Serializable.

Definition at line 77 of file column.hh.

78{
79 std::size_t currentBlock = 0;
80 bool* dataPtr = nullptr;
81
82 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _shift);
83 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _count);
84 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, *_base, 2*_count);
85
86 return dataPtr;
87}
void registerVar(const std::size_t iBlock, std::size_t &sizeBlock, std::size_t &currentBlock, bool *&dataPtr, const DataType &data, const size_t arrayLength=1) const
Register primitive data types (int, double, ...) or arrays of those.
Definition serializer.h:212

◆ getNblock()

template<typename T >
std::size_t olb::cpu::simd::CyclicColumn< T >::getNblock ( ) const
overridevirtual

Number of data blocks for the serializable interface.

Implements olb::Serializable.

Definition at line 65 of file column.hh.

66{
67 return 3;
68}

◆ getSerializableSize()

template<typename T >
std::size_t olb::cpu::simd::CyclicColumn< T >::getSerializableSize ( ) const
overridevirtual

Binary size for the serializer.

Implements olb::Serializable.

Definition at line 71 of file column.hh.

72{
73 return 2*_size + sizeof(std::ptrdiff_t) + sizeof(std::size_t);
74}

◆ operator[]() [1/2]

template<typename T >
const T & olb::cpu::simd::CyclicColumn< T >::operator[] ( std::size_t i) const
inlineoverridevirtual

Implements olb::AbstractCyclicColumn< T >.

Definition at line 215 of file column.h.

216 {
217 return _f[i];
218 }

◆ operator[]() [2/2]

template<typename T >
T & olb::cpu::simd::CyclicColumn< T >::operator[] ( std::size_t i)
inlineoverridevirtual

Implements olb::AbstractCyclicColumn< T >.

Definition at line 220 of file column.h.

221 {
222 return _f[i];
223 }

◆ postLoad()

template<typename T >
void olb::cpu::simd::CyclicColumn< T >::postLoad ( )
inlineoverridevirtual

Reimplemented from olb::Serializable.

Definition at line 260 of file column.h.

260{ refresh(); }

References olb::cpu::simd::CyclicColumn< T >::refresh().

+ Here is the call graph for this function:

◆ refresh()

template<typename T >
void olb::cpu::simd::CyclicColumn< T >::refresh ( )
inline

Definition at line 230 of file column.h.

231 {
232 _f = _base + _shift;
233 }
+ Here is the caller graph for this function:

◆ resize()

template<typename T >
void olb::cpu::simd::CyclicColumn< T >::resize ( std::size_t count)
inline

Definition at line 247 of file column.h.

248 {
249 throw std::logic_error("Cyclic column can not be resized");
250 }

◆ rotate()

template<typename T >
void olb::cpu::simd::CyclicColumn< T >::rotate ( std::ptrdiff_t offset)
inline

Definition at line 235 of file column.h.

236 {
237 _shift -= offset;
238 if (_shift >= _count) {
239 _shift -= _count;
240 }
241 else if (_shift < 0) {
242 _shift += _count;
243 }
244 refresh();
245 }

References olb::cpu::simd::CyclicColumn< T >::refresh().

+ Here is the call graph for this function:

◆ setProcessingContext()

template<typename T >
void olb::cpu::simd::CyclicColumn< T >::setProcessingContext ( ProcessingContext )
inline

Definition at line 252 of file column.h.

252{ };

◆ size()

template<typename T >
std::size_t olb::cpu::simd::CyclicColumn< T >::size ( ) const
inline

Definition at line 225 of file column.h.

226 {
227 return _count;
228 }

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