Itoyori  v0.0.1
ityr::global_vector< T > Class Template Reference

Global vector to manage a global memory region. More...

#include <global_vector.hpp>

Public Types

using element_type = T
 
using value_type = std::remove_cv_t< element_type >
 
using size_type = std::size_t
 
using pointer = ori::global_ptr< element_type >
 
using const_pointer = ori::global_ptr< std::add_const_t< element_type > >
 
using difference_type = typename std::iterator_traits< pointer >::difference_type
 
using reference = typename std::iterator_traits< pointer >::reference
 
using const_reference = typename std::iterator_traits< const_pointer >::reference
 
using iterator = pointer
 
using const_iterator = const_pointer
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

 global_vector () noexcept
 
 global_vector (size_type count)
 
 global_vector (size_type count, const value_type &value)
 
template<typename InputIterator >
 global_vector (InputIterator first, InputIterator last)
 
 global_vector (std::initializer_list< T > il)
 
 global_vector (const global_vector_options &opts) noexcept
 
 global_vector (const global_vector_options &opts, size_type count)
 
 global_vector (const global_vector_options &opts, size_type count, const T &value)
 
template<typename InputIterator , typename = std::enable_if_t<std::is_convertible_v<typename std::iterator_traits<InputIterator>::iterator_category, std::input_iterator_tag>>>
 global_vector (const global_vector_options &opts, InputIterator first, InputIterator last)
 
 global_vector (const global_vector_options &opts, std::initializer_list< T > il)
 
 ~global_vector ()
 
 global_vector (const this_t &other)
 
this_toperator= (const this_t &other)
 
 global_vector (this_t &&other) noexcept
 
this_toperator= (this_t &&other) noexcept
 
pointer data () noexcept
 
const_pointer data () const noexcept
 
size_type size () const noexcept
 
size_type capacity () const noexcept
 
global_vector_options options () const noexcept
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
reverse_iterator rbegin () const noexcept
 
reverse_iterator rend () const noexcept
 
const_reverse_iterator rbegin () noexcept
 
const_reverse_iterator rend () noexcept
 
const_reverse_iterator crbegin () const noexcept
 
const_reverse_iterator crend () const noexcept
 
reference operator[] (size_type i)
 
const_reference operator[] (size_type i) const
 
reference at (size_type i)
 
const_reference at (size_type i) const
 
reference front ()
 
reference back ()
 
const_reference front () const
 
const_reference back () const
 
bool empty () const noexcept
 
void swap (this_t &other) noexcept
 
void clear ()
 
void reserve (size_type new_cap)
 
void resize (size_type count)
 
void resize (size_type count, const value_type &value)
 
void push_back (const value_type &value)
 
void push_back (value_type &&value)
 
template<typename... Args>
reference emplace_back (Args &&... args)
 
void pop_back ()
 
iterator insert (const_iterator position, const T &x)
 
iterator insert (const_iterator position, T &&x)
 
iterator insert (const_iterator position, size_type n, const T &x)
 
template<typename InputIterator , typename = std::enable_if_t<std::is_convertible_v<typename std::iterator_traits<InputIterator>::iterator_category, std::input_iterator_tag>>>
iterator insert (const_iterator position, InputIterator first, InputIterator last)
 
iterator insert (const_iterator position, std::initializer_list< T > il)
 
template<typename... Args>
iterator emplace (const_iterator position, Args &&... args)
 

Detailed Description

template<typename T>
class ityr::global_vector< T >

Global vector to manage a global memory region.

A global vector is a container for managing a contiguous global memory region. This resembles the standard std::vector container and has some extensions for global memory.

As a global vector manages global memory, its elements cannot be directly accessed. Access to its elements must be granted by checkout/checkin operations (e.g., ityr::make_checkout()).

