vector [DEPRECATED]#

Header file: <Kokkos_Vector.hpp> (deprecated in Kokkos 4.3)

The Kokkos Vector is semantically similar to the std::vector, but it is designed to overcome issues with memory allocations and copies when working with devices that have different memory spaces. The Kokkos::Vector is a Rank-1 DualView that implements the same interface as the std::vector. This allows programs that rely heavily on std::vector to grant access to program data from within a non-host execution space. Note that many of the std::vector compatible functions are host only, so access may be limited based on kernel complexity. Below is a synopsis of the class and the description for each method specifies whether it is supported on the host, device or both.

Usage#

Kokkos::vector<Scalar, Device> v(n,1);  // (deprecated since 4.3)
v.push_back(2);
v.resize(n+3);
v.[n+1] = 3;
v.[n+2] = 4;

Description#

template<class Scalar, class Arg1Type = void>
class vector : public DualView<Scalar*, LayoutLeft, Arg1Type>#

Public Typedefs

typedef Scalar value_type;#

Scalar value type

typedef Scalar *pointer;#

Scalar pointer type

typedef const Scalar *const_pointer;#

Const Scalar pointer type

typedef Scalar &reference;#

Scalar reference type

typedef const Scalar &const_reference;#

Const Scalar reference type

typedef Scalar *iterator;#

Iterator type

typedef const Scalar *const_iterator;#

Const iterator type

Accessors

KOKKOS_INLINE_FUNCTION reference operator()(int i) const;#

Accessor

Warning

Host only

KOKKOS_INLINE_FUNCTION reference operator[](int i) const;#

Accessor

Warning

Host only

Constructors

vector();#

Construct empty vector

vector(int n, Scalar val = Scalar());#

Construct vector of size n + 10% and initialize values to val

Other Public Methods

void resize(size_t n);#

Resize vector to size n + 10%

void resize(size_t n, const Scalar &val);#

Resize vector to size n + 10% and set values to val

void assign(size_t n, const Scalar &val);#

Set n values to val will auto synchronize between host and device

void reserve(size_t n);#

Same as resize (for compatibility)

void push_back(Scalar val);#

Resize vector to size() + 1 and set last value to val

Warning

Host only, auto synchronize device

void pop_back();#

Reduce size() by 1

void clear();#

Set size() to 0

size_type size() const;#

Return number of elements in vector

size_type max_size() const;#

Return maximum possible number of elements

size_type span() const;#

Return memory used by vector

bool empty() const;#

Returns true if vector is empty

pointer data() const;#

Returns pointer to the underlying array

Warning

Host only

iterator begin() const;#

Returns iterator starting at the beginning

Warning

Host only

iterator end() const;#

Returns iterator past the last element

Warning

Host only

reference front();#

Returns reference to the front of the list

Warning

Host only

reference back();#

Returns reference to the last element in the list

Warning

Host only

const_reference front() const;#

Returns const reference to the front of the list

Warning

Host only

const_reference back() const;#

Returns const reference to the last element in the list

Warning

Host only

size_t lower_bound(const size_t &start, const size_t &theEnd, const Scalar &comp_val) const;#

Return the index of largest value satisfying val < comp_val within the range start-theEnd

Warning

Host only

bool is_sorted();#

Return true if the list is sorted

iterator find(Scalar val) const;#

Return iterator pointing to element matching val

void device_to_host();#

Copy data from device to host

void host_to_device() const;#

Copy data from host to device

void on_host();#

Update/synchronize data in dual view from host perspective

void on_device();#

Update/synchronize data in dual view from the device perspective

void set_overallocation(float extra);#

Set the data buffer available at the end of the vector

constexpr bool is_allocated() const;#

Returns true if the internal views (host and device) are allocated (non-null pointers).