Template Class Array

Nested Relationships

Inheritance Relationships

Base Type

Class Documentation

template <typename T>
class Array : public shad::AbstractDataStructure<Array<T>>

The Array data structure.

SHAD’s Array is a fixed size distributed container.

Warning
obects of type T need to be trivially copiable.
Template Parameters
  • T: type of the entries stored in the Array.

Public Types

template<>
using ObjectID = typename AbstractDataStructure::ObjectID
template<>
using BuffersVector = impl::BuffersVector<std::tuple<size_t, T>, Array<T>>
template<>
using ShadArrayPtr = typename AbstractDataStructure<Array<T>>::SharedPtr

Public Functions

ObjectID GetGlobalID() const

Retrieve the Global Identifier.

Return
The global identifier associated with the array instance.

size_t Size() const

Return the size of the shad::Array.

Return
The size of the shad::Array.

void InsertAt(const size_t pos, const T &value)

Synchronous insert method.

Inserts an element at the specified position synchronously.

Typical usage:

auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
for (size_t i = 0; i < kArraySize; i++) {
  arrayPtr->InsertAt(i, i+1);
}

Parameters
  • pos: The target position.
  • value: The value of the element to be inserted.

void InsertAt(const size_t pos, const T *values, const size_t numValues)

Synchronous bulk insert method.

Inserts multiple elements starting at the specified position.

Typical usage:

std::vector<size_t> values(10, 1);
auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
arrayPtr->InsertAt(0, values.data(), values.size());

Parameters
  • pos: The target position.
  • values: Pointer to the values to be inserted.
  • numValues: Number of values to be inserted.

void AsyncInsertAt(rt::Handle &handle, const size_t pos, const T &value)

Asynchronous Insert method.

Asynchronously inserts an element at the specified position.

Typical usage:

shad::rt::Handle handle;
auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
for (size_t i = 0; i < kArraySize; i++) {
  arrayPtr->AsyncInsertAt(handle, i, i+1);
}
// ... more work here and then finally wait.
shad::rt::waitForCompletion(handle);
Warning
Asynchronous operations are guaranteed to have completed only after calling the rt::waitForCompletion(rt::Handle& handle) method.

Parameters
  • handle: The handle to be used to wait for completion.
  • pos: The target position.
  • value: The value to be inserted.

void AsyncInsertAt(rt::Handle &handle, const size_t pos, const T *values, const size_t numValues)

Asynchronous bulk insert method.

Asynchronously inserts multiple elements starting at the specified position.

Typical usage:

std::vector<size_t> values(10, 1);
auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);

shad::rt::Handle handle;
arrayPtr->AsyncInsertAt(handle, 0, values.data(), values.size());
// ... more work here and then finally wait.
shad::rt::waitForCompletion(handle);;

Parameters
  • handle: The handle to be used to wait for completion.
  • pos: The target position.
  • values: Pointer to the values to be inserted.
  • numValues: Number of values to be inserted.

void BufferedInsertAt(const size_t pos, const T &value)

Buffered insert method.

Inserts an element at the specified position, using aggregation buffers.

Typical usage:

auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
for (size_t i = 0; i < kArraySize; i++) {
  arrayPtr->BufferedInsertAt(i, i+1);
}
arrayPtr->WaitForBufferedInsert();
Warning
Insertions are finalized only after calling the WaitForBufferedInsert() method.

Parameters
  • pos: The target position.
  • value: The value of the element to be inserted.

void BufferedAsyncInsertAt(rt::Handle &handle, const size_t pos, const T &value)

Asynchronous buffered insert method.

Asynchronously inserts an element at the specified position, using aggregation buffers.

Typical usage:

auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);

shad::rt::Handle handle;
for (size_t i = 0; i < kArraySize; i++) {
  arrayPtr->BufferedAsyncInsertAt(handle, i, i+1);
}
// ... more work here and then finally wait.
shad::rt::waitForCompletion(handle);
arrayPtr->WaitForBufferedInsert();
Warning
asynchronous buffered insertions are finalized only after calling the rt::waitForCompletion(rt::Handle &handle) method and the WaitForBufferedInsert() method, in this order.

Parameters
  • handle: The handle to be used to wait for completion.
  • pos: The target position.
  • value: The value to be inserted.

void WaitForBufferedInsert()

Finalize method for buffered insertions.

T At(const size_t pos)

Lookup Method.

Retireve an element at a given position.

Typical usage:

auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
// ... fill the array with useful values ...

for (size_t i = 0; i < arrayPtr->Size(); ++i)
  PrintValue(arrayPtr->At(i));  // Don't do this !

Return
The value of the element at position pos.
Parameters
  • pos: The target position.

void AsyncAt(rt::Handle &handle, const size_t pos, T *result)

Asynchronous Lookup Method.

Retireve an element at a given position asynchronously.

Typical usage:

auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
// ... fill the array with useful values ...

std::vector<size_t> top(k);
shad::rt::Handle handle;
for (size_t i = 0; i < k; ++i)
  arrayPtr->AsyncAt(i, &top[i]);

shad::rt::waitForCompletion(handle);
for (auto v : top)
  PrintValue(v);
Warning
Asynchronous operations are guaranteed to have completed only after calling the rt::waitForCompletion(rt::Handle &handle) method.

Parameters
  • handle: The handle to be used to wait for completion.
  • pos: The target position.
  • result: pointer to the region where the element value is written; result must point to a valid memory allocation.

template <typename ApplyFunT, typename... Args>
void Apply(const size_t pos, ApplyFunT &&function, Args&... args)

Applies a user-defined function to an element.

Applies a user-defined function to the element at the specified position.

Typical usage:

void fn(size_t i, size_t& elem, size_t & incr) { /* do something */ }
...
auto edsPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
for (size_t i = 0; i < kArraySize; i++) {
  edsPtr->Apply(i, fn, kInitValue);
}
...

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype must be:
    void(size_t, T&, Args& args);
    
  • ...Args: Types of the function arguments.
Parameters
  • pos: The target position.
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void AsyncApply(rt::Handle &handle, const size_t pos, ApplyFunT &&function, Args&... args)

Asynchronously applies a user-defined function to an element.

Asynchronously applies a user-defined function to the element at the specified position.

Typical usage:

void fn(shad::rt::Handle&, size_t i, size_t& elem, size_t & incr) {
  /* do something */
}
...
auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
shad::rt::Handle handle;
for (size_t i = 0; i < kArraySize; i++) {
  arrayPtr->AsyncApply(handle, i, fn, kInitValue);
}
shad::rt::waitForCompletion(handle);
...
Warning
Asynchronous operations are guaranteed to have completed only after calling the rt::waitForCompletion(rt::Handle &handle) method.

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype must be:
    void(shad::rt::Handle&, size_t, T&, Args& args);
    
  • ...Args: Types of the function arguments.
Parameters
  • handle: Reference to the handle to be used to wait for completion.
  • pos: The target position.
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void ForEachInRange(const size_t first, const size_t last, ApplyFunT &&function, Args&... args)

Applies a user-defined function to every element in the specified range.

Applies a user-defined function to all the elements in the specified range of positions.

Typical usage:

static void fn(size_t i, size_t& elem, size_t & incr) {
  /* do something */
}
...
auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
arrayPtr->ForEachInRange(0, kArraySize, fn, kInitValue);
...

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype must be:
    void(size_t, T&, Args& args);
    
  • ...Args: Types of the function arguments.
Parameters
  • first: The first position of the range.
  • last: The last position of the range.
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void AsyncForEachInRange(rt::Handle &handle, const size_t first, const size_t last, ApplyFunT &&function, Args&... args)

Asynchronously applies a user-defined function to every element in the specified range.

Asynchronously applies a user-defined function to all the elements in the specified range of positions.

Typical usage:

void fn(shad::rt::Handle&, size_t i, size_t& elem, size_t& incr) {
  /* do something */
}
...
auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
shad::rt::Handle handle;
arrayPtr->AsyncForEachInRange(handle, 0, kArraySize, fn, kInitValue);
...
rt::waitForCompletion(handle);
...
Warning
Asynchronous operations are guaranteed to have completed only after calling the rt::waitForCompletion(rt::Handle &handle) method.

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype must be:
    void(shad::rt::Handle&, size_t, T&, Args& args);
    
  • ...Args: Types of the function arguments.
Parameters
  • handle: Reference to the handle to be used to wait for completion.
  • first: The first position of the range.
  • last: The last position of the range.
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void ForEach(ApplyFunT &&function, Args&... args)

Applies a user-defined function to every element.

Applies a user-defined function to all the elements.

Typical usage:

void fn(size_t i, size_t& elem, size_t& incr) {
  /* do something */
}
...
auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
arrayPtr->ForEach(fn, someValue);

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype must be:
    void(size_t pos, T&, Args& args);
    
  • ...Args: Types of the function arguments.
Parameters
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void AsyncForEach(rt::Handle &handle, ApplyFunT &&function, Args&... args)

Asynchronously applies a user-defined function to every element.

Asynchronously applies a user-defined function to all the elements.

Typical usage:

void fn(shad::rt::Handle&, size_t i, size_t& elem, size_t& incr) {
  /* do something */
}
...
auto arrayPtr = shad::Array<size_t>::Create(kArraySize, kInitValue);
rt::Handle handle;
arrayPtr->AsyncForEach(handle, fn, someValue);
...
shad::rt::waitForCompletion(handle);
...
Warning
Asynchronous operations are guaranteed to have completed only after calling the rt::waitForCompletion(rt::Handle &handle) method.

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype must be:
    void(shad::rt::Handle&, size_t pos, T&, Args& args);
    
  • ...Args: Types of the function arguments.
Parameters
  • handle: The handle to be used to wait for completion.
  • function: The function to apply.
  • args: The function arguments.

void BufferEntryInsert(const std::tuple<size_t, T> entry)

Public Static Attributes

constexpr size_t kMaxChunkSize

=

constants::max(constants::kBufferNumBytes / sizeof(T), 1lu)


Protected Functions

Array(ObjectID oid, size_t size, const T &initValue)