A global vector can accept ityr::global_vector_options as the first argument when initialized. Global vectors have two types (collective or noncollective), which can be configured with the ityr::global_vector_options::collective option.

  • A collective global vector must be allocated and deallocated by all processes collectively, either in the SPMD region or in the root thread. Its global memory is distributed to the processes by following the memory distribution policy. Some operations that modify the vector capacity (e.g., push_back()) are not permitted in the fork-join region (except for the root thread) for collective global vectors.
  • A noncollective global vector can be independently allocated and deallocated in each process. Its memory is allocated in the local process and can be deallocated from any other processes.

Once allocated, both global vectors can be uniformly accessed by global iterators, for example.

Example:

assert(ityr::is_spmd());
// Collective global vector's memory is distributed to all processes
// (Note: This example vector is too small to be distributed to multiple processes.)
ityr::global_vector<int> v_coll({.collective = true}, {1, 2, 3, 4, 5});
// Create a global span to prevent copying the global vector
ityr::global_span<int> s_coll(v_coll);
// Noncollective global vector's memory is allocated in the local process
ityr::global_vector<int> v_noncoll = {2, 3, 4, 5, 6};
// Calculate a dot product of the collective and noncollective vectors in parallel
s_coll.begin(), s_coll.end(), v_noncoll.begin(), 0);
// dot = 70
});
Global span to represent a view of a global memory range.
Definition: global_span.hpp:33
Global vector to manage a global memory region.
Definition: global_vector.hpp:129
iterator begin() noexcept
Definition: global_vector.hpp:233
constexpr parallel_policy par
Default parallel execution policy for iterator-based loop functions.
Definition: execution.hpp:89
bool is_spmd()
Return true if the current execution context is within the SPMD region.
Definition: ityr.hpp:143
auto root_exec(Fn &&fn, Args &&... args)
Spawn the root thread (collective).
Definition: root_exec.hpp:47
Reducer::accumulator_type transform_reduce(const ExecutionPolicy &policy, ForwardIterator first, ForwardIterator last, Reducer reducer, UnaryTransformOp unary_transform_op)
Calculate reduction while transforming each element.
Definition: parallel_reduce.hpp:167

In addition, the construction and destruction of vector elements can also be parallelized by setting the ityr::global_vector_options::parallel_construct and ityr::global_vector_options::parallel_destruct options. The cutoff count for leaf tasks can be configured by the ityr::global_vector_options::cutoff_count option. Destruction for elements may be skipped if T is trivially destructive.

See also
std::vector – cppreference.com
ityr::global_vector_options
ityr::global_span.

Member Typedef Documentation

◆ const_iterator

template<typename T >
using ityr::global_vector< T >::const_iterator = const_pointer

◆ const_pointer

template<typename T >
using ityr::global_vector< T >::const_pointer = ori::global_ptr<std::add_const_t<element_type> >

◆ const_reference

template<typename T >
using ityr::global_vector< T >::const_reference = typename std::iterator_traits<const_pointer>::reference

◆ const_reverse_iterator

template<typename T >
using ityr::global_vector< T >::const_reverse_iterator = std::reverse_iterator<const_iterator>

◆ difference_type

template<typename T >
using ityr::global_vector< T >::difference_type = typename std::iterator_traits<pointer>::difference_type

◆ element_type

template<typename T >
using ityr::global_vector< T >::element_type = T

◆ iterator

template<typename T >
using ityr::global_vector< T >::iterator = pointer

◆ pointer

template<typename T >
using ityr::global_vector< T >::pointer = ori::global_ptr<element_type>

◆ reference

template<typename T >
using ityr::global_vector< T >::reference = typename std::iterator_traits<pointer>::reference

◆ reverse_iterator

template<typename T >
using ityr::global_vector< T >::reverse_iterator = std::reverse_iterator<iterator>

◆ size_type

template<typename T >
using ityr::global_vector< T >::size_type = std::size_t

◆ value_type

template<typename T >
using ityr::global_vector< T >::value_type = std::remove_cv_t<element_type>

