Turi Create  4.0
turi::sparse_parallel_2d_array< T > Class Template Reference

#include <core/generics/sparse_parallel_2d_array.hpp>

Public Member Functions

template<typename ApplyFunction >
GL_HOT void apply (size_t i, size_t j, ApplyFunction &&apply_f)
 
GL_HOT_INLINE_FLATTEN T & operator() (size_t i, size_t j)
 
template<typename ApplyFunction >
void apply_all (ApplyFunction &&apply_f) const
 
template<typename ApplyFunction >
void apply_all (ApplyFunction &&apply_f)
 

Detailed Description

template<typename T>
class turi::sparse_parallel_2d_array< T >

A sparse 2d array structure for holding items accessed by multiple threads. Besides metadata operations, this structure essentially provides two operations – apply and apply_all. apply takes as input a row index, a column index, and a function taking a reference to an item. The item is created if it does not exist, is locked, and then the function is called. The reference is invalid as soon as the function exits. apply_all takes a function that takes as input a row_index, a column_index, and a reference to the item. apply_all calls this function on every entry of the matrix in parallel, with the added gaurantee that each row is called by the same thread.

Definition at line 33 of file sparse_parallel_2d_array.hpp.

Member Function Documentation

◆ apply()

template<typename T >
template<typename ApplyFunction >
GL_HOT void turi::sparse_parallel_2d_array< T >::apply ( size_t  i,
size_t  j,
ApplyFunction &&  apply_f 
)
inline

Provides concurrant access to a particular element. The access must be done through the apply_f function, which should have the signature apply_f(T&). It is assumed that all changes to the element are completed when the element exits.

Definition at line 54 of file sparse_parallel_2d_array.hpp.

◆ apply_all() [1/2]

template<typename T >
template<typename ApplyFunction >
void turi::sparse_parallel_2d_array< T >::apply_all ( ApplyFunction &&  apply_f) const
inline

Calls apply_f, in parallel, for every value currently in the table. The signature of the apply function is assumed to be apply_f(size_t i, size_t j, const T& t); Note this is the const overload.

The storage and scheduling gaurantees that each unique value of i is called within the same thread. In other words, there are never two simultaneous calls to apply_f with the same value of i.

Definition at line 104 of file sparse_parallel_2d_array.hpp.

◆ apply_all() [2/2]

template<typename T >
template<typename ApplyFunction >
void turi::sparse_parallel_2d_array< T >::apply_all ( ApplyFunction &&  apply_f)
inline

Calls apply_f, in parallel, for every value currently in the table. The signature of the apply function is assumed to be apply_f(size_t i, size_t j, T& t);

The storage and scheduling gaurantees that each unique value of i is called within the same thread. In other words, there are never two simultaneous calls to apply_f with the same value of i.

mutable overload.

Definition at line 147 of file sparse_parallel_2d_array.hpp.

◆ operator()()

template<typename T >
GL_HOT_INLINE_FLATTEN T& turi::sparse_parallel_2d_array< T >::operator() ( size_t  i,
size_t  j 
)
inline

Provides non-locking access to a particular element. Cannot be used in parallel.

Definition at line 78 of file sparse_parallel_2d_array.hpp.


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