Go to the documentation of this file.
20 #ifndef __VectorSingle_hpp__
21 #define __VectorSingle_hpp__
43 template<
typename T,
typename MemorySpace=
void>
260 void fill(
const T& val);
267 void assign(
size_t n,
const T& val);
279 void assign(
const std::vector<T>& src);
290 template<
typename MSpace>
298 void append(
const std::vector<T>& appVec);
325 template<
bool Enable = true>
327 typename std::enable_if_t<isHostAccessible_ && Enable, void>
345 template<
bool Enable = true>
347 typename std::enable_if_t<isHostAccessible_ && Enable,iterator>
353 template<
bool Enable = true>
355 typename std::enable_if_t<isHostAccessible_ && Enable,const_iterator>
362 template<
bool Enable = true>
364 typename std::enable_if_t<isHostAccessible_ && Enable,iterator>
371 template<
bool Enable = true>
373 typename std::enable_if_t<isHostAccessible_ && Enable,const_iterator>
379 template<
bool Enable = true>
381 typename std::enable_if_t<isHostAccessible_ && Enable,reference>
387 template<
bool Enable = true>
389 typename std::enable_if_t<isHostAccessible_ && Enable,const_reference>
400 std::vector<T> vecFromFile;
403 this->
assign(vecFromFile);
412 std::vector<T> vecFromFile;
414 this->
assign(vecFromFile);
424 auto sp =
span<T>(
const_cast<T*
>(hVec.data()), hVec.size());
434 auto sp =
span<T>(
const_cast<T*
>(hVec.data()), hVec.size());
440 template<
typename HostMask>
446 auto numActive = mask.numActive();
447 std::vector<T> finalField;
449 finalField.reserve(numActive);
451 uint32 start = mask.activeRange().start();
457 finalField.push_back(hVec[i]);
460 auto sp =
span<T>( finalField.data(), finalField.size());
471 return memory_space::name();
476 template<
typename T,
typename MemorySpace>
487 template<
typename T,
typename MemorySpace>
491 if( !ovec.
write(os) )
509 #endif //__VectorSingle_hpp__
INLINE_FUNCTION_H std::enable_if_t< isHostAccessible_ &&Enable, reference > operator[](size_t i)
Return reference to element i. it works when host is accessible.
INLINE_FUNCTION_H void fill(const T &val)
Fill the range [0,size) with val.
INLINE_FUNCTION_H void reserve(uint32 cap)
Reserve capacity for vector Preserve the content.
const uint32 * const_pointer
INLINE_FUNCTION_H std::enable_if_t< isHostAccessible_ &&Enable, const_iterator > begin() const
Return begin iterator. it works when host is accessible.
INLINE_FUNCTION_H void resize(uint32 n)
Resize the vector and preserve the content.
INLINE_FUNCTION_H void append(const ViewType1D< T, MemorySpace > &appVec)
#define fatalExit
Fatal exit.
bool readStdVector(iIstream &is, std::vector< T, Allocator > &vec)
VectorSingle()
Empty vector.
INLINE_FUNCTION_H void assignFromDevice(const VectorSingle< T, MSpace > &src, bool srcCapacity=true)
INLINE_FUNCTION_H std::enable_if_t< isHostAccessible_ &&Enable, iterator > begin()
Return begin iterator. It works when devices is host accessible.
INLINE_FUNCTION_H void reallocate(uint32 cap)
Reallocate memory to new cap and set size to 0.
INLINE_FUNCTION_H std::enable_if_t< isHostAccessible_ &&Enable, void > push_back(const T &val)
push a new element at the end (host call only) resize if necessary and works on host accessible vecto...
INLINE_FUNCTION_H void clear()
Clear the vector, but keep the allocated memory unchanged.
FUNCTION_H bool read(iIstream &is)
Read vector from stream.
INLINE_FUNCTION_H uint32 setSize(uint32 n)
FUNCTION_H bool write(iOstream &os, const IOPattern &iop, const HostMask &mask) const
INLINE_FUNCTION_H uniquePtr< VectorSingle > clone() const
Clone as a uniquePtr (perform deep copy)
INLINE_FUNCTION_H uint32 changeCapacitySize(uint32 actualCap, uint32 n, bool withInit=false)
Change the size and capacity of Vector.
INLINE_FUNCTION_H bool empty() const
If vector is empty.
typename viewType::memory_space memory_space
FUNCTION_H bool read(iIstream &is, const IOPattern &iop)
Read vector from stream.
typename viewType::execution_space execution_space
INLINE_FUNCTION_H bool reorderItems(const uint32IndexContainer &indices)
INLINE_FUNCTION_H auto deviceView() const
Device view range [0, size)
INLINE_FUNCTION_H word name() const
Name of the vector.
INLINE_FUNCTION_H void changeCapacity(uint32 actualCap, bool withInit=false)
uint32 size_
Size of the vector.
typename viewType::device_type device_type
Interface class for any input stream
INLINE_FUNCTION_H pointer data()
INLINE_FUNCTION_H void assignFromHost(const VectorTypeHost &src)
Assign source vector from host side.
~VectorSingle()
Descructor This may not destroy the underlying memory, sice view is shared_ptr and maybe referenced b...
static INLINE_FUNCTION_H uint32 evalCapacity(uint32 n)
Evaluate capacity based on the input size.
INLINE_FUNCTION_H auto getSpan()
INLINE_FUNCTION_H uint32 changeSize(uint32 n, bool withInit=false)
Change size to n and preserve the conetent if realloc occurs
INLINE_FUNCTION_H auto hostView() const
Return a view accessible on Host in range [0,size)
const uint32 * const_iterator
TypeInfoTemplateNV111("VectorSingle", T, memoerySpaceName())
Type info.
INLINE_FUNCTION_H std::enable_if_t< isHostAccessible_ &&Enable, iterator > end()
Return end iterator. it works when host is accessible.
VectorSingle< T, HostSpace > VectorTypeHost
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
const double vectorGrowthFactor__
#define INLINE_FUNCTION_H
bool writeSpan(iOstream &os, span< T > sp)
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
INLINE_FUNCTION_H std::enable_if_t< isHostAccessible_ &&Enable, const_reference > operator[](size_t i) const
Return reference to element i. it works when host is accessible.
virtual const word & name() const
Return the name of the stream.
static constexpr bool isDeviceAccessible_
Is the memory of this vector accessiple from Divce.
INLINE_FUNCTION_H const_pointer data() const
INLINE_FUNCTION_H auto & deviceViewAll()
Device view range [0,capcity)
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
INLINE_FUNCTION_H std::enable_if_t< isHostAccessible_ &&Enable, const_iterator > end() const
Return end iterator. it works when host is accessible.
INLINE_FUNCTION_H auto hostViewAll() const
Return a view accessible on Host in range [0,capacity)
static constexpr const char * memoerySpaceName()
Name of the memory space.
INLINE_FUNCTION_H void assign(size_t n, const T &val)
Change size of the vector and assign val to vector and.
FUNCTION_H bool write(iOstream &os, const IOPattern &iop) const
Write the vector to os.
FUNCTION_H bool write(iOstream &os) const
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
INLINE_FUNCTION_H uint32 capacity() const
INLINE_FUNCTION_H VectorType & VectorField()
Return *this.
int32 lineNumber() const
Const access to the current stream line number.
VectorSingle< T, MemorySpace > VectorType
static constexpr bool isHostAccessible_
Is the memory of this vector accessible from Host.
INLINE_FUNCTION_H uint32 reallocateCapacitySize(uint32 cap, uint32 s)
VectorSingle & operator=(const VectorSingle &rhs)
Copy assignment (perform deep copy from rhs to *this)
Interface class for any output stream.
static constexpr bool isTriviallyCopyable_
const uint32 & const_reference
INLINE_FUNCTION_H bool insertSetElement(const uint32IndexContainer &indices, const T &val)
It holds two vectors of indecis on Host and Device.
INLINE_FUNCTION_H uint32 size() const
Size of the vector.
ViewType1D< uint32, HostSpace > viewType
viewType view_
view of the vector