Constructor & Destructor Documentation

◆ global_vector() [1/12]

template<typename T >
ityr::global_vector< T >::global_vector ( )
inlinenoexcept

◆ global_vector() [2/12]

template<typename T >
ityr::global_vector< T >::global_vector ( size_type  count)
inlineexplicit

◆ global_vector() [3/12]

template<typename T >
ityr::global_vector< T >::global_vector ( size_type  count,
const value_type value 
)
inlineexplicit

◆ global_vector() [4/12]

template<typename T >
template<typename InputIterator >
ityr::global_vector< T >::global_vector ( InputIterator  first,
InputIterator  last 
)
inline

◆ global_vector() [5/12]

template<typename T >
ityr::global_vector< T >::global_vector ( std::initializer_list< T >  il)
inline

◆ global_vector() [6/12]

template<typename T >
ityr::global_vector< T >::global_vector ( const global_vector_options opts)
inlineexplicitnoexcept

◆ global_vector() [7/12]

template<typename T >
ityr::global_vector< T >::global_vector ( const global_vector_options opts,
size_type  count 
)
inlineexplicit

◆ global_vector() [8/12]

template<typename T >
ityr::global_vector< T >::global_vector ( const global_vector_options opts,
size_type  count,
const T &  value 
)
inlineexplicit

◆ global_vector() [9/12]

template<typename T >
template<typename InputIterator , typename = std::enable_if_t<std::is_convertible_v<typename std::iterator_traits<InputIterator>::iterator_category, std::input_iterator_tag>>>
ityr::global_vector< T >::global_vector ( const global_vector_options opts,
InputIterator  first,
InputIterator  last 
)
inline

◆ global_vector() [10/12]

template<typename T >
ityr::global_vector< T >::global_vector ( const global_vector_options opts,
std::initializer_list< T >  il 
)
inline

◆ ~global_vector()

template<typename T >
ityr::global_vector< T >::~global_vector ( )
inline

◆ global_vector() [11/12]

template<typename T >
ityr::global_vector< T >::global_vector ( const this_t other)
inline

◆ global_vector() [12/12]

template<typename T >
ityr::global_vector< T >::global_vector ( this_t &&  other)
inlinenoexcept

Member Function Documentation

◆ at() [1/2]

template<typename T >
reference ityr::global_vector< T >::at ( size_type  i)
inline

◆ at() [2/2]

template<typename T >
const_reference ityr::global_vector< T >::at ( size_type  i) const
inline

◆ back() [1/2]

template<typename T >
reference ityr::global_vector< T >::back ( )
inline

◆ back() [2/2]

template<typename T >
const_reference ityr::global_vector< T >::back ( ) const
inline

◆ begin() [1/2]

template<typename T >
const_iterator ityr::global_vector< T >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<typename T >
iterator ityr::global_vector< T >::begin ( )
inlinenoexcept

◆ capacity()

template<typename T >
size_type ityr::global_vector< T >::capacity ( ) const
inlinenoexcept

◆ cbegin()

template<typename T >
const_iterator ityr::global_vector< T >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<typename T >
const_iterator ityr::global_vector< T >::cend ( ) const
inlinenoexcept

◆ clear()

template<typename T >
void ityr::global_vector< T >::clear ( )
inline

◆ crbegin()

template<typename T >
const_reverse_iterator ityr::global_vector< T >::crbegin ( ) const
inlinenoexcept

◆ crend()

template<typename T >
const_reverse_iterator ityr::global_vector< T >::crend ( ) const
inlinenoexcept

◆ data() [1/2]

template<typename T >
const_pointer ityr::global_vector< T >::data ( ) const
inlinenoexcept

◆ data() [2/2]

template<typename T >
pointer ityr::global_vector< T >::data ( )
inlinenoexcept

◆ emplace()

template<typename T >
template<typename... Args>
iterator ityr::global_vector< T >::emplace ( const_iterator  position,
Args &&...  args 
)
inline

