OpenLB 1.8.1
Loading...
Searching...
No Matches
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 override
 
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::AbstractCyclicColumn< T >
- 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 169 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 171 of file column.h.

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

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

◆ ~CyclicColumn()

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

Definition at line 213 of file column.h.

213 {
214 munmap(_buffer, 2 * _size);
215 close(_shm_file);
216 }

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 218 of file column.h.

219 {
220 return _f[i];
221 }

◆ 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 223 of file column.h.

224 {
225 return _f[i];
226 }

◆ postLoad()

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

Reimplemented from olb::Serializable.

Definition at line 263 of file column.h.

263{ 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 233 of file column.h.

234 {
235 _f = _base + _shift;
236 }
+ 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 250 of file column.h.

251 {
252 throw std::logic_error("Cyclic column can not be resized");
253 }

◆ rotate()

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

Definition at line 238 of file column.h.

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

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 255 of file column.h.

255{ };

◆ size()

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

Implements olb::AbstractCyclicColumn< T >.

Definition at line 228 of file column.h.

229 {
230 return _count;
231 }

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