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

Writting documentation and refactoring DenseMatrix.

parent 8e247844
Loading
Loading
Loading
Loading
+39 −23
Original line number Diff line number Diff line
IF( BUILD_CUDA )
   CUDA_ADD_EXECUTABLE( DenseMatrixExample_Constructor_init_list_cuda DenseMatrixExample_Constructor_init_list.cu )
   ADD_CUSTOM_COMMAND( COMMAND DenseMatrixExample_Constructor_init_list_cuda > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/DenseMatrixExample_Constructor_init_list.out 
                       OUTPUT DenseMatrixExample_Constructor_init_list.out )

   CUDA_ADD_EXECUTABLE( DenseMatrixExample_setElements_cuda DenseMatrixExample_setElements.cu )
   ADD_CUSTOM_COMMAND( COMMAND DenseMatrixExample_setElements_cuda > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/DenseMatrixExample_setElements.out 
                       OUTPUT DenseMatrixExample_setElements.out )

   CUDA_ADD_EXECUTABLE( DenseMatrixExample_getCompressedRowLengths_cuda DenseMatrixExample_getCompressedRowLengths.cu )
   ADD_CUSTOM_COMMAND( COMMAND DenseMatrixExample_getCompressedRowLengths_cuda > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/DenseMatrixExample_getCompressedRowLengths.out 
                       OUTPUT DenseMatrixExample_getCompressedRowLengths.out )

ELSE()
#IF( BUILD_CUDA )
#   CUDA_ADD_EXECUTABLE( DenseMatrixExample_Constructor_init_list_cuda DenseMatrixExample_Constructor_init_list.cu )
#   ADD_CUSTOM_COMMAND( COMMAND DenseMatrixExample_Constructor_init_list_cuda > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/DenseMatrixExample_Constructor_init_list.out 
#                       OUTPUT DenseMatrixExample_Constructor_init_list.out )
#
#   CUDA_ADD_EXECUTABLE( DenseMatrixExample_setElements_cuda DenseMatrixExample_setElements.cu )
#   ADD_CUSTOM_COMMAND( COMMAND DenseMatrixExample_setElements_cuda > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/DenseMatrixExample_setElements.out 
#                       OUTPUT DenseMatrixExample_setElements.out )
#
#   CUDA_ADD_EXECUTABLE( DenseMatrixExample_getCompressedRowLengths_cuda DenseMatrixExample_getCompressedRowLengths.cu )
#   ADD_CUSTOM_COMMAND( COMMAND DenseMatrixExample_getCompressedRowLengths_cuda > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/DenseMatrixExample_getCompressedRowLengths.out 
#                       OUTPUT DenseMatrixExample_getCompressedRowLengths.out )
#
#ELSE()
   ADD_EXECUTABLE( DenseMatrixExample_Constructor_init_list DenseMatrixExample_Constructor_init_list.cpp )
   ADD_CUSTOM_COMMAND( COMMAND DenseMatrixExample_Constructor_init_list > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/DenseMatrixExample_Constructor_init_list.out 
                       OUTPUT DenseMatrixExample_Constructor_init_list.out )
@@ -23,18 +23,34 @@ ELSE()
   ADD_EXECUTABLE( DenseMatrixExample_getCompressedRowLengths DenseMatrixExample_getCompressedRowLengths.cpp )
   ADD_CUSTOM_COMMAND( COMMAND DenseMatrixExample_getCompressedRowLengths > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/DenseMatrixExample_getCompressedRowLengths.out 
                       OUTPUT DenseMatrixExample_getCompressedRowLengths.out )
ENDIF()

IF( BUILD_CUDA )
ADD_CUSTOM_TARGET( RunMatricesExamples-cuda ALL DEPENDS
   DenseMatrixExample_Constructor_init_list.out
   DenseMatrixExample_setElements.out
   DenseMatrixExample_getCompressedRowLengths.out
   )
ELSE()
   ADD_EXECUTABLE( DenseMatrixExample_getElementsCount DenseMatrixExample_getElementsCount.cpp )
   ADD_CUSTOM_COMMAND( COMMAND DenseMatrixExample_getElementsCount > ${TNL_DOCUMENTATION_OUTPUT_SNIPPETS_PATH}/DenseMatrixExample_getElementsCount.out 
                       OUTPUT DenseMatrixExample_getElementsCount.out )

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

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

#ENDIF()

#IF( BUILD_CUDA )
#ADD_CUSTOM_TARGET( RunMatricesExamples-cuda ALL DEPENDS
#   DenseMatrixExample_Constructor_init_list.out
#   DenseMatrixExample_setElements.out
#   DenseMatrixExample_getCompressedRowLengths.out
#   )
#ELSE()
ADD_CUSTOM_TARGET( RunMatricesExamples ALL DEPENDS
   DenseMatrixExample_Constructor_init_list.out
   DenseMatrixExample_setElements.out
   DenseMatrixExample_getCompressedRowLengths.out
   DenseMatrixExample_getElementsCount.out
   DenseMatrixExample_getConstRow.out
   DenseMatrixExample_getRow.out
   )
ENDIF()
#ENDIF()
+0 −1
Original line number Diff line number Diff line
DenseMatrixExample_Constructor_init_list.cpp
 No newline at end of file
+0 −1
Original line number Diff line number Diff line
DenseMatrixExample_getCompressedRowLengths.cpp
 No newline at end of file
+32 −0
Original line number Diff line number Diff line
#include <iostream>
#include <functional>
#include <TNL/Algorithms/ParallelFor.h>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Devices/Host.h>

int main( int argc, char* argv[] )
{
   TNL::Matrices::DenseMatrix< double, TNL::Devices::Host > matrix {
      { 1, 0, 0, 0, 0 },
      { 1, 2, 0, 0, 0 },
      { 1, 2, 3, 0, 0 },
      { 1, 2, 3, 4, 0 },
      { 1, 2, 3, 4, 5 }
   };

   /***
    * We need a matrix view to pass the matrix to lambda function even on CUDA device.
    */
   const auto matrixView = matrix.getConstView();

   /***
    * Fetch lambda function returns diagonal element in each row.
    */
   auto fetch = [=] __cuda_callable__ ( int rowIdx ) mutable -> double {
      auto row = matrixView.getRow( rowIdx );
      return row.getElement( rowIdx );
   };

   int trace = TNL::Algorithms::Reduction< TNL::Devices::Host >::reduce( matrix.getRows(), std::plus<>{}, fetch, 0 );
   std::cout << "Matrix trace is " << trace << "." << std::endl;
}
+17 −0
Original line number Diff line number Diff line
#include <iostream>
#include <TNL/Matrices/DenseMatrix.h>
#include <TNL/Devices/Host.h>

int main( int argc, char* argv[] )
{
   TNL::Matrices::DenseMatrix< double, TNL::Devices::Host > triangularMatrix {
      {  1 },
      {  2,  3 },
      {  4,  5,  6 },
      {  7,  8,  9, 10 },
      { 11, 12, 13, 14, 15 }
   };

   std::cout << "Matrix elements count is " << triangularMatrix.getElementsCount() << "." << std::endl;
   std::cout << "Non-zero matrix elements count is " << triangularMatrix.getNonzeroElementsCount() << "." << std::endl;
}
Loading