ViennaCL - The Vienna Computing Library: viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT > Class Template Reference

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT > Class Template Reference

A STL-type const-iterator for vector elements. Elements can be accessed, but cannot be manipulated. VERY SLOW!! More...

`#include <forwards.h>`

## Public Types
typedef scalar< NumericT > | value_type
typedef vcl_size_t | size_type
typedef vcl_ptrdiff_t | difference_type
typedef viennacl::backend::mem_handle | handle_type

## Public Member Functions
| const_vector_iterator (vector_base< NumericT > const &vec, size_type index, size_type start=0, size_type stride=1)
| Constructor. More...
| const_vector_iterator (handle_type const &elements, size_type index, size_type start=0, size_type stride=1)
| Constructor for vector-like treatment of arbitrary buffers. More...
value_type | operator* (void) const
| Dereferences the iterator and returns the value of the element. For convenience only, performance is poor due to OpenCL overhead! More...
self_type | operator++ (void)
self_type | operator++ (int)
bool | operator== (self_type const &other) const
bool | operator!= (self_type const &other) const
difference_type | operator- (self_type const &other) const
self_type | operator+ (difference_type diff) const
size_type | offset () const
| Offset of the current element index with respect to the beginning of the buffer. More...
size_type | stride () const
| Index increment in the underlying buffer when incrementing the iterator to the next element. More...
handle_type const & | handle () const

## Protected Attributes
handle_type const & | elements_
| The index of the entry the iterator is currently pointing to. More...
size_type | index_
size_type | start_
size_type | stride_

## Detailed Description

### template<class SCALARTYPE, unsigned int ALIGNMENT>
class viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >

A STL-type const-iterator for vector elements. Elements can be accessed, but cannot be manipulated. VERY SLOW!!

Every dereference operation initiates a transfer from the GPU to the CPU. The overhead of such a transfer is around 50us, so 20.000 dereferences take one second. This is four orders of magnitude slower than similar dereferences on the CPU. However, increments and comparisons of iterators is as fast as for CPU types. If you need a fast iterator, copy the whole vector to the CPU first and iterate over the CPU object, e.g. std::vector<float> temp; copy(gpu_vector, temp); for (std::vector<float>::const_iterator iter = temp.begin(); iter != temp.end(); ++iter) { //do something } Note that you may obtain inconsistent data if entries of gpu_vector are manipulated elsewhere in the meanwhile.

Template Parameters

  NumericT | The underlying floating point type (either float or double)
  AlignmentV | Alignment of the underlying vector,

See Also
  vector

Definition at line 245 of file forwards.h.

## Member Typedef Documentation

template<class SCALARTYPE, unsigned int ALIGNMENT>

typedef vcl_ptrdiff_t viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::difference_type

Definition at line 114 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

typedef viennacl::backend::mem_handle viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::handle_type

Definition at line 115 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

typedef vcl_size_t viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::size_type

Definition at line 113 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

typedef scalar<NumericT> viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::value_type

Definition at line 112 of file vector.hpp.

## Constructor & Destructor Documentation

template<class SCALARTYPE, unsigned int ALIGNMENT>

viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::const_vector_iterator | ( | vector_base< NumericT > const & | vec,
|  | size_type | index,
|  | size_type | start = `0`,
|  | size_type | stride = `1`
| ) |  |
| inline

Constructor.

Parameters

  vec | The vector over which to iterate
  index | The starting index of the iterator
  start | First index of the element in the vector pointed to be the iterator (for vector_range and vector_slice)
  stride | Stride for the support of vector_slice

Definition at line 125 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::const_vector_iterator | ( | handle_type const & | elements,
|  | size_type | index,
|  | size_type | start = `0`,
|  | size_type | stride = `1`
| ) |  |
| inline

Constructor for vector-like treatment of arbitrary buffers.

Parameters

  elements | The buffer over which to iterate
  index | The starting index of the iterator
  start | First index of the element in the vector pointed to be the iterator (for vector_range and vector_slice)
  stride | Stride for the support of vector_slice

Definition at line 136 of file vector.hpp.

## Member Function Documentation

template<class SCALARTYPE, unsigned int ALIGNMENT>

handle_type const& viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::handle | ( |  | ) | const
| inline

Definition at line 174 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

size_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::offset | ( |  | ) | const
| inline

Offset of the current element index with respect to the beginning of the buffer.

Definition at line 170 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

bool viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::operator!= | ( | self_type const & | other | ) | const
| inline

Definition at line 152 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

value_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::operator* | ( | void |  | ) | const
| inline

Dereferences the iterator and returns the value of the element. For convenience only, performance is poor due to OpenCL overhead!

Definition at line 142 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

self_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::operator+ | ( | difference_type | diff | ) | const
| inline

Definition at line 166 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

self_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::operator++ | ( | void |  | ) |
| inline

Definition at line 148 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

self_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::operator++ | ( | int |  | ) |
| inline

Definition at line 149 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

difference_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::operator- | ( | self_type const & | other | ) | const
| inline

Definition at line 161 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

bool viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::operator== | ( | self_type const & | other | ) | const
| inline

Definition at line 151 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

size_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::stride | ( |  | ) | const
| inline

Index increment in the underlying buffer when incrementing the iterator to the next element.

Definition at line 173 of file vector.hpp.

## Member Data Documentation

template<class SCALARTYPE, unsigned int ALIGNMENT>

handle_type const& viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::elements_
| protected

The index of the entry the iterator is currently pointing to.

Definition at line 178 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

size_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::index_
| protected

Definition at line 179 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

size_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::start_
| protected

Definition at line 180 of file vector.hpp.

template<class SCALARTYPE, unsigned int ALIGNMENT>

size_type viennacl::const_vector_iterator< SCALARTYPE, ALIGNMENT >::stride_
| protected

Definition at line 181 of file vector.hpp.

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

- viennacl/forwards.h
- viennacl/vector.hpp