Loading Documentation/Examples/Matrices/SparseMatrix/CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ set( COMMON_EXAMPLES SparseMatrixExample_allRowsReduction SparseMatrixExample_forElements SparseMatrixExample_forEachElement SparseMatrixExample_forRows SparseMatrixViewExample_getSerializationType SparseMatrixViewExample_getCompressedRowLengths SparseMatrixViewExample_getConstRow Loading @@ -27,6 +28,7 @@ set( COMMON_EXAMPLES SparseMatrixViewExample_rowsReduction SparseMatrixViewExample_allRowsReduction SparseMatrixViewExample_forElements SparseMatrixViewExample_forRows SparseMatrixViewExample_forEachElement ) Loading Documentation/Examples/Matrices/SparseMatrix/SparseMatrixExample_forRows.cpp 0 → 100644 +37 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/Matrices/SparseMatrix.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> template< typename Device > void forRowsExample() { using MatrixType = TNL::Matrices::SparseMatrix< double, Device >; using RowViewType = typename MatrixType::RowViewType; MatrixType matrix( { 1, 2, 3, 4, 5, }, 5 ); auto f = [] __cuda_callable__ ( RowViewType& row ) mutable { for( int localIdx = 0; localIdx <= row.getRowIndex(); // This is important, some matrix formats may allocate more matrix elements localIdx++ ) // than we requested. These padding elements are processed here as well. // and so we cannot use row.getSize() { row.setValue( localIdx, row.getRowIndex() - localIdx + 1.0 ); row.setColumnIndex( localIdx, localIdx ); } }; matrix.forEachRow( f ); std::cout << matrix << std::endl; } int main( int argc, char* argv[] ) { std::cout << "Creating matrix on host: " << std::endl; forRowsExample< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Creating matrix on CUDA device: " << std::endl; forRowsExample< TNL::Devices::Cuda >(); #endif } Documentation/Examples/Matrices/SparseMatrix/SparseMatrixExample_forRows.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SparseMatrixExample_forRows.cpp No newline at end of file Documentation/Examples/Matrices/SparseMatrix/SparseMatrixViewExample_forRows.cpp 0 → 100644 +38 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/Matrices/SparseMatrix.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> template< typename Device > void forRowsExample() { using MatrixType = TNL::Matrices::SparseMatrix< double, Device >; using RowViewType = typename MatrixType::ViewType::RowViewType; MatrixType matrix( { 1, 2, 3, 4, 5, }, 5 ); auto view = matrix.getView(); auto f = [] __cuda_callable__ ( RowViewType& row ) mutable { for( int localIdx = 0; localIdx <= row.getRowIndex(); // This is important, some matrix formats may allocate more matrix elements localIdx++ ) // than we requested. These padding elements are processed here as well. // and so we cannot use row.getSize() { row.setValue( localIdx, row.getRowIndex() - localIdx + 1.0 ); row.setColumnIndex( localIdx, localIdx ); } }; view.forEachRow( f ); std::cout << matrix << std::endl; } int main( int argc, char* argv[] ) { std::cout << "Creating matrix on host: " << std::endl; forRowsExample< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Creating matrix on CUDA device: " << std::endl; forRowsExample< TNL::Devices::Cuda >(); #endif } Documentation/Examples/Matrices/SparseMatrix/SparseMatrixViewExample_forRows.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SparseMatrixViewExample_forRows.cpp No newline at end of file Loading
Documentation/Examples/Matrices/SparseMatrix/CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ set( COMMON_EXAMPLES SparseMatrixExample_allRowsReduction SparseMatrixExample_forElements SparseMatrixExample_forEachElement SparseMatrixExample_forRows SparseMatrixViewExample_getSerializationType SparseMatrixViewExample_getCompressedRowLengths SparseMatrixViewExample_getConstRow Loading @@ -27,6 +28,7 @@ set( COMMON_EXAMPLES SparseMatrixViewExample_rowsReduction SparseMatrixViewExample_allRowsReduction SparseMatrixViewExample_forElements SparseMatrixViewExample_forRows SparseMatrixViewExample_forEachElement ) Loading
Documentation/Examples/Matrices/SparseMatrix/SparseMatrixExample_forRows.cpp 0 → 100644 +37 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/Matrices/SparseMatrix.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> template< typename Device > void forRowsExample() { using MatrixType = TNL::Matrices::SparseMatrix< double, Device >; using RowViewType = typename MatrixType::RowViewType; MatrixType matrix( { 1, 2, 3, 4, 5, }, 5 ); auto f = [] __cuda_callable__ ( RowViewType& row ) mutable { for( int localIdx = 0; localIdx <= row.getRowIndex(); // This is important, some matrix formats may allocate more matrix elements localIdx++ ) // than we requested. These padding elements are processed here as well. // and so we cannot use row.getSize() { row.setValue( localIdx, row.getRowIndex() - localIdx + 1.0 ); row.setColumnIndex( localIdx, localIdx ); } }; matrix.forEachRow( f ); std::cout << matrix << std::endl; } int main( int argc, char* argv[] ) { std::cout << "Creating matrix on host: " << std::endl; forRowsExample< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Creating matrix on CUDA device: " << std::endl; forRowsExample< TNL::Devices::Cuda >(); #endif }
Documentation/Examples/Matrices/SparseMatrix/SparseMatrixExample_forRows.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SparseMatrixExample_forRows.cpp No newline at end of file
Documentation/Examples/Matrices/SparseMatrix/SparseMatrixViewExample_forRows.cpp 0 → 100644 +38 −0 Original line number Diff line number Diff line #include <iostream> #include <TNL/Matrices/SparseMatrix.h> #include <TNL/Devices/Host.h> #include <TNL/Devices/Cuda.h> template< typename Device > void forRowsExample() { using MatrixType = TNL::Matrices::SparseMatrix< double, Device >; using RowViewType = typename MatrixType::ViewType::RowViewType; MatrixType matrix( { 1, 2, 3, 4, 5, }, 5 ); auto view = matrix.getView(); auto f = [] __cuda_callable__ ( RowViewType& row ) mutable { for( int localIdx = 0; localIdx <= row.getRowIndex(); // This is important, some matrix formats may allocate more matrix elements localIdx++ ) // than we requested. These padding elements are processed here as well. // and so we cannot use row.getSize() { row.setValue( localIdx, row.getRowIndex() - localIdx + 1.0 ); row.setColumnIndex( localIdx, localIdx ); } }; view.forEachRow( f ); std::cout << matrix << std::endl; } int main( int argc, char* argv[] ) { std::cout << "Creating matrix on host: " << std::endl; forRowsExample< TNL::Devices::Host >(); #ifdef HAVE_CUDA std::cout << "Creating matrix on CUDA device: " << std::endl; forRowsExample< TNL::Devices::Cuda >(); #endif }
Documentation/Examples/Matrices/SparseMatrix/SparseMatrixViewExample_forRows.cu 0 → 120000 +1 −0 Original line number Diff line number Diff line SparseMatrixViewExample_forRows.cpp No newline at end of file