DASH  0.3.0
dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT > Class Template Reference

A distributed array. More...

#include <Array.h>

Public Types

typedef ElementType value_type
 Public types as required by iterator concept. More...
 
typedef IndexType index_type
 
typedef std::make_unsigned< IndexType >::type size_type
 
typedef std::make_unsigned< IndexType >::type difference_type
 
typedef dash::GlobStaticMem< LocalMemSpaceT > memory_type
 
typedef dash::GlobalAllocator< value_type, memory_typeallocator_type
 
typedef GlobIter< value_type, PatternType, memory_typeiterator
 
typedef GlobIter< const value_type, PatternType, memory_typeconst_iterator
 
typedef std::reverse_iterator< iteratorreverse_iterator
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 
typedef GlobRef< value_typereference
 
typedef GlobRef< value_type >::const_type const_reference
 
typedef iterator::pointer pointer
 
typedef pointer::const_type const_pointer
 
typedef pointer::local_type local_pointer
 
typedef pointer::const_local_type const_local_pointer
 
typedef DistributionSpec< 1 > distribution_spec
 
typedef PatternType pattern_type
 Public types as required by dash container concept. More...
 
typedef LocalArrayRef< value_type, IndexType, PatternType, LocalMemSpaceT > local_type
 
typedef ArrayRef< ElementType, IndexType, PatternType, LocalMemSpaceT > view_type
 
typedef AsyncArrayRef< value_type, IndexType, PatternType, LocalMemSpaceT > async_type
 
typedef std::integral_constant< dim_t, 1 > rank
 

Public Member Functions

constexpr Array (Team &team=dash::Team::Null())
 Default constructor, for delayed allocation. More...
 
 Array (size_type nelem, const distribution_spec &distribution, Team &team=dash::Team::All())
 Constructor, specifies the array's global capacity and distribution. More...
 
 Array (size_type nelem, Team &team=dash::Team::All())
 Delegating constructor, specifies the array's global capacity. More...
 
 Array (size_type nelem, std::initializer_list< value_type > local_elements, const distribution_spec &distribution, Team &team=dash::Team::All())
 Constructor, specifies the array's global capacity, values of local elements and distribution. More...
 
 Array (size_type nelem, std::initializer_list< value_type > local_elements, Team &team=dash::Team::All())
 Delegating constructor, specifies the array's global capacity and values of local elements. More...
 
 Array (const PatternType &pattern)
 Constructor, specifies distribution pattern explicitly. More...
 
 Array (const self_t &other)=delete
 Copy constructor is deleted to prevent unintentional copies of - usually huge - distributed arrays. More...
 
 Array (self_t &&other) noexcept(std::is_nothrow_move_constructible< memory_type >::value)
 Move construction is supported for the container with the following limitations: More...
 
self_toperator= (const self_t &rhs)=delete
 Assignment operator is deleted to prevent unintentional copies of. More...
 
self_toperator= (self_t &&other)
 Move assignment is supported for the container with the following limitations: More...
 
 ~Array ()
 Destructor, deallocates array elements. More...
 
constexpr const view_type block (index_type block_gindex) const
 View at block at given global block offset. More...
 
constexpr const memory_typeglobmem () const noexcept
 The instance of GlobStaticMem used by this iterator to resolve addresses in global memory. More...
 
constexpr const_pointer data () const noexcept
 Global const pointer to the beginning of the array. More...
 
iterator begin () noexcept
 Global pointer to the beginning of the array. More...
 
constexpr const_iterator begin () const noexcept
 Global pointer to the beginning of the array. More...
 
iterator end () noexcept
 Global pointer to the end of the array. More...
 
constexpr const_iterator end () const noexcept
 Global pointer to the end of the array. More...
 
constexpr const ElementType * lbegin () const noexcept
 Native pointer to the first local element in the array. More...
 
ElementType * lbegin () noexcept
 Native pointer to the first local element in the array. More...
 
constexpr const ElementType * lend () const noexcept
 Native pointer to the end of the array. More...
 
ElementType * lend () noexcept
 Native pointer to the end of the array. More...
 
reference operator[] (size_type global_index)
 Subscript assignment operator, not range-checked. More...
 
constexpr const_reference operator[] (size_type global_index) const
 Subscript operator, not range-checked. More...
 
reference at (size_type global_pos)
 Random access assignment operator, range-checked. More...
 
const_reference at (size_type global_pos) const
 Random access operator, range-checked. More...
 
constexpr size_type size () const noexcept
 The size of the array. More...
 
constexpr size_type capacity () const noexcept
 The number of elements that can be held in currently allocated storage of the array. More...
 
constexpr Teamteam () const noexcept
 The team containing all units accessing this array. More...
 
