Commit ee8a7d16 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Merge branch 'JK/shared_ptr' into 'develop'

Replaced TNL::Pointers::SharedPointer with std::shared_ptr in the LinearSolver base class

See merge request !111
parents ec96c5d1 4c57175e
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
#pragma once

#include <TNL/Pointers/SharedPointer.h>
#include <TNL/Config/ParameterContainer.h>
#include <TNL/Solvers/IterativeSolverMonitor.h>
#include <TNL/Matrices/DistributedMatrix.h>
@@ -15,7 +14,6 @@
#include <stdexcept>  // std::runtime_error

using namespace TNL;
using namespace TNL::Pointers;
using namespace TNL::Benchmarks;


@@ -56,7 +54,7 @@ template< template<typename> class Preconditioner, typename Matrix >
void
benchmarkPreconditionerUpdate( Benchmark<>& benchmark,
                               const Config::ParameterContainer& parameters,
                               const SharedPointer< Matrix >& matrix )
                               const std::shared_ptr< Matrix >& matrix )
{
   // skip benchmarks on devices which the user did not select
   if( ! checkDevice< typename Matrix::DeviceType >( parameters ) )
@@ -80,7 +78,7 @@ template< template<typename> class Solver, template<typename> class Precondition
void
benchmarkSolver( Benchmark<>& benchmark,
                 const Config::ParameterContainer& parameters,
                 const SharedPointer< Matrix >& matrix,
                 const std::shared_ptr< Matrix >& matrix,
                 const Vector& x0,
                 const Vector& b )
{
@@ -132,12 +130,12 @@ benchmarkSolver( Benchmark<>& benchmark,
      using RowElements = BenchmarkResult::RowElements;

      Solver< Matrix >& solver;
      const SharedPointer< Matrix >& matrix;
      const std::shared_ptr< Matrix >& matrix;
      const Vector& x;
      const Vector& b;

      MyBenchmarkResult( Solver< Matrix >& solver,
                         const SharedPointer< Matrix >& matrix,
                         const std::shared_ptr< Matrix >& matrix,
                         const Vector& x,
                         const Vector& b )
      : solver(solver), matrix(matrix), x(x), b(b)
@@ -180,7 +178,7 @@ benchmarkSolver( Benchmark<>& benchmark,
template< typename Vector >
void
benchmarkArmadillo( const Config::ParameterContainer& parameters,
                    const Pointers::SharedPointer< Matrices::CSR< double, Devices::Host, int > >& matrix,
                    const std::shared_ptr< Matrices::CSR< double, Devices::Host, int > >& matrix,
                    const Vector& x0,
                    const Vector& b )
{
+10 −14
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ using SegmentsType = TNL::Algorithms::Segments::SlicedEllpack< _Device, _Index,

using namespace TNL;
using namespace TNL::Benchmarks;
using namespace TNL::Pointers;


static const std::set< std::string > valid_solvers = {
@@ -147,7 +146,7 @@ template< typename Matrix, typename Vector >
void
benchmarkIterativeSolvers( Benchmark<>& benchmark,
                           Config::ParameterContainer parameters,
                           const SharedPointer< Matrix >& matrixPointer,
                           const std::shared_ptr< Matrix >& matrixPointer,
                           const Vector& x0,
                           const Vector& b )
{
@@ -159,11 +158,8 @@ benchmarkIterativeSolvers( Benchmark<>& benchmark,
   cuda_x0 = x0;
   cuda_b = b;

   SharedPointer< CudaMatrix > cudaMatrixPointer;
   auto cudaMatrixPointer = std::make_shared< CudaMatrix >();
   *cudaMatrixPointer = *matrixPointer;

   // synchronize shared pointers
   Pointers::synchronizeSmartPointersOnDevice< Devices::Cuda >();
#endif

   using namespace Solvers::Linear;
@@ -344,7 +340,7 @@ struct LinearSolversBenchmark
      const String file_dof = parameters.getParameter< String >( "input-dof" );
      const String file_rhs = parameters.getParameter< String >( "input-rhs" );

      SharedPointer< MatrixType > matrixPointer;
      auto matrixPointer = std::make_shared< MatrixType >();
      VectorType x0, b;

      // load the matrix
@@ -399,7 +395,7 @@ struct LinearSolversBenchmark
         using PermutationVector = Containers::Vector< IndexType, DeviceType, IndexType >;
         PermutationVector perm, iperm;
         getTrivialOrdering( *matrixPointer, perm, iperm );
         SharedPointer< MatrixType > matrix_perm;
         auto matrix_perm = std::make_shared< MatrixType >();
         VectorType x0_perm, b_perm;
         x0_perm.setLike( x0 );
         b_perm.setLike( b );
@@ -424,14 +420,14 @@ struct LinearSolversBenchmark
   static void
   runDistributed( Benchmark<>& benchmark,
                   const Config::ParameterContainer& parameters,
                   const SharedPointer< MatrixType >& matrixPointer,
                   const std::shared_ptr< MatrixType >& matrixPointer,
                   const VectorType& x0,
                   const VectorType& b )
   {
      // set up the distributed matrix
      const auto communicator = MPI_COMM_WORLD;
      const auto localRange = Partitioner::splitRange( matrixPointer->getRows(), communicator );
      SharedPointer< DistributedMatrix > distMatrixPointer( localRange, matrixPointer->getRows(), matrixPointer->getColumns(), communicator );
      auto distMatrixPointer = std::make_shared< DistributedMatrix >( localRange, matrixPointer->getRows(), matrixPointer->getColumns(), communicator );
      DistributedVector dist_x0( localRange, 0, matrixPointer->getRows(), communicator );
      DistributedVector dist_b( localRange, 0, matrixPointer->getRows(), communicator );

@@ -467,7 +463,7 @@ struct LinearSolversBenchmark
   static void
   runNonDistributed( Benchmark<>& benchmark,
                      const Config::ParameterContainer& parameters,
                      const SharedPointer< MatrixType >& matrixPointer,
                      const std::shared_ptr< MatrixType >& matrixPointer,
                      const VectorType& x0,
                      const VectorType& b )
   {
@@ -479,7 +475,7 @@ struct LinearSolversBenchmark
                                                  TNL::Matrices::GeneralMatrix,
                                                  Algorithms::Segments::CSRDefault
                                                >;
         SharedPointer< CSR > matrixCopy;
         auto matrixCopy = std::make_shared< CSR >();
         Matrices::copySparseMatrix( *matrixCopy, *matrixPointer );

#ifdef HAVE_UMFPACK
@@ -507,7 +503,7 @@ struct LinearSolversBenchmark
                                                  TNL::Matrices::GeneralMatrix,
                                                  Algorithms::Segments::CSR
                                                >;
         SharedPointer< CSR > matrixCopy;
         auto matrixCopy = std::make_shared< CSR >();
         Matrices::copySparseMatrix( *matrixCopy, *matrixPointer );

         using CudaCSR = TNL::Matrices::SparseMatrix< RealType,
@@ -517,7 +513,7 @@ struct LinearSolversBenchmark
                                                      Algorithms::Segments::CSR
                                                    >;
         using CudaVector = typename VectorType::template Self< RealType, Devices::Cuda >;
         SharedPointer< CudaCSR > cuda_matrixCopy;
         auto cuda_matrixCopy = std::make_shared< CudaCSR >();
         *cuda_matrixCopy = *matrixCopy;
         CudaVector cuda_x0, cuda_b;
         cuda_x0.setLike( x0 );
+6 −4
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@

#pragma once

#include <TNL/Pointers/SharedPointer.h>

namespace TNL {
namespace Matrices {

+2 −2
Original line number Diff line number Diff line
@@ -158,7 +158,7 @@ HeatEquationProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperato
setupLinearSystem( MatrixPointer& matrixPointer )
{
   const IndexType dofs = this->getDofs();
   typedef typename MatrixPointer::ObjectType::RowsCapacitiesType RowsCapacitiesTypeType;
   typedef typename MatrixPointer::element_type::RowsCapacitiesType RowsCapacitiesTypeType;
   Pointers::SharedPointer<  RowsCapacitiesTypeType > rowLengthsPointer;
   rowLengthsPointer->setSize( dofs );
   Matrices::MatrixSetter< MeshType, DifferentialOperator, BoundaryCondition, RowsCapacitiesTypeType > matrixSetter;
@@ -255,7 +255,7 @@ assemblyLinearSystem( const RealType& time,
                      DofVectorPointer& bPointer )
{
   this->bindDofs( dofsPointer );
   this->systemAssembler.template assembly< typename Mesh::Cell, typename MatrixPointer::ObjectType >(
   this->systemAssembler.template assembly< typename Mesh::Cell, typename MatrixPointer::element_type >(
      time,
      tau,
      this->getMesh(),
+1 −2
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@

#include <TNL/Solvers/IterativeSolver.h>
#include <TNL/Solvers/Linear/Preconditioners/Preconditioner.h>
#include <TNL/Pointers/SharedPointer.h>

#include "Traits.h"

@@ -39,7 +38,7 @@ public:
   using VectorViewType = typename Traits< Matrix >::VectorViewType;
   using ConstVectorViewType = typename Traits< Matrix >::ConstVectorViewType;
   using MatrixType = Matrix;
   using MatrixPointer = Pointers::SharedPointer< std::add_const_t< MatrixType > >;
   using MatrixPointer = std::shared_ptr< std::add_const_t< MatrixType > >;
   using PreconditionerType = Preconditioners::Preconditioner< MatrixType >;
   using PreconditionerPointer = std::shared_ptr< std::add_const_t< PreconditionerType > >;

Loading