33 template<
typename POLICY,
typename T >
35 void atomicAdd( POLICY, T *
const acc, T
const & val )
36 { RAJA::atomicAdd< POLICY >( acc, val ); }
47 template<
typename T >
49 void atomicAdd( RAJA::seq_atomic, T * acc, T
const & val )
72 template<
typename >
class BUFFER_TYPE
86 static_assert( !std::is_const< T >::value ||
87 (std::is_const< COL_TYPE >::value && std::is_const< INDEX_TYPE >::value),
88 "When T is const COL_TYPE and INDEX_TYPE must also be const." );
128 INDEX_TYPE
const nCols,
129 BUFFER_TYPE< INDEX_TYPE >
const & offsets,
130 BUFFER_TYPE< SIZE_TYPE >
const & nnz,
131 BUFFER_TYPE< COL_TYPE >
const & columns,
132 BUFFER_TYPE< T >
const & entries ):
133 ParentClass( nRows, nCols, offsets, nnz, columns ),
222 using ParentClass::numRows;
223 using ParentClass::numColumns;
224 using ParentClass::numNonZeros;
225 using ParentClass::nonZeroCapacity;
226 using ParentClass::empty;
244 &this->m_sizes[ row ],
254 return m_entries.data();
257 using ParentClass::getColumns;
258 using ParentClass::getOffsets;
259 using ParentClass::getSizes;
278 bool insertNonZero( INDEX_TYPE
const row, COL_TYPE
const col, T
const & entry )
const 279 {
return ParentClass::insertIntoSetImpl( row, col,
CallBacks( *
this, row, &entry ) ); }
294 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
295 T
const *
const LVARRAY_RESTRICT entriesToInsert,
296 INDEX_TYPE
const ncols )
const 297 {
return ParentClass::insertIntoSetImpl( row, cols, cols + ncols,
CallBacks( *
this, row, entriesToInsert ) ); }
307 {
return ParentClass::removeFromSetImpl( row, col,
CallBacks( *
this, row,
nullptr )); }
320 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
321 INDEX_TYPE
const ncols )
const 323 T *
const entries = getEntries( row );
324 INDEX_TYPE
const rowNNZ = numNonZeros( row );
325 INDEX_TYPE
const nRemoved = ParentClass::removeFromSetImpl( row, cols, cols + ncols,
CallBacks( *
this, row,
nullptr ) );
344 template<
typename POLICY >
348 RAJA::forall< POLICY >( RAJA::TypedRangeSegment< INDEX_TYPE >( 0, numRows() ),
355 { entries[ i ] = value; }
371 #if !defined( LVARRAY_USE_UMPIRE ) 372 LVARRAY_ERROR_IF_NE_MSG( m_entries.getPreviousSpace(), MemorySpace::host,
"Without Umpire only host memory is supported." );
375 if( m_entries.capacity() > 0 )
377 ParentClass::move( m_entries.getPreviousSpace(), false );
378 m_entries.move( m_entries.getPreviousSpace(), true );
380 size_t const numBytes = m_entries.capacity() *
sizeof( T );
382 umpireInterface::memset( m_entries.data(), 0, numBytes );
399 template<
typename AtomicPolicy >
402 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
403 T
const *
const LVARRAY_RESTRICT vals,
404 INDEX_TYPE
const nCols )
const 406 INDEX_TYPE
const nnz = numNonZeros( row );
407 if( nCols < nnz / 4 && nnz > 64 )
409 addToRowBinarySearch< AtomicPolicy >( row, cols, vals, nCols );
413 addToRowLinearSearch< AtomicPolicy >( row, cols, vals, nCols );
429 template<
typename AtomicPolicy >
432 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
433 T
const *
const LVARRAY_RESTRICT vals,
434 INDEX_TYPE
const nCols )
const 438 INDEX_TYPE
const nnz = numNonZeros( row );
439 COL_TYPE
const *
const columns = getColumns( row );
440 T *
const entries = getEntries( row );
449 internal::atomicAdd( AtomicPolicy{}, entries + pos, vals[ i ] );
466 template<
typename AtomicPolicy >
469 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
470 T
const *
const LVARRAY_RESTRICT vals,
471 INDEX_TYPE
const nCols )
const 475 INDEX_TYPE
const nnz = numNonZeros( row );
476 COL_TYPE
const *
const columns = getColumns( row );
477 T *
const entries = getEntries( row );
484 if( columns[ j ] == cols[ i ] )
491 internal::atomicAdd( AtomicPolicy{}, entries + curPos, vals[ i ] );
507 template<
typename AtomicPolicy >
510 COL_TYPE
const *
const LVARRAY_RESTRICT cols,
511 T
const *
const LVARRAY_RESTRICT vals,
512 INDEX_TYPE
const nCols )
const 514 INDEX_TYPE
const nnz = numNonZeros( row );
515 COL_TYPE
const *
const columns = getColumns( row );
516 T *
const entries = getEntries( row );
524 internal::atomicAdd( AtomicPolicy{}, entries + pos, vals[ i ] );
543 ParentClass::move( space, touch );
544 m_entries.move( space, touch );
565 template<
typename U >
568 ParentClass::template setName< U >( name );
569 m_entries.template setName< U >( name +
"/entries" );
593 INDEX_TYPE
const row, T
const *
const entriesToInsert ):
596 m_rowNNZ( crsMV.numNonZeros( row ) ),
597 m_rowCapacity( crsMV.nonZeroCapacity( row ) ),
598 m_entries( crsMV.getEntries( row ) ),
599 m_entriesToInsert( entriesToInsert )
611 COL_TYPE *
incrementSize( COL_TYPE *
const curPtr, INDEX_TYPE
const nToAdd )
const 614 #ifdef LVARRAY_BOUNDS_CHECK 619 return m_crsMV.getSetValues( m_row );
629 void insert( INDEX_TYPE
const insertPos )
const 641 void set( INDEX_TYPE
const pos, INDEX_TYPE
const colPos )
const 642 {
new (&m_entries[ pos ]) T( m_entriesToInsert[ colPos ] ); }
655 void insert( INDEX_TYPE
const nLeftToInsert,
656 INDEX_TYPE
const colPos,
657 INDEX_TYPE
const pos,
658 INDEX_TYPE
const prevPos )
const 661 new (&m_entries[pos + nLeftToInsert - 1]) T( m_entriesToInsert[colPos] );
685 void remove( INDEX_TYPE
const nRemoved,
686 INDEX_TYPE
const curPos,
687 INDEX_TYPE
const nextPos )
const #define LVARRAY_UNUSED_VARIABLE(X)
Mark X as an unused variable, used to silence compiler warnings.
Definition: Macros.hpp:51
#define LVARRAY_ASSERT(EXP)
Assert EXP is true with no message.
Definition: Macros.hpp:184
This class provides a view into a compressed row storage sparsity pattern.
Definition: SparsityPatternView.hpp:61
CRSMatrixView const & m_crsMV
A reference to the associated CRSMatrixView.
Definition: CRSMatrixView.hpp:692
INDEX_TYPE IndexType
The integer type used for indexing.
Definition: ArrayOfArraysView.hpp:188
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void insert(INDEX_TYPE const nLeftToInsert, INDEX_TYPE const colPos, INDEX_TYPE const pos, INDEX_TYPE const prevPos) const
Used with the sortedArrayManipulation::insertSorted routine this callback signals that the given colu...
Definition: CRSMatrixView.hpp:655
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE std::ptrdiff_t find(T const *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, T const &value, Compare &&comp=Compare())
Definition: sortedArrayManipulation.hpp:411
#define ARRAYOFARRAYS_CHECK_BOUNDS(i)
Check that i is a valid array index.
Definition: ArrayOfArraysView.hpp:106
LVARRAY_HOST_DEVICE bool removeNonZero(INDEX_TYPE const row, COL_TYPE const col) const
Remove a non-zero entry at the given position.
Definition: CRSMatrixView.hpp:306
LVARRAY_HOST_DEVICE T const * getEntries() const
Definition: CRSMatrixView.hpp:252
LVARRAY_HOST_DEVICE 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.
Definition: CRSMatrixView.hpp:509
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
Definition: ArraySlice.hpp:89
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T, COL_TYPE, INDEX_TYPE const, BUFFER_TYPE > toView() const
Definition: CRSMatrixView.hpp:161
LVARRAY_HOST_DEVICE 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.
Definition: CRSMatrixView.hpp:127
CRSMatrixView(bool)
Protected constructor to be used by the CRSMatrix class.
Definition: CRSMatrixView.hpp:555
void move(MemorySpace const space, bool const touch=true) const
Move this matrix to the given memory space and touch the values, sizes and offsets.
Definition: CRSMatrixView.hpp:541
LVARRAY_HOST_DEVICE CallBacks(CRSMatrixView const &crsMV, INDEX_TYPE const row, T const *const entriesToInsert)
Constructor.
Definition: CRSMatrixView.hpp:592
This class provides the callbacks for the sortedArrayManipulation routines.
Definition: CRSMatrixView.hpp:581
#define LVARRAY_ASSERT_GT(lhs, rhs)
Assert that one value compares greater than the other in debug builds.
Definition: Macros.hpp:515
#define LVARRAY_ERROR_IF_NE_MSG(lhs, rhs, msg)
Raise a hard error if two values are not equal.
Definition: Macros.hpp:305
void setValues(T const &value) const
Set all the entries in the matrix to the given value.
Definition: CRSMatrixView.hpp:345
Contains the LvArray umpire interface. This is only used to keep umpire/ResourceManager.hpp out of the includes for most headers.
std::conditional_t< CONST_SIZES, INDEX_TYPE const, INDEX_TYPE_NC > SIZE_TYPE
The type contained by the m_sizes buffer.
Definition: ArrayOfArraysView.hpp:177
T *const m_entries
A pointer to the entries in the row.
Definition: CRSMatrixView.hpp:704
void zero() const
Use memset to set all the values in the matrix to 0.
Definition: CRSMatrixView.hpp:369
LVARRAY_HOST_DEVICE void insert(INDEX_TYPE const insertPos) const
Used with sortedArrayManipulation::insert routine this callback signals that the column was inserted ...
Definition: CRSMatrixView.hpp:629
BUFFER_TYPE< T > m_entries
Holds the entries of the matrix, of length numNonZeros().
Definition: CRSMatrixView.hpp:573
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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...
Definition: arrayManipulation.hpp:396
Contains the implementation of LvArray::ArraySlice.
LVARRAY_HOST_DEVICE constexpr SparsityPatternView< COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toSparsityPatternView() const &
Definition: CRSMatrixView.hpp:206
LVARRAY_HOST_DEVICE COL_TYPE * incrementSize(COL_TYPE *const curPtr, INDEX_TYPE const nToAdd) const
Callback signaling that the size of the row has increased.
Definition: CRSMatrixView.hpp:611
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: CRSMatrixView.hpp:319
Contains the implementation of LvArray:SparsityPatternView.
INDEX_TYPE const m_row
The associated row.
Definition: CRSMatrixView.hpp:695
LVARRAY_HOST_DEVICE INDEX_TYPE_NC numNonZeros() const
Definition: SparsityPatternView.hpp:208
LVARRAY_HOST_DEVICE void atomicAdd(POLICY, T *const acc, T const &val)
Wrapper around RAJA::atomicAdd.
Definition: CRSMatrixView.hpp:35
void setName(std::string const &name)
Set the name to be displayed whenever the underlying Buffer's user call back is called.
Definition: CRSMatrixView.hpp:566
INDEX_TYPE const m_rowCapacity
The non zero capacity of the row.
Definition: CRSMatrixView.hpp:701
LVARRAY_HOST_DEVICE 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.
Definition: CRSMatrixView.hpp:468
LVARRAY_HOST_DEVICE 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.
Definition: CRSMatrixView.hpp:293
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T const, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConst() const
Definition: CRSMatrixView.hpp:191
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE bool isSortedUnique(ITER first, ITER const last, Compare &&comp=Compare())
Definition: sortedArrayManipulation.hpp:374
camp::resources::Platform MemorySpace
an alias for camp::resources::Platform.
Definition: bufferManipulation.hpp:31
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.
Definition: Macros.hpp:57
T const *const m_entriesToInsert
A pointer to the entries to insert.
Definition: CRSMatrixView.hpp:707
The top level namespace.
Definition: Array.hpp:24
LVARRAY_HOST_DEVICE 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.
Definition: CRSMatrixView.hpp:431
#define LVARRAY_ERROR_IF_GT_MSG(lhs, rhs, msg)
Raise a hard error if one value compares greater than the other.
Definition: Macros.hpp:337
LVARRAY_HOST_DEVICE 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...
Definition: CRSMatrixView.hpp:401
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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...
Definition: arrayManipulation.hpp:363
COL_TYPE ColType
The integer type used to enumerate the columns.
Definition: SparsityPatternView.hpp:77
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void destroy(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size)
Destory the values in the array.
Definition: arrayManipulation.hpp:152
LVARRAY_HOST_DEVICE bool insertNonZero(INDEX_TYPE const row, COL_TYPE const col, T const &entry) const
Insert a non-zero entry at the given position.
Definition: CRSMatrixView.hpp:278
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:326
LVARRAY_HOST_DEVICE ArraySlice< T, 1, 0, INDEX_TYPE_NC > getEntries(INDEX_TYPE const row) const
Definition: CRSMatrixView.hpp:240
INDEX_TYPE const m_rowNNZ
The number of non zero entries in the row.
Definition: CRSMatrixView.hpp:698
#define DISABLE_HD_WARNING
Disable host device warnings.
Definition: Macros.hpp:561
LVARRAY_HOST_DEVICE constexpr CRSMatrixView< T, COL_TYPE const, INDEX_TYPE const, BUFFER_TYPE > toViewConstSizes() const
Definition: CRSMatrixView.hpp:176
typename ParentClass::INDEX_TYPE_NC INDEX_TYPE_NC
Since INDEX_TYPE should always be const we need an alias for the non const version.
Definition: ArrayOfSetsView.hpp:47
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE 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.
Definition: arrayManipulation.hpp:478
T EntryType
The type of the entries in the matrix.
Definition: CRSMatrixView.hpp:91
#define LVARRAY_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
Definition: Macros.hpp:485
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:549
This class provides a view into a compressed row storage matrix.
Definition: CRSMatrixView.hpp:74