constexpr size_type lsize () const noexcept
 The number of elements in the local part of the array. More...
 
constexpr size_type lcapacity () const noexcept
 The capacity of the local part of the array. More...
 
constexpr bool empty () const noexcept
 Checks whether the array is empty. More...
 
constexpr view_type local_in (dash::util::Locality::Scope scope) const
 
constexpr bool is_local (index_type global_index) const
 Checks whether the given global index is local to the calling unit. More...
 
void barrier () const
 Establish a barrier for all units operating on the array, publishing all changes to all units. More...
 
void flush () const
 Complete all outstanding non-blocking operations to all units on the array's underlying global memory. More...
 
void flush (dash::team_unit_t target) const
 Complete all outstanding non-blocking operations to the specified unit on the array's underlying global memory. More...
 
void flush_local () const
 Locally complete all outstanding non-blocking operations to all units on the array's underlying global memory. More...
 
void flush_local (dash::team_unit_t target) const
 Locally complete all outstanding non-blocking operations to the specified unit on the array's underlying global memory. More...
 
constexpr const PatternType & pattern () const noexcept
 The pattern used to distribute array elements to units. More...
 
bool allocate (size_type nelem, dash::DistributionSpec< 1 > distribution, dash::Team &team=dash::Team::All())
 Delayed allocation of global memory using a one-dimensional distribution spec. More...
 
bool allocate (size_type nelem, Team &team=dash::Team::All())
 Delayed allocation of global memory using the default blocked distribution spec. More...
 
bool allocate (size_type nelem, std::initializer_list< value_type > local_elements, dash::DistributionSpec< 1 > distribution, dash::Team &team=dash::Team::All())
 Delayed allocation of global memory using a one-dimensional distribution spec and initializing values. More...
 
void deallocate ()
 
bool allocate (const PatternType &pattern)
 Delayed allocation of global memory using the specified pattern. More...
 

Static Public Member Functions

static constexpr dim_t ndim ()
 

Public Attributes

local_type local
 Local proxy object, allows use in range-based for loops. More...
 
async_type async
 Proxy object, provides non-blocking operations on array. More...
 

Detailed Description

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
class dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >

A distributed array.

Implemented concept:
Array Concept
Todo:
Add template parameter: class GlobMemType = dash::GlobStaticMem<ElementType>
Note
: Template parameter IndexType could be deduced from pattern type PatternT::index_type
Examples:
ex.02.array-csr/main.cpp, ex.02.array-ctors/main.cpp, ex.02.array-delayed/main.cpp, ex.02.array-local/main.cpp, ex.02.array/main.cpp, ex.03.globref/main.cpp, ex.04.memalloc/main.cpp, ex.05.min_element/main.cpp, ex.06.std-algo/main.cpp, ex.08.io-hdf5/main.cpp, ex.09.view-1dim/main.cpp, ex.10.radixsort/main.cpp, ex.11.halo-stencil/main.cpp, and ex.11.simple-stencil/main.cpp.

Definition at line 89 of file Array.h.

Member Typedef Documentation

◆ pattern_type

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
typedef PatternType dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::pattern_type

Public types as required by dash container concept.

The type of the pattern used to distribute array elements to units

Definition at line 701 of file Array.h.

◆ value_type

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
typedef ElementType dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::value_type

Public types as required by iterator concept.

Definition at line 658 of file Array.h.

Constructor & Destructor Documentation

◆ Array() [1/8]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::Array ( Team team = dash::Team::Null())
inlineexplicit

Default constructor, for delayed allocation.

Sets the associated team to DART_TEAM_NULL for global array instances that are declared before dash::Init().

Definition at line 770 of file Array.h.

771  : local(this)
772  , async(this)
773  , m_team(&team)
774  , m_pattern(SizeSpec_t(0), distribution_spec(dash::BLOCKED), team)
775  {
776  DASH_LOG_TRACE("Array() >", "finished default constructor");
777  }
async_type async
Proxy object, provides non-blocking operations on array.
Definition: Array.h:734
constexpr Team & team() const noexcept
The team containing all units accessing this array.
Definition: Array.h:1195
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732

◆ Array() [2/8]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::Array ( size_type  nelem,
const distribution_spec distribution,
Team team = dash::Team::All() 
)
inline

Constructor, specifies the array's global capacity and distribution.

Definition at line 782 of file Array.h.

