Go to the documentation of this file.
21 template<
typename T,
typename MemorySpace>
29 if(
n > this->capacity() )
31 uint32 newCap = evalCapacity(
n);
32 changeCapacity(newCap, withInit);
37 template<
typename T,
typename MemorySpace>
46 changeCapacity(actualCap, withInit);
50 template<
typename T,
typename MemorySpace>
70 template<
typename T,
typename MemorySpace>
82 template<
typename T,
typename MemorySpace>
94 template<
typename T,
typename MemorySpace>
100 template<
typename T,
typename MemorySpace>
107 template<
typename T,
typename MemorySpace>
115 view_(name, evalCapacity(
n))
118 template<
typename T,
typename MemorySpace>
131 template<
typename T,
typename MemorySpace>
144 template<
typename T,
typename MemorySpace>
148 const std::vector<T> & src
156 template<
typename T,
typename MemorySpace>
160 const std::vector<T> & src,
169 template<
typename T,
typename MemorySpace>
178 template<
typename T,
typename MemorySpace>
190 template<
typename T,
typename MemorySpace>
199 copy(deviceView(), src);
202 template<
typename T,
typename MemorySpace>
206 if(&rhs ==
this)
return *
this;
215 template<
typename T,
typename MemorySpace>
222 template<
typename T,
typename MemorySpace>
227 return makeUnique<VectorSingle>( this->name(), *
this);
231 template<
typename T,
typename MemorySpace>
239 template<
typename T,
typename MemorySpace>
247 template<
typename T,
typename MemorySpace>
254 template<
typename T,
typename MemorySpace>
261 template<
typename T,
typename MemorySpace>
265 return Kokkos::subview(
267 Kokkos::make_pair(0u,
static_cast<uint32>(size_)));
270 template<
typename T,
typename MemorySpace>
274 auto hView = Kokkos::create_mirror_view(view_);
279 template<
typename T,
typename MemorySpace>
283 auto hView = Kokkos::create_mirror_view(deviceView());
284 copy(hView, deviceView());
288 template<
typename T,
typename MemorySpace>
292 return view_.label();
295 template<
typename T,
typename MemorySpace>
302 template<
typename T,
typename MemorySpace>
306 return view_.extent(0);
309 template<
typename T,
typename MemorySpace>
316 template<
typename T,
typename MemorySpace>
320 if(cap == capacity() )
return;
324 template<
typename T,
typename MemorySpace>
328 reallocateCapacitySize(cap, 0);
331 template<
typename T,
typename MemorySpace>
339 reallocateCapacitySize(cap, newSize);
342 template<
typename T,
typename MemorySpace>
349 template<
typename T,
typename MemorySpace>
356 template<
typename T,
typename MemorySpace>
363 template<
typename T,
typename MemorySpace>
371 template<
typename T,
typename MemorySpace>
383 template<
typename T,
typename MemorySpace>
394 reallocateCapacitySize(evalCapacity(
n),
n);
403 template<
typename T,
typename MemorySpace>
407 const std::vector<T>& src,
413 uint32 srcSize = src.size();
415 if(newCap != capacity())
417 reallocateCapacitySize(newCap, srcSize);
426 copy(deviceView(), temp);
430 template<
typename T,
typename MemorySpace>
434 const std::vector<T>& src
437 assign(src, this->capacity());
440 template<
typename T,
typename MemorySpace>
447 if(srcCap != capacity())
449 reallocateCapacitySize(srcCap, srcSize);
460 template<
typename T,
typename MemorySpace>
471 if(srcCapacity && srcCap != capacity())
473 reallocateCapacitySize(srcCap, srcSize);
484 template<
typename T,
typename MemorySpace>
485 template<
typename MSpace>
495 if(srcCapacity && srcCap != capacity()){
496 reallocateCapacitySize(srcCap, srcSize);
504 template <
typename T,
typename MemorySpace>
508 uint32 appSize = appVec.size();
509 if(appSize == 0)
return;
512 uint32 newSize = oldS + appSize;
516 auto appendView = Kokkos::subview(
518 Kokkos::make_pair<uint32>(oldS, newSize));
520 copy(appendView, appVec);
524 template <
typename T,
typename MemorySpace>
528 const std::vector<T> &appVec
531 if(appVec.empty())
return;
533 auto srcSize = appVec.size();
535 uint32 newSize = srcSize + oldSize;
540 auto dest = Kokkos::subview(view_, Kokkos::make_pair<uint32>(oldSize,newSize));
545 template <
typename T,
typename MemorySpace>
553 if(appSize == 0)
return;
556 uint32 newSize = oldS + appSize;
560 auto appendView = Kokkos::subview(
562 Kokkos::make_pair<uint32>(oldS, newSize));
568 template <
typename T,
typename MemorySpace>
571 return span<T>(view_.data(), size());
574 template<
typename T,
typename MemorySpace>
578 return span<T>(
const_cast<T*
>(view_.data()), this->size());
581 template<
typename T,
typename MemorySpace>
585 if(indices.
empty())
return true;
587 auto maxInd = indices.
max();
589 if(this->
empty() || maxInd > size()-1 )
594 using policy = Kokkos::RangePolicy<execution_space,Kokkos::IndexType<uint32>>;
596 if constexpr( isDeviceAccessible_ )
601 Kokkos::parallel_for(
602 "VectorSingle::insertSetElement",
616 Kokkos::parallel_for(
617 "VectorSingle::insertSetElement",
631 template<
typename T,
typename MemorySpace>
636 const std::vector<T>& vals
640 if(indices.
empty())
return true;
641 if(indices.
size() != vals.size())
return false;
643 auto maxInd = indices.
max();
645 if(this->
empty() || maxInd > size()-1 )
650 using policy = Kokkos::RangePolicy<execution_space,Kokkos::IndexType<uint32>>;
654 if constexpr( isDeviceAccessible_ )
661 Kokkos::parallel_for(
662 "VectorSingle::insertSetElement",
664 dVec(ind(i))= dVals(i);});
673 Kokkos::parallel_for(
674 "VectorSingle::insertSetElement",
676 dVec(ind(i))= hVals(i);});
684 template<
typename T,
typename MemorySpace>
692 if(indices.
empty())
return true;
693 if(indices.
size() != vals.size())
return false;
695 auto maxInd = indices.
max();
697 if(this->
empty() || maxInd > size()-1 )
702 using policy = Kokkos::RangePolicy<
704 Kokkos::IndexType<uint32>>;
706 if constexpr( isDeviceAccessible_ )
712 Kokkos::parallel_for(
713 "VectorSingle::insertSetElement",
715 dVec(ind(i))= dVals(i);});
725 Kokkos::parallel_for(
726 "VectorSingle::insertSetElement",
728 dVec(ind(i))= hVals(i);});
736 template<
typename T,
typename MemorySpace>
740 if(indices.
size() == 0)
746 auto maxInd = indices.
max();
748 if(maxInd >= this->size())
751 << this->name()<<
") maximum index ("<< maxInd <<
752 ") exceeds the size of the vector (" << this->size()<<
")"<<
endl;
758 viewType sortedView(this->name(), newSize);
760 using policy = Kokkos::RangePolicy< execution_space,Kokkos::IndexType<uint32>>;
762 if constexpr( isDeviceAccessible_)
769 "VectorSingle::sortItems",
773 sortedView(i) = d_view(d_indices(i));
782 auto h_indices = indices.
hostView();
787 "VectorSingle::sortItems",
791 sortedView(i) = d_view(h_indices(i));
800 copy(deviceView(), sortedView);
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.
INLINE_FUNCTION_H void resize(uint32 n)
Resize the vector and preserve the content.
INLINE_FUNCTION_H void resizeNoInit(ViewType1D< Type, Properties... > &view, uint32 newLen)
INLINE_FUNCTION_H void append(const ViewType1D< T, MemorySpace > &appVec)
void fill(Vector< T, Allocator > &vec, const T &val)
VectorSingle()
Empty vector.
INLINE_FUNCTION_H void assignFromDevice(const VectorSingle< T, MSpace > &src, bool srcCapacity=true)
INLINE_FUNCTION_HD IndexType max() const
Max value of indices.
INLINE_FUNCTION_HD T & end()
End.
INLINE_FUNCTION_H Type max(const Type *first, uint32 numElems)
INLINE_FUNCTION_H void copy(const ViewType1D< dType, dProperties... > &dst, const ViewType1D< sType, sProperties... > &src)
INLINE_FUNCTION_H void reallocate(uint32 cap)
Reallocate memory to new cap and set size to 0.
INLINE_FUNCTION_H void clear()
Clear the vector, but keep the allocated memory unchanged.
INLINE_FUNCTION_H uint32 setSize(uint32 n)
INLINE_FUNCTION_H void reallocNoInit(ViewType1D< Type, Properties... > &view, uint32 len)
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.
iOstream & endl(iOstream &os)
Add newline and flush stream.
INLINE_FUNCTION_H bool empty() const
If vector is empty.
Kokkos::View< T * > deviceViewType1D
1D array (vector) with default device (memory space and execution space)
Kokkos::RangePolicy< pFlow::DefaultExecutionSpace, Kokkos::Schedule< Kokkos::Static >, Kokkos::IndexType< pFlow::uint32 > > policy
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)
const HostViewType & hostView() const
Return Host veiw.
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...
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
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)
void fill(Vector< T, Allocator > &vec, const T &val)
#define INLINE_FUNCTION_H
INLINE_FUNCTION_HD bool empty() const
If the container empty.
INLINE_FUNCTION_H void resizeInit(ViewType1D< Type, Properties... > &view, uint32 newLen)
INLINE_FUNCTION_H auto & deviceViewAll()
Device view range [0,capcity)
Kokkos::View< T *, properties... > ViewType1D
1D veiw as a vector
Kokkos::View< T *, Kokkos::HostSpace > hostViewType1D
1D array (vector with host memeory space)
INLINE_FUNCTION_H auto hostViewAll() const
Return a view accessible on Host in range [0,capacity)
INLINE_FUNCTION_H void assign(size_t n, const T &val)
Change size of the vector and assign val to vector and.
INLINE_FUNCTION_H uint32 capacity() const
INLINE_FUNCTION_H VectorType & VectorField()
Return *this.
INLINE_FUNCTION_HD auto size() const
Size.
INLINE_FUNCTION_H uint32 reallocateCapacitySize(uint32 cap, uint32 s)
VectorSingle & operator=(const VectorSingle &rhs)
Copy assignment (perform deep copy from rhs to *this)
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.
const DeviceViewType & deviceView() const
Return Device view.
ViewType1D< uint32, HostSpace > viewType
viewType view_
view of the vector