◆ emplace_back()

template<typename T >
template<typename... Args>
reference ityr::global_vector< T >::emplace_back ( Args &&...  args)
inline

◆ empty()

template<typename T >
bool ityr::global_vector< T >::empty ( ) const
inlinenoexcept

◆ end() [1/2]

template<typename T >
const_iterator ityr::global_vector< T >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<typename T >
iterator ityr::global_vector< T >::end ( )
inlinenoexcept

◆ front() [1/2]

template<typename T >
reference ityr::global_vector< T >::front ( )
inline

◆ front() [2/2]

template<typename T >
const_reference ityr::global_vector< T >::front ( ) const
inline

◆ insert() [1/5]

template<typename T >
iterator ityr::global_vector< T >::insert ( const_iterator  position,
const T &  x 
)
inline

◆ insert() [2/5]

template<typename T >
template<typename InputIterator , typename = std::enable_if_t<std::is_convertible_v<typename std::iterator_traits<InputIterator>::iterator_category, std::input_iterator_tag>>>
iterator ityr::global_vector< T >::insert ( const_iterator  position,
InputIterator  first,
InputIterator  last 
)
inline

◆ insert() [3/5]

template<typename T >
iterator ityr::global_vector< T >::insert ( const_iterator  position,
size_type  n,
const T &  x 
)
inline

◆ insert() [4/5]

template<typename T >
iterator ityr::global_vector< T >::insert ( const_iterator  position,
std::initializer_list< T >  il 
)
inline

◆ insert() [5/5]

template<typename T >
iterator ityr::global_vector< T >::insert ( const_iterator  position,
T &&  x 
)
inline

◆ operator=() [1/2]

template<typename T >
this_t& ityr::global_vector< T >::operator= ( const this_t other)
inline

◆ operator=() [2/2]

template<typename T >
this_t& ityr::global_vector< T >::operator= ( this_t &&  other)
inlinenoexcept

◆ operator[]() [1/2]

template<typename T >
reference ityr::global_vector< T >::operator[] ( size_type  i)
inline

◆ operator[]() [2/2]

template<typename T >
const_reference ityr::global_vector< T >::operator[] ( size_type  i) const
inline

◆ options()

template<typename T >
global_vector_options ityr::global_vector< T >::options ( ) const
inlinenoexcept

◆ pop_back()

template<typename T >
void ityr::global_vector< T >::pop_back ( )
inline

◆ push_back() [1/2]

template<typename T >
void ityr::global_vector< T >::push_back ( const value_type value)
inline

◆ push_back() [2/2]

template<typename T >
void ityr::global_vector< T >::push_back ( value_type &&  value)
inline

◆ rbegin() [1/2]

template<typename T >
reverse_iterator ityr::global_vector< T >::rbegin ( ) const
inlinenoexcept

◆ rbegin() [2/2]

template<typename T >
const_reverse_iterator ityr::global_vector< T >::rbegin ( )
inlinenoexcept

◆ rend() [1/2]

template<typename T >
reverse_iterator ityr::global_vector< T >::rend ( ) const
inlinenoexcept

◆ rend() [2/2]

template<typename T >
const_reverse_iterator ityr::global_vector< T >::rend ( )
inlinenoexcept

◆ reserve()

template<typename T >
void ityr::global_vector< T >::reserve ( size_type  new_cap)
inline

◆ resize() [1/2]

template<typename T >
void ityr::global_vector< T >::resize ( size_type  count)
inline

◆ resize() [2/2]

template<typename T >
void ityr::global_vector< T >::resize ( size_type  count,
const value_type value 
)
inline

◆ size()

template<typename T >
size_type ityr::global_vector< T >::size ( ) const
inlinenoexcept

◆ swap()

template<typename T >
void ityr::global_vector< T >::swap ( this_t other)
inlinenoexcept

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