786  : local(this)
787  , async(this)
788  , m_team(&team)
789  , m_pattern(SizeSpec_t(nelem), distribution, team)
790  {
791  DASH_LOG_TRACE("Array(nglobal,dist,team)()", "size:", nelem);
792  allocate(m_pattern);
793  DASH_LOG_TRACE("Array(nglobal,dist,team) >");
794  }
async_type async
Proxy object, provides non-blocking operations on array.
Definition: Array.h:734
constexpr Team & team() const noexcept
The team containing all units accessing this array.
Definition: Array.h:1195
bool allocate(size_type nelem, dash::DistributionSpec< 1 > distribution, dash::Team &team=dash::Team::All())
Delayed allocation of global memory using a one-dimensional distribution spec.
Definition: Array.h:1319
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732

◆ Array() [3/8]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::Array ( size_type  nelem,
Team team = dash::Team::All() 
)
inlineexplicit

Delegating constructor, specifies the array's global capacity.

Definition at line 799 of file Array.h.

800  : Array(nelem, dash::BLOCKED, team)
801  {
802  DASH_LOG_TRACE(
803  "Array(nglobal,team) >", "finished delegating constructor");
804  }
constexpr Team & team() const noexcept
The team containing all units accessing this array.
Definition: Array.h:1195
constexpr Array(Team &team=dash::Team::Null())
Default constructor, for delayed allocation.
Definition: Array.h:770

◆ Array() [4/8]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::Array ( size_type  nelem,
std::initializer_list< value_type local_elements,
const distribution_spec distribution,
Team team = dash::Team::All() 
)
inline

Constructor, specifies the array's global capacity, values of local elements and distribution.

Definition at line 810 of file Array.h.

815  : local(this)
816  , async(this)
817  , m_team(&team)
818  , m_pattern(SizeSpec_t(nelem), distribution, team)
819  , m_globmem(*m_team)
820  , m_allocator(&m_globmem)
821  , m_myid(team.myid())
822  {
823  DASH_LOG_TRACE("Array(nglobal,lvals,dist,team)()",
824  "size:", nelem,
825  "nlocal:", local_elements.size());
826  allocate(local_elements);
827  DASH_LOG_TRACE("Array(nglobal,lvals,dist,team) >");
828  }
async_type async
Proxy object, provides non-blocking operations on array.
Definition: Array.h:734
constexpr Team & team() const noexcept
The team containing all units accessing this array.
Definition: Array.h:1195
bool allocate(size_type nelem, dash::DistributionSpec< 1 > distribution, dash::Team &team=dash::Team::All())
Delayed allocation of global memory using a one-dimensional distribution spec.
Definition: Array.h:1319
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732

◆ Array() [5/8]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::Array ( size_type  nelem,
std::initializer_list< value_type local_elements,
Team team = dash::Team::All() 
)
inline

Delegating constructor, specifies the array's global capacity and values of local elements.

Definition at line 834 of file Array.h.

838  : Array(nelem, local_elements, dash::BLOCKED, team)
839  {
840  DASH_LOG_TRACE("Array(nglobal,lvals,team) >",
841  "finished delegating constructor");
842  }
constexpr Team & team() const noexcept
The team containing all units accessing this array.
Definition: Array.h:1195
constexpr Array(Team &team=dash::Team::Null())
Default constructor, for delayed allocation.
Definition: Array.h:770

◆ Array() [6/8]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::Array ( const PatternType &  pattern)
inlineexplicit

Constructor, specifies distribution pattern explicitly.

Definition at line 848 of file Array.h.

850  : local(this),
851  async(this),
852  m_team(&pattern.team()),
853  m_pattern(pattern),
854  m_myid(m_team->myid())
855  {
856  DASH_LOG_TRACE("Array()", "pattern instance constructor");
857  allocate(m_pattern);
858  }
async_type async
Proxy object, provides non-blocking operations on array.
Definition: Array.h:734
constexpr const PatternType & pattern() const noexcept
The pattern used to distribute array elements to units.
Definition: Array.h:1310
bool allocate(size_type nelem, dash::DistributionSpec< 1 > distribution, dash::Team &team=dash::Team::All())
Delayed allocation of global memory using a one-dimensional distribution spec.
Definition: Array.h:1319
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732

◆ Array() [7/8]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::Array ( const self_t other)
delete

Copy constructor is deleted to prevent unintentional copies of - usually huge - distributed arrays.

To create a copy of a dash::Array instance, instantiate the copy instance explicitly and use dash::copy to clone elements.

Example:

dash::fill(a1.begin(), a1.end(), 123);
// create copy of array a1:
dash::Array<int> a2(a1.size());
dash::copy(a1.begin(), a1.end(), a2.begin());

◆ Array() [8/8]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::Array ( self_t &&  other)
inlinenoexcept

Move construction is supported for the container with the following limitations:

The pattern has to be movable or copyable The underlying memory does not have to be movable (it might).

Definition at line 887 of file Array.h.

889  : local(this)
890  , async(this)
891  , m_team(other.m_team)
892  , m_pattern(std::move(other.m_pattern))
893  , m_globmem(std::move(other.m_globmem))
894  , m_allocator(&m_globmem)
895  , m_data(
896  other.m_data.release(),
897  typename unique_gptr_t::deleter_type{m_allocator,
898  m_pattern.local_size()})
899  , m_begin(other.m_begin)
900  , m_end(other.m_end)
901  , m_size(other.m_size)
902  , m_lsize(other.m_lsize)
903  , m_lcapacity(other.m_lcapacity)
904  , m_lbegin(other.m_lbegin)
905  , m_lend(other.m_lend)
906  , m_myid(other.m_myid)
907  {
908  other.m_begin = iterator{};
909  other.m_end = iterator{};
910  other.m_lbegin = nullptr;
911  other.m_lend = nullptr;
912  other.m_lsize = 0;
913  other.m_size = 0;
914 
915  other.m_team->unregister_deallocator(&other, std::bind(&Array::deallocate, &other));
916 
917  // Register deallocator of this array instance at the team
918  // instance that has been used to initialized it:
919  m_team->register_deallocator(this, std::bind(&Array::deallocate, this));
920  }
async_type async
Proxy object, provides non-blocking operations on array.
Definition: Array.h:734
void register_deallocator(void *object, Deallocator::dealloc_function dealloc)
Register a deallocator function for a team-allocated object.
Definition: Team.h:285
local_type local
Local proxy object, allows use in range-based for loops.
Definition: Array.h:732

◆ ~Array()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::~Array ( )
inline

Destructor, deallocates array elements.

Definition at line 1005 of file Array.h.

1006  {
1007  DASH_LOG_TRACE_VAR("Array.~Array()", this);
1008  deallocate();
1009  DASH_LOG_TRACE_VAR("Array.~Array >", this);
1010  }

Member Function Documentation

◆ allocate() [1/4]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
bool dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::allocate ( size_type  nelem,
dash::DistributionSpec< 1 >  distribution,
dash::Team team = dash::Team::All() 
)
inline

Delayed allocation of global memory using a one-dimensional distribution spec.

Definition at line 1319 of file Array.h.

Referenced by dash::Coevent::initialize(), and dash::List< ElementType, LocalMemorySpace >::List().

1323  {
1324  DASH_LOG_TRACE_VAR("Array.allocate(nlocal,ds,team)", nelem);
1325  DASH_LOG_TRACE_VAR("Array.allocate", m_team->dart_id());
1326  DASH_LOG_TRACE_VAR("Array.allocate", team.dart_id());
1327  // Check requested capacity:
1328  if (nelem == 0) {
1329  DASH_LOG_WARN("Array.allocate", "allocating dash::Array with size 0");
1330  }
1331  if (m_team == nullptr || *m_team == dash::Team::Null()) {
1332  DASH_LOG_TRACE("Array.allocate",
1333  "initializing with specified team -",
1334  "team size:", team.size());
1335  m_team = &team;
1336  m_pattern = PatternType(nelem, distribution, team);
1337  DASH_LOG_TRACE_VAR("Array.allocate", team.dart_id());
1338  DASH_LOG_TRACE_VAR("Array.allocate", m_pattern.team().dart_id());
1339  } else {
1340  DASH_LOG_TRACE("Array.allocate",
1341  "initializing pattern with initial team");
1342  m_pattern = PatternType(nelem, distribution, *m_team);
1343  }
1344 
1345  bool ret = allocate(m_pattern);
1346  DASH_LOG_TRACE("Array.allocate(nlocal,ds,team) >");
1347  return ret;
1348  }
size_t size() const
The number of units in this team.
Definition: Team.h:498
constexpr Team & team() const noexcept
The team containing all units accessing this array.
Definition: Array.h:1195
static Team & Null()
The invariant Team instance representing an undefined team.
Definition: Team.h:229
dart_team_t dart_id() const
Index of this team relative to global team dash::Team::All().
Definition: Team.h:522
bool allocate(size_type nelem, dash::DistributionSpec< 1 > distribution, dash::Team &team=dash::Team::All())
Delayed allocation of global memory using a one-dimensional distribution spec.
Definition: Array.h:1319

◆ allocate() [2/4]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
bool dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::allocate ( size_type  nelem,
Team team = dash::Team::All() 
)
inline

Delayed allocation of global memory using the default blocked distribution spec.

Definition at line 1355 of file Array.h.

1358  {
1359  return allocate(nelem, dash::BLOCKED, team);
1360  }
constexpr Team & team() const noexcept
The team containing all units accessing this array.
Definition: Array.h:1195
bool allocate(size_type nelem, dash::DistributionSpec< 1 > distribution, dash::Team &team=dash::Team::All())
Delayed allocation of global memory using a one-dimensional distribution spec.
Definition: Array.h:1319

◆ allocate() [3/4]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
bool dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::allocate ( size_type  nelem,
std::initializer_list< value_type local_elements,
dash::DistributionSpec< 1 >  distribution,
dash::Team team = dash::Team::All() 
)
inline

Delayed allocation of global memory using a one-dimensional distribution spec and initializing values.

Definition at line 1367 of file Array.h.

1372  {
1373  DASH_LOG_TRACE_VAR("Array.allocate(lvals,ds,team)",
1374  local_elements.size());
1375  DASH_LOG_TRACE_VAR("Array.allocate", m_team->dart_id());
1376  DASH_LOG_TRACE_VAR("Array.allocate", team.dart_id());
1377  // Check requested capacity:
1378  if (nelem == 0) {
1379  DASH_THROW(
1381  "Tried to allocate dash::Array with size 0");
1382  }
1383  if (m_team == nullptr || *m_team == dash::Team::Null()) {
1384  DASH_LOG_TRACE("Array.allocate",
1385  "initializing pattern with Team::All()");
1386  m_team = &team;
1387  m_pattern = PatternType(nelem, distribution, team);
1388  DASH_LOG_TRACE_VAR("Array.allocate", team.dart_id());
1389  DASH_LOG_TRACE_VAR("Array.allocate", m_pattern.team().dart_id());
1390  } else {
1391  DASH_LOG_TRACE("Array.allocate",
1392  "initializing pattern with initial team");
1393  m_pattern = PatternType(nelem, distribution, *m_team);
1394  }
1395  bool ret = allocate(local_elements);
1396  DASH_LOG_TRACE("Array.allocate(lvals,ds,team) >");
1397  return ret;
1398  }
constexpr Team & team() const noexcept
The team containing all units accessing this array.
Definition: Array.h:1195
static Team & Null()
The invariant Team instance representing an undefined team.
Definition: Team.h:229
dart_team_t dart_id() const
Index of this team relative to global team dash::Team::All().
Definition: Team.h:522
bool allocate(size_type nelem, dash::DistributionSpec< 1 > distribution, dash::Team &team=dash::Team::All())
Delayed allocation of global memory using a one-dimensional distribution spec.
Definition: Array.h:1319

◆ allocate() [4/4]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
bool dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::allocate ( const PatternType &  pattern)
inline

Delayed allocation of global memory using the specified pattern.

Definition at line 1522 of file Array.h.

1523  {
1524  DASH_LOG_TRACE("< Array.allocate", "finished");
1525  if (&m_pattern != &pattern) {
1526  DASH_LOG_TRACE("Array.allocate()", "using specified pattern");
1527  m_pattern = pattern;
1528  }
1529 
1530  do_allocate();
1531 
1532  // Local iterators:
1533  auto soon_to_be_lbegin = m_data.get();
1534  soon_to_be_lbegin.set_unit(m_myid);
1535  m_lbegin = soon_to_be_lbegin.local();
1536  // More efficient than using m_globmem->lend as this a second mapping
1537  // of the local memory segment:
1538  m_lend = std::next(m_lbegin, m_lsize);
1539 
1540  // We do no construct the elements to prevent NUMA effects
1541  // construct_at_end(m_lsize);
1542 
1543  // Register deallocator of this array instance at the team
1544  // instance that has been used to initialized it:
1545  m_team->register_deallocator(this, std::bind(&Array::deallocate, this));
1546  // Assure all units are synchronized after allocation, otherwise
1547  // other units might start working on the array before allocation
1548  // completed at all units:
1549  DASH_LOG_TRACE("Array.allocate", "waiting for allocation of all units");
1550  m_team->barrier();
1551  DASH_LOG_TRACE("Array.allocate >", "finished");
1552  return true;
1553  }
constexpr const PatternType & pattern() const noexcept
The pattern used to distribute array elements to units.
Definition: Array.h:1310
void register_deallocator(void *object, Deallocator::dealloc_function dealloc)
Register a deallocator function for a team-allocated object.
Definition: Team.h:285

◆ at() [1/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
reference dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::at ( size_type  global_pos)
inline

Random access assignment operator, range-checked.

See also
operator[]
Returns
A global reference to the element in the array at the given index.
Parameters
global_posThe position of the element to return
Examples:
ex.11.halo-stencil/main.cpp, and ex.11.simple-stencil/main.cpp.

Definition at line 1132 of file Array.h.

Referenced by dash::Coevent::wait().

1135  {
1136  if (global_pos >= size()) {
1137  DASH_THROW(
1139  "Position " << global_pos
1140  << " is out of range " << size()
1141  << " in Array.at()" );
1142  }
1143  return m_begin[global_pos];
1144  }
constexpr size_type size() const noexcept
The size of the array.
Definition: Array.h:1173

◆ at() [2/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
const_reference dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::at ( size_type  global_pos) const
inline

Random access operator, range-checked.

See also
operator[]
Returns
A global reference to the element in the array at the given index.
Parameters
global_posThe position of the element to return

Definition at line 1154 of file Array.h.

1157  {
1158  if (global_pos >= size()) {
1159  DASH_THROW(
1161  "Position " << global_pos
1162  << " is out of range " << size()
1163  << " in Array.at()" );
1164  }
1165  return m_begin[global_pos];
1166  }
constexpr size_type size() const noexcept
The size of the array.
Definition: Array.h:1173

◆ barrier()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
void dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::barrier ( ) const
inline

Establish a barrier for all units operating on the array, publishing all changes to all units.

Examples:
ex.09.view-1dim/main.cpp.

Definition at line 1254 of file Array.h.

Referenced by dash::Coevent::initialize(), and dash::SharedCounter< ValueType >::SharedCounter().

1255  {
1256  DASH_LOG_TRACE_VAR("Array.barrier()", m_team);
1257  flush();
1258  if (m_team && *m_team != dash::Team::Null()) {
1259  m_team->barrier();
1260  }
1261  DASH_LOG_TRACE("Array.barrier >", "passed barrier");
1262  }
void flush() const
Complete all outstanding non-blocking operations to all units on the array&#39;s underlying global memory...
Definition: Array.h:1268
static Team & Null()
The invariant Team instance representing an undefined team.
Definition: Team.h:229

◆ begin() [1/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
iterator dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::begin ( )
inlinenoexcept

◆ begin() [2/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr const_iterator dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::begin ( ) const
inlinenoexcept

Global pointer to the beginning of the array.

Definition at line 1048 of file Array.h.

1049  {
1050  return const_iterator(
1051  const_cast<memory_type *>(&m_globmem), m_pattern, m_begin.pos());
1052  }
DASH_CONSTEXPR index_type pos() const DASH_NOEXCEPT
Position of the iterator in global index space.
Definition: GlobIter.h:336

◆ block()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr const view_type dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::block ( index_type  block_gindex) const
inline

View at block at given global block offset.

Definition at line 1015 of file Array.h.

1016  {
1017  return View(this, ViewSpec<1>(pattern().block(block_gindex)));
1018  }
constexpr const PatternType & pattern() const noexcept
The pattern used to distribute array elements to units.
Definition: Array.h:1310
constexpr const view_type block(index_type block_gindex) const
View at block at given global block offset.
Definition: Array.h:1015

◆ capacity()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr size_type dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::capacity ( ) const
inlinenoexcept

The number of elements that can be held in currently allocated storage of the array.

Returns
The number of elements in the array.

Definition at line 1184 of file Array.h.

1185  {
1186  return m_size;
1187  }

◆ data()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr const_pointer dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::data ( ) const
inlinenoexcept

Global const pointer to the beginning of the array.

Definition at line 1032 of file Array.h.

1033  {
1034  return const_pointer(m_data.get());
1035  }

◆ empty()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr bool dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::empty ( ) const
inlinenoexcept

Checks whether the array is empty.

Returns
True if size() is 0, otherwise false

Definition at line 1227 of file Array.h.

1228  {
1229  return size() == 0;
1230  }
constexpr size_type size() const noexcept
The size of the array.
Definition: Array.h:1173

◆ end() [1/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
iterator dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::end ( )
inlinenoexcept

Global pointer to the end of the array.

Examples:
ex.08.io-hdf5/main.cpp, ex.11.halo-stencil/main.cpp, and ex.11.simple-stencil/main.cpp.

Definition at line 1057 of file Array.h.

Referenced by dash::Coevent::Coevent(), and dash::Coevent::initialize().

1057  {
1058  return m_end;
1059  }

◆ end() [2/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr const_iterator dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::end ( ) const
inlinenoexcept

Global pointer to the end of the array.

Definition at line 1064 of file Array.h.

1065  {
1066  return const_iterator(
1067  const_cast<memory_type *>(&m_globmem), m_pattern, m_end.pos());
1068  }
DASH_CONSTEXPR index_type pos() const DASH_NOEXCEPT
Position of the iterator in global index space.
Definition: GlobIter.h:336

◆ flush() [1/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
void dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::flush ( ) const
inline

Complete all outstanding non-blocking operations to all units on the array's underlying global memory.

Definition at line 1268 of file Array.h.

Referenced by dash::LocalArrayRef< value_type, dash::default_index_t, BlockPattern< 1, ROW_MAJOR, dash::default_index_t >, HostSpace >::pattern().

1268  {
1269  //if (m_globmem && m_begin != m_end) {
1270  if (m_data) {
1271  //If we have some allocated memory -> flush it
1272  m_globmem.flush(m_data.get());
1273  }
1274  }
constexpr void flush(void_pointer ptr, dash::team_unit_t unit=dash::team_unit_t{}) const
Complete all outstanding non-blocking operations to either all units or a specified unit...

◆ flush() [2/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
void dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::flush ( dash::team_unit_t  target) const
inline

Complete all outstanding non-blocking operations to the specified unit on the array's underlying global memory.

Definition at line 1280 of file Array.h.

1280  {
1281  if (m_data) {
1282  m_globmem.flush(m_data.get(), target);
1283  }
1284  }
constexpr void flush(void_pointer ptr, dash::team_unit_t unit=dash::team_unit_t{}) const
Complete all outstanding non-blocking operations to either all units or a specified unit...

◆ flush_local() [1/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
void dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::flush_local ( ) const
inline

Locally complete all outstanding non-blocking operations to all units on the array's underlying global memory.

Definition at line 1290 of file Array.h.

Referenced by dash::LocalArrayRef< value_type, dash::default_index_t, BlockPattern< 1, ROW_MAJOR, dash::default_index_t >, HostSpace >::pattern().

1290  {
1291  if (m_data) {
1292  m_globmem.flush_local(m_data.get());
1293  }
1294  }
DASH_CONSTEXPR void flush_local(void_pointer ptr, dash::team_unit_t unit=dash::team_unit_t{}) const
Locally complete all outstanding non-blocking operations to all units.

◆ flush_local() [2/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
void dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::flush_local ( dash::team_unit_t  target) const
inline

Locally complete all outstanding non-blocking operations to the specified unit on the array's underlying global memory.

Definition at line 1301 of file Array.h.

1301  {
1302  if (m_data) {
1303  m_globmem.flush_local(m_data.get(), target);
1304  }
1305  }
DASH_CONSTEXPR void flush_local(void_pointer ptr, dash::team_unit_t unit=dash::team_unit_t{}) const
Locally complete all outstanding non-blocking operations to all units.

◆ globmem()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr const memory_type& dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::globmem ( ) const
inlinenoexcept

The instance of GlobStaticMem used by this iterator to resolve addresses in global memory.

Definition at line 1024 of file Array.h.

1025  {
1026  return m_globmem;
1027  }

◆ is_local()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr bool dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::is_local ( index_type  global_index) const
inline

Checks whether the given global index is local to the calling unit.

Returns
True if the array element referenced by the index is held in the calling unit's local memory
Parameters
global_indexA global array index

Definition at line 1243 of file Array.h.

1246  {
1247  return m_pattern.is_local(global_index, m_myid);
1248  }

◆ lbegin() [1/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr const ElementType* dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::lbegin ( ) const
inlinenoexcept

Native pointer to the first local element in the array.

Examples:
ex.11.simple-stencil/main.cpp.

Definition at line 1073 of file Array.h.

1073  {
1074  return m_lbegin;
1075  }

◆ lbegin() [2/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
ElementType* dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::lbegin ( )
inlinenoexcept

Native pointer to the first local element in the array.

Definition at line 1080 of file Array.h.

1080  {
1081  return m_lbegin;
1082  }

◆ lcapacity()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr size_type dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::lcapacity ( ) const
inlinenoexcept

The capacity of the local part of the array.

Returns
The number of allocated elements in the array that are local to the calling unit.

Definition at line 1217 of file Array.h.

1218  {
1219  return m_lcapacity;
1220  }

◆ lend() [1/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr const ElementType* dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::lend ( ) const
inlinenoexcept

Native pointer to the end of the array.

Definition at line 1087 of file Array.h.

1087  {
1088  return m_lend;
1089  }

◆ lend() [2/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
ElementType* dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::lend ( )
inlinenoexcept

Native pointer to the end of the array.

Definition at line 1094 of file Array.h.

1094  {
1095  return m_lend;
1096  }

◆ lsize()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr size_type dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::lsize ( ) const
inlinenoexcept

The number of elements in the local part of the array.

Returns
The number of elements in the array that are local to the calling unit.

Definition at line 1206 of file Array.h.

1207  {
1208  return m_lsize;
1209  }

◆ operator=() [1/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
self_t& dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::operator= ( const self_t rhs)
delete

Assignment operator is deleted to prevent unintentional copies of.

  • usually huge - distributed arrays.

To create a copy of a dash::Array instance, instantiate the copy instance explicitly and use dash::copy to clone elements.

Example:

dash::fill(a1.begin(), a1.end(), 123);
// create copy of array a1:
dash::Array<int> a2(a1.size());
dash::copy(a1.begin(), a1.end(), a2.begin());

◆ operator=() [2/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
self_t& dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::operator= ( self_t &&  other)
inline

Move assignment is supported for the container with the following limitations:

The pattern has to be movable or copyable The underlying memory does not have to be movable (it might).

Definition at line 949 of file Array.h.

949  {
950  if (this == &other) {
951  return *this;
952  }
953 
954  m_pattern = std::move(other.m_pattern);
955 
956  DASH_ASSERT_EQ(
957  m_allocator.resource(),
958  &m_globmem,
959  "invalid state in move assignment");
960 
961  // a) reset own data
962  if (m_data) {
963  destruct_at_end(m_lbegin);
964  }
965  m_data.reset();
966  // b) swap memory resources
967  m_globmem = std::move(other.m_globmem);
968  // c) move the unique_gptr from other into this
969  unique_gptr_t __tmp{other.m_data.release(),
970  typename unique_gptr_t::deleter_type{
971  m_allocator, m_pattern.local_size()}};
972  m_data = std::move(__tmp);
973 
974 
975  //TODO rko: we have to provide a proper dash::swap for iterators;
976  this->m_begin = iterator{&m_globmem, m_pattern, other.m_begin.pos()};
977  this->m_end = iterator{&m_globmem, m_pattern, other.m_end.pos()};
978 
979  this->m_lbegin = other.m_lbegin;
980  this->m_lcapacity = other.m_lcapacity;
981  this->m_lend = other.m_lend;
982  this->m_lsize = other.m_lsize;
983  this->m_myid = other.m_myid;
984  this->m_size = other.m_size;
985  this->m_team = other.m_team;
986 
987  other.m_begin = iterator{};
988  other.m_end = iterator{};
989 
990  other.m_lbegin = nullptr;
991  other.m_lend = nullptr;
992  other.m_lsize = 0;
993  other.m_size = 0;
994 
995  other.m_team->unregister_deallocator(&other, std::bind(&Array::deallocate, &other));
996 
997  m_team->register_deallocator(this, std::bind(&Array::deallocate, this));
998 
999  return *this;
1000  }
void register_deallocator(void *object, Deallocator::dealloc_function dealloc)
Register a deallocator function for a team-allocated object.
Definition: Team.h:285

◆ operator[]() [1/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
reference dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::operator[] ( size_type  global_index)
inline

Subscript assignment operator, not range-checked.

Returns
A global reference to the element in the array at the given index.
Parameters
global_indexThe position of the element to return

Definition at line 1104 of file Array.h.

1107  {
1108  return m_begin[global_index];
1109  }

◆ operator[]() [2/2]

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr const_reference dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::operator[] ( size_type  global_index) const
inline

Subscript operator, not range-checked.

Returns
A global reference to the element in the array at the given index.
Parameters
global_indexThe position of the element to return

Definition at line 1117 of file Array.h.

1120  {
1121  return m_begin[global_index];
1122  }

◆ pattern()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr const PatternType& dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::pattern ( ) const
inlinenoexcept

The pattern used to distribute array elements to units.

Examples:
ex.08.io-hdf5/main.cpp, ex.09.view-1dim/main.cpp, and ex.11.simple-stencil/main.cpp.

Definition at line 1310 of file Array.h.

Referenced by dash::LocalArrayRef< value_type, dash::default_index_t, BlockPattern< 1, ROW_MAJOR, dash::default_index_t >, HostSpace >::pattern().

1311  {
1312  return m_pattern;
1313  }

◆ size()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr size_type dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::size ( ) const
inlinenoexcept

The size of the array.

Returns
The number of elements in the array.
Examples:
ex.11.halo-stencil/main.cpp.

Definition at line 1173 of file Array.h.

Referenced by dash::LocalArrayRef< value_type, dash::default_index_t, BlockPattern< 1, ROW_MAJOR, dash::default_index_t >, HostSpace >::pattern().

1174  {
1175  return m_size;
1176  }

◆ team()

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
constexpr Team& dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::team ( ) const
inlinenoexcept

The team containing all units accessing this array.

Returns
The instance of Team that this array has been instantiated with

Definition at line 1195 of file Array.h.

1196  {
1197  return *m_team;
1198  }

Member Data Documentation

◆ async

template<typename ElementType, typename IndexType = dash::default_index_t, class PatternType = BlockPattern<1, ROW_MAJOR, IndexType>, typename LocalMemSpaceT = HostSpace>
async_type dash::Array< ElementType, IndexType, PatternType, LocalMemSpaceT >::async

Proxy object, provides non-blocking operations on array.

Definition at line 734 of file Array.h.

◆ local


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