Commit fca67419 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Writting sparse matrix documentation.

parent 96484f79
Loading
Loading
Loading
Loading
+52 −19
Original line number Diff line number Diff line
@@ -14,15 +14,30 @@ IF( BUILD_CUDA )
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_Constructor_std_map.out
                       OUTPUT SparseMatrixExample_Constructor_std_map.out )

#   CUDA_ADD_EXECUTABLE( SparseMatrixExample_setElements_cuda SparseMatrixExample_setElements.cu )
#   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_setElements_cuda > 
#                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_setElements.out
#                       OUTPUT SparseMatrixExample_setElements.out )

#   CUDA_ADD_EXECUTABLE( SparseMatrixExample_getCompressedRowLengths_cuda SparseMatrixExample_getCompressedRowLengths.cu )
#   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_getCompressedRowLengths_cuda >
#                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_getCompressedRowLengths.out
#                       OUTPUT SparseMatrixExample_getCompressedRowLengths.out )
   CUDA_ADD_EXECUTABLE( SparseMatrixExample_getSerializationType_cuda SparseMatrixExample_getSerializationType.cu )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_getSerializationType_cuda >
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_getSerializationType.out
                       OUTPUT SparseMatrixExample_getSerializationType.out )

   CUDA_ADD_EXECUTABLE( SparseMatrixExample_setRowCapacities_cuda SparseMatrixExample_setRowCapacities.cu )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_setRowCapacities_cuda >
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_setRowCapacities.out
                       OUTPUT SparseMatrixExample_setRowCapacities.out )

   CUDA_ADD_EXECUTABLE( SparseMatrixExample_setElements_cuda SparseMatrixExample_setElements.cu )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_setElements_cuda > 
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_setElements.out
                       OUTPUT SparseMatrixExample_setElements.out )

   CUDA_ADD_EXECUTABLE( SparseMatrixExample_setElements_map_cuda SparseMatrixExample_setElements_map.cu )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_setElements_map_cuda > 
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_setElements_map.out
                       OUTPUT SparseMatrixExample_setElements_map.out )

   CUDA_ADD_EXECUTABLE( SparseMatrixExample_getCompressedRowLengths_cuda SparseMatrixExample_getCompressedRowLengths.cu )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_getCompressedRowLengths_cuda >
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_getCompressedRowLengths.out
                       OUTPUT SparseMatrixExample_getCompressedRowLengths.out )

#   CUDA_ADD_EXECUTABLE( SparseMatrixExample_getElementsCount_cuda SparseMatrixExample_getElementsCount.cu )
#   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_getElementsCount_cuda >
@@ -150,15 +165,30 @@ ELSE()
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_Constructor_std_map.out
                       OUTPUT SparseMatrixExample_Constructor_std_map.out )

#   ADD_EXECUTABLE( SparseMatrixExample_setElements SparseMatrixExample_setElements.cpp )
#   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_setElements > 
#                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_setElements.out
#                       OUTPUT SparseMatrixExample_setElements.out )
   ADD_EXECUTABLE( SparseMatrixExample_getSerializationType SparseMatrixExample_getSerializationType.cpp )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_getSerializationType >
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_getSerializationType.out
                       OUTPUT SparseMatrixExample_getSerializationType.out )

   ADD_EXECUTABLE( SparseMatrixExample_setRowCapacities SparseMatrixExample_setRowCapacities.cpp )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_setRowCapacities >
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_setRowCapacities.out
                       OUTPUT SparseMatrixExample_setRowCapacities.out )

   ADD_EXECUTABLE( SparseMatrixExample_setElements SparseMatrixExample_setElements.cpp )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_setElements > 
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_setElements.out
                       OUTPUT SparseMatrixExample_setElements.out )

   ADD_EXECUTABLE( SparseMatrixExample_setElements_map SparseMatrixExample_setElements_map.cpp )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_setElements_map > 
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_setElements_map.out
                       OUTPUT SparseMatrixExample_setElements_map.out )

#   ADD_EXECUTABLE( SparseMatrixExample_getCompressedRowLengths SparseMatrixExample_getCompressedRowLengths.cpp )
#   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_getCompressedRowLengths >
#                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_getCompressedRowLengths.out
#                       OUTPUT SparseMatrixExample_getCompressedRowLengths.out )
   ADD_EXECUTABLE( SparseMatrixExample_getCompressedRowLengths SparseMatrixExample_getCompressedRowLengths.cpp )
   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_getCompressedRowLengths >
                        ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/SparseMatrixExample_getCompressedRowLengths.out
                       OUTPUT SparseMatrixExample_getCompressedRowLengths.out )

#   ADD_EXECUTABLE( SparseMatrixExample_getElementsCount SparseMatrixExample_getElementsCount.cpp )
#   ADD_CUSTOM_COMMAND( COMMAND SparseMatrixExample_getElementsCount >
@@ -276,8 +306,11 @@ ADD_CUSTOM_TARGET( RunSparseMatricesExamples ALL DEPENDS
   SparseMatrixExample_Constructor_init_list_1.out
   SparseMatrixExample_Constructor_init_list_2.out
   SparseMatrixExample_Constructor_std_map.out
#   SparseMatrixExample_setElements.out
#   SparseMatrixExample_getCompressedRowLengths.out
   SparseMatrixExample_getSerializationType.out
   SparseMatrixExample_setRowCapacities.out
   SparseMatrixExample_setElements.out
   SparseMatrixExample_setElements_map.out
   SparseMatrixExample_getCompressedRowLengths.out
#   SparseMatrixExample_getElementsCount.out
#   SparseMatrixExample_getConstRow.out
#   SparseMatrixExample_getRow.out
+2 −1
Original line number Diff line number Diff line
@@ -7,7 +7,8 @@ template< typename Device >
void initializerListExample()
{
   TNL::Matrices::SparseMatrix< double, Device > matrix {
      {  1,  2,  3,  4,  5 }, 6 };
      {  1,  2,  3,  4,  5 }, // row capacities
      6 };                    // number of matrix columns

   for( int row = 0; row < matrix.getRows(); row++ )
      for( int column = 0; column <= row; column++ )
+9 −6
Original line number Diff line number Diff line
@@ -6,7 +6,10 @@
template< typename Device >
void initializerListExample()
{
   TNL::Matrices::SparseMatrix< double, Device > matrix ( 5, 5, {
   TNL::Matrices::SparseMatrix< double, Device > matrix (
      5, // number of matrix rows
      5, // number of matrix columns
      {  // matrix elements definition
         {  0,  0,  2.0 },
         {  1,  0, -1.0 }, {  1,  1,  2.0 }, {  1,  2, -1.0 },
         {  2,  1, -1.0 }, {  2,  2,  2.0 }, {  2,  3, -1.0 },
+34 −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 getCompressedRowLengthsExample()
{
   TNL::Matrices::SparseMatrix< double, Device > triangularMatrix( 5, 5 );
   triangularMatrix.setElements( {
      { 0, 0,  1 },
      { 1, 0,  2 }, { 1, 1,  3 },
      { 2, 0,  4 }, { 2, 1,  5 }, { 2, 2,  6 },
      { 3, 0,  7 }, { 3, 1,  8 }, { 3, 2,  9 }, { 3, 3, 10 },
      { 4, 0, 11 }, { 4, 1, 12 }, { 4, 2, 13 }, { 4, 3, 14 }, { 4, 4, 15 } } );

   std::cout << triangularMatrix << std::endl;

   TNL::Containers::Vector< int, Device > rowLengths;
   triangularMatrix.getCompressedRowLengths( rowLengths );

   std::cout << "Compressed row lengths are: " << rowLengths << std::endl;
}

int main( int argc, char* argv[] )
{
   std::cout << "Getting compressed row lengths on host: " << std::endl;
   getCompressedRowLengthsExample< TNL::Devices::Host >();

#ifdef HAVE_CUDA
   std::cout << "Getting compressed row lengths on CUDA device: " << std::endl;
   getCompressedRowLengthsExample< TNL::Devices::Cuda >();
#endif
}
+1 −0
Original line number Diff line number Diff line
SparseMatrixExample_getCompressedRowLengths.cpp
 No newline at end of file
Loading