32 template<
typename POLICY,
typename T >
34 void atomicAdd( POLICY, T *
const acc, T
const & val )
35 { RAJA::atomicAdd< POLICY >( acc, val ); }
46 template<
typename T >
48 void atomicAdd( RAJA::seq_atomic, T * acc, T
const & val )
71 template<
typename >
class BUFFER_TYPE
85 static_assert( !std::is_const< T >::value ||
86 (std::is_const< COL_TYPE >::value && std::is_const< INDEX_TYPE >::value),
87 "When T is const COL_TYPE and INDEX_TYPE must also be const." );
91 using typename ParentClass::ColType;
127 INDEX_TYPE
const nCols,
128 BUFFER_TYPE< INDEX_TYPE >
const & offsets,
129 BUFFER_TYPE< SIZE_TYPE >
const & nnz,
130 BUFFER_TYPE< COL_TYPE >
const & columns,
131 BUFFER_TYPE< T >
const & entries ):
132 ParentClass( nRows, nCols, offsets, nnz, columns ),
221 using ParentClass::numRows;
222 using ParentClass::numColumns;
223 using ParentClass::numNonZeros;
224 using ParentClass::nonZeroCapacity;
225 using ParentClass::empty;
243 &this->m_sizes[ row ],
247 using ParentClass::getColumns;
248 using ParentClass::getOffsets;
267 bool insertNonZero( INDEX_TYPE
const row, COL_TYPE
const col, T
const & entry )
const 268 {
return ParentClass::insertIntoSetImpl( row, col, CallBacks( *
this, row, &entry ) ); }
283 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
284 T
const *
const LVARRAY_RESTRICT entriesToInsert,
285 INDEX_TYPE
const ncols )
const 286 {
return ParentClass::insertIntoSetImpl( row, cols, cols + ncols, CallBacks( *
this, row, entriesToInsert ) ); }
296 {
return ParentClass::removeFromSetImpl( row, col, CallBacks( *
this, row,
nullptr )); }
309 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
310 INDEX_TYPE
const ncols )
const 312 T *
const entries = getEntries( row );
313 INDEX_TYPE
const rowNNZ = numNonZeros( row );
314 INDEX_TYPE
const nRemoved = ParentClass::removeFromSetImpl( row, cols, cols + ncols, CallBacks( *
this, row,
nullptr ) );
333 template<
typename POLICY >
338 RAJA::forall< POLICY >( RAJA::TypedRangeSegment< INDEX_TYPE >( 0, numRows() ),
345 { entries[ i ] = value; }
361 template<
typename AtomicPolicy >
364 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
365 T
const *
const LVARRAY_RESTRICT vals,
366 INDEX_TYPE
const nCols )
const 368 INDEX_TYPE
const nnz = numNonZeros( row );
369 if( nCols < nnz / 4 && nnz > 64 )
371 addToRowBinarySearch< AtomicPolicy >( row, cols, vals, nCols );
375 addToRowLinearSearch< AtomicPolicy >( row, cols, vals, nCols );
391 template<
typename AtomicPolicy >
394 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
395 T
const *
const LVARRAY_RESTRICT vals,
396 INDEX_TYPE
const nCols )
const 400 INDEX_TYPE
const nnz = numNonZeros( row );
401 COL_TYPE
const *
const columns = getColumns( row );
402 T *
const entries = getEntries( row );
411 internal::atomicAdd( AtomicPolicy{}, entries + pos, vals[ i ] );
428 template<
typename AtomicPolicy >
431 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
432 T
const *
const LVARRAY_RESTRICT vals,
433 INDEX_TYPE
const nCols )
const 437 INDEX_TYPE
const nnz = numNonZeros( row );
438 COL_TYPE
const *
const columns = getColumns( row );
439 T *
const entries = getEntries( row );
446 if( columns[ j ] == cols[ i ] )
453 internal::atomicAdd( AtomicPolicy{}, entries + curPos, vals[ i ] );
469 template<
typename AtomicPolicy >
472 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
473 T
const *
const LVARRAY_RESTRICT vals,
474 INDEX_TYPE
const nCols )
const 476 INDEX_TYPE
const nnz = numNonZeros( row );
477 COL_TYPE
const *
const columns = getColumns( row );
478 T *
const entries = getEntries( row );
486 internal::atomicAdd( AtomicPolicy{}, entries + pos, vals[ i ] );
505 ParentClass::move( space, touch );
506 m_entries.move( space, touch );
527 template<
typename U >
530 ParentClass::template setName< U >( name );
531 m_entries.template setName< U >( name +
"/entries" );
555 INDEX_TYPE
const row, T
const *
const entriesToInsert ):
561 m_entriesToInsert( entriesToInsert )
573 COL_TYPE * incrementSize( COL_TYPE *
const curPtr, INDEX_TYPE
const nToAdd )
const 576 #ifdef LVARRAY_BOUNDS_CHECK 581 return m_crsMV.getSetValues( m_row );
591 void insert( INDEX_TYPE
const insertPos )
const 603 void set( INDEX_TYPE
const pos, INDEX_TYPE
const colPos )
const 604 {
new (&m_entries[ pos ]) T( m_entriesToInsert[ colPos ] ); }
617 void insert( INDEX_TYPE
const nLeftToInsert,
618 INDEX_TYPE
const colPos,
619 INDEX_TYPE
const pos,
620 INDEX_TYPE
const prevPos )
const 623 new (&m_entries[pos + nLeftToInsert - 1]) T( m_entriesToInsert[colPos] );
647 void remove( INDEX_TYPE
const nRemoved,
648 INDEX_TYPE
const curPos,
649 INDEX_TYPE
const nextPos )
const 657 INDEX_TYPE
const m_row;
660 INDEX_TYPE
const m_rowNNZ;
663 INDEX_TYPE
const m_rowCapacity;
669 T
const *
const m_entriesToInsert;
#define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
constexpr CRSMatrixView< T, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConstSizes() const
#define LVARRAY_ASSERT(EXP)
Assert EXP is true with no message.
void addToRowBinarySearchUnsorted(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, INDEX_TYPE const nCols) const
Add to the given entries, the entries must already exist in the matrix.
This class provides a view into a compressed row storage sparsity pattern.
INDEX_TYPE_NC removeNonZeros(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, INDEX_TYPE const ncols) const
Remove non-zero entries from the given row.
INDEX_TYPE_NC numNonZeros() const
#define ARRAYOFARRAYS_CHECK_BOUNDS(i)
Check that i is a valid array index.
bool isSortedUnique(ITER first, ITER const last, Compare &&comp=Compare())
constexpr CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConst() const
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
INDEX_TYPE IndexType
The integer type used for indexing.
constexpr CRSMatrixView< T, COL_TYPE, INDEX_TYPE const, BUFFER_TYPE > toView() const
INDEX_TYPE_NC insertNonZeros(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT entriesToInsert, INDEX_TYPE const ncols) const
Insert a non-zero entries into the given row.
CRSMatrixView(bool)
Protected constructor to be used by the CRSMatrix class.
void move(MemorySpace const space, bool const touch=true) const
Move this SparsityPattern to the given memory space and touch the values, sizes and offsets...
bool insertNonZero(INDEX_TYPE const row, COL_TYPE const col, T const &entry) const
Insert a non-zero entry at the given position.
#define LVARRAY_ASSERT_GT(lhs, rhs)
Assert that one value compares greater than the other in debug builds.
void shiftUp(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n)
Shift the values in the array at or above the given position up by the given amount. New uninitialized values take their place.
void setValues(T const &value) const
Set all the entries in the matrix to the given value.
std::conditional_t< CONST_SIZES, INDEX_TYPE const, INDEX_TYPE_NC > SIZE_TYPE
The type contained by the m_sizes buffer.
void destroy(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destory the values in the array.
constexpr INDEX_TYPE_NC nonZeroCapacity() const
BUFFER_TYPE< T > m_entries
Holds the entries of the matrix, of length numNonZeros().
Contains the implementation of LvArray::ArraySlice.
ArraySlice< T, 1, 0, INDEX_TYPE_NC > getEntries(INDEX_TYPE const row) const
Contains the implementation of LvArray:SparsityPatternView.
std::ptrdiff_t find(T const *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, T const &value, Compare &&comp=Compare())
void setName(std::string const &name)
Set the name to be displayed whenever the underlying Buffer's user call back is called.
void emplace(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, ARGS &&... args)
Insert into the array constructing the new value in place.
void addToRowBinarySearch(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, INDEX_TYPE const nCols) const
Add to the given entries, the entries must already exist in the matrix.
LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Contains functions for manipulating a contiguous array of values.
#define LVARRAY_DEBUG_VAR(X)
Mark X as an debug variable, used to silence compiler warnings.
MemorySpace
An enum containing the available memory spaces.
#define LVARRAY_ERROR_IF_GT_MSG(lhs, rhs, msg)
Raise a hard error if one value compares greater than the other.
void addToRow(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, INDEX_TYPE const nCols) const
Add to the given entries, the entries must already exist in the matrix. The columns must be sorted...
constexpr CRSMatrixView(INDEX_TYPE const nRows, INDEX_TYPE const nCols, BUFFER_TYPE< INDEX_TYPE > const &offsets, BUFFER_TYPE< SIZE_TYPE > const &nnz, BUFFER_TYPE< COL_TYPE > const &columns, BUFFER_TYPE< T > const &entries)
Construct a new CRSMatrixView from the given buffers.
constexpr SparsityPatternView< COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toSparsityPatternView() const &
std::remove_const_t< INDEX_TYPE > INDEX_TYPE_NC
Since INDEX_TYPE should always be const we need an alias for the non const version.
bool removeNonZero(INDEX_TYPE const row, COL_TYPE const col) const
Remove a non-zero entry at the given position.
void erase(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n=1)
Shift the values in the array at or above the given position down by the given amount overwriting the...
void addToRowLinearSearch(INDEX_TYPE const row, COL_TYPE const *const LVARRAY_RESTRICT cols, T const *const LVARRAY_RESTRICT vals, INDEX_TYPE const nCols) const
Add to the given entries, the entries must already exist in the matrix.
std::string string
String type.
void shiftDown(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n)
Shift the values in the array at or above the given position down by the given amount overwriting the...
#define DISABLE_HD_WARNING
Disable host device warnings.
void insert(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, ITERATOR first, std::ptrdiff_t const n)
Insert the given values into the array at the given position.
typename ParentClass::INDEX_TYPE_NC INDEX_TYPE_NC
Since INDEX_TYPE should always be const we need an alias for the non const version.
real64 EntryType
The type of the entries in the matrix.
#define LVARRAY_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
This class provides a view into a compressed row storage matrix.