OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
Public Member Functions | Private Attributes | List of all members
FieldArray Class Reference

#include <FieldArray.h>

Public Member Functions

 FieldArray ()=default
 
 ~FieldArray ()
 
 FieldArray (const FieldArray &)=delete
 
FieldArray & operator= (const FieldArray &)=delete
 
std::size_t size () const
 Number of samples. Zero for an array that has not been filled.
 
bool empty () const
 
double operator[] (std::size_t i) const
 
const double * data () const
 
bool anyNonZero (std::size_t begin, std::size_t end) const
 
bool isMapped () const
 
void allocate (std::size_t n)
 
double * mutableData ()
 
bool tryMap (const std::string &filename, const std::string &dataset, std::size_t expectedSamples, std::string &why)
 
void reset ()
 Release the buffer or the mapping.
 

Private Attributes

const double * data_m = nullptr
 what operator[] reads; into owned_m or the mapping
 
std::size_t size_m = 0
 samples, not bytes
 
std::vector< double > owned_m
 used when not mapped
 
void * mapping_m = nullptr
 page-aligned mmap base, null when not mapped
 
std::size_t mapBytes_m = 0
 length passed to mmap, for munmap
 

Detailed Description

Definition at line 38 of file FieldArray.h.

Constructor & Destructor Documentation

◆ FieldArray() [1/2]

FieldArray::FieldArray ( )
default

◆ ~FieldArray()

FieldArray::~FieldArray ( )
inline

Definition at line 41 of file FieldArray.h.

References reset().

Here is the call graph for this function:

◆ FieldArray() [2/2]

FieldArray::FieldArray ( const FieldArray &  )
delete

Member Function Documentation

◆ allocate()

void FieldArray::allocate ( std::size_t  n)

Allocate a writable buffer of n samples, zero filled. Releases any previous contents, including a mapping.

Definition at line 37 of file FieldArray.cpp.

References data_m, owned_m, reset(), and size_m.

Referenced by _FM3DH5Block::readMap(), _FM3DH5Block_nonscale::readMap(), and _FM3DMagnetoStaticH5Block::readMap().

Here is the call graph for this function:

◆ anyNonZero()

bool FieldArray::anyNonZero ( std::size_t  begin,
std::size_t  end 
) const

True if any sample in [begin, end) is nonzero; NaN counts as nonzero. For a mapped array the range is read with sequential readahead: this is a one-off pass, not the random gather of tracking.

Definition at line 138 of file FieldArray.cpp.

References begin(), data_m, end(), mapping_m, and size_m.

Referenced by _FM3DH5BlockBase::anyNonZero().

Here is the call graph for this function:

◆ data()

const double * FieldArray::data ( ) const
inline

Definition at line 54 of file FieldArray.h.

References data_m.

◆ empty()

bool FieldArray::empty ( ) const
inline

◆ isMapped()

bool FieldArray::isMapped ( ) const
inline

True when the samples are a view of a mapped file rather than our own buffer. Callers that modify the samples in place must check this.

Definition at line 63 of file FieldArray.h.

References mapping_m.

◆ mutableData()

double * FieldArray::mutableData ( )
inline

Writable pointer, for handing to a reader. Null when the array is mapped; a mapped array is read-only by construction.

Definition at line 71 of file FieldArray.h.

References owned_m.

Referenced by _FM3DH5Block::readMap(), _FM3DH5Block_nonscale::readMap(), and _FM3DMagnetoStaticH5Block::readMap().

◆ operator=()

FieldArray & FieldArray::operator= ( const FieldArray &  )
delete

◆ operator[]()

double FieldArray::operator[] ( std::size_t  i) const
inline

Read access. This is the hot path: one load through a pointer the caller already has, exactly as indexing a vector was.

Definition at line 52 of file FieldArray.h.

References data_m.

◆ reset()

void FieldArray::reset ( )

◆ size()

std::size_t FieldArray::size ( ) const
inline

Number of samples. Zero for an array that has not been filled.

Definition at line 47 of file FieldArray.h.

References size_m.

Referenced by _FM3DH5BlockBase::anyNonZero().

◆ tryMap()

bool FieldArray::tryMap ( const std::string &  filename,
const std::string &  dataset,
std::size_t  expectedSamples,
std::string &  why 
)

Try to back this array by a read-only mapping of one dataset of an HDF5 file. Returns false, leaving the array untouched, if the file cannot be opened, the dataset is absent, or its layout is not one we can map directly. why receives a short reason on failure, for the log.

Definition at line 55 of file FieldArray.cpp.

References data_m, mapBytes_m, mapping_m, reset(), and size_m.

Here is the call graph for this function:

Member Data Documentation

◆ data_m

const double* FieldArray::data_m = nullptr
private

what operator[] reads; into owned_m or the mapping

Definition at line 86 of file FieldArray.h.

Referenced by allocate(), anyNonZero(), data(), operator[](), reset(), and tryMap().

◆ mapBytes_m

std::size_t FieldArray::mapBytes_m = 0
private

length passed to mmap, for munmap

Definition at line 90 of file FieldArray.h.

Referenced by reset(), and tryMap().

◆ mapping_m

void* FieldArray::mapping_m = nullptr
private

page-aligned mmap base, null when not mapped

Definition at line 89 of file FieldArray.h.

Referenced by anyNonZero(), isMapped(), reset(), and tryMap().

◆ owned_m

std::vector<double> FieldArray::owned_m
private

used when not mapped

Definition at line 88 of file FieldArray.h.

Referenced by allocate(), mutableData(), and reset().

◆ size_m

std::size_t FieldArray::size_m = 0
private

samples, not bytes

Definition at line 87 of file FieldArray.h.

Referenced by allocate(), anyNonZero(), empty(), reset(), size(), and tryMap().


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