16 #if !defined(KRATOS_DISTRIBUTED_CSR_CONVERSION_UTILITIES_H_INCLUDED)
17 #define KRATOS_DISTRIBUTED_CSR_CONVERSION_UTILITIES_H_INCLUDED
22 #include <amgcl/backend/builtin.hpp>
23 #include <amgcl/backend/interface.hpp>
24 #include <amgcl/mpi/distributed_matrix.hpp>
25 #include <amgcl/adapter/zero_copy.hpp>
46 template<
class TDataType,
class TIndexType >
50 bool MoveToBackend=
true)
53 auto loc_a = amgcl::adapter::zero_copy(chunk,
60 auto rem_a = amgcl::adapter::zero_copy(chunk,
62 global_index2.data().
begin(),
69 amgcl::mpi::communicator comm(raw_mpi_comm);
71 auto pAmgcl = Kratos::make_shared<amgcl::mpi::distributed_matrix<amgcl::backend::builtin<double>>>(comm, loc_a, rem_a);
74 pAmgcl->move_to_backend();
79 template<
class TDataType,
class TIndexType >
81 amgcl::mpi::distributed_matrix<amgcl::backend::builtin<double>>& rA,
86 KRATOS_ERROR <<
"matrix A was moved to backend, so it is impossible to convert it back to CSR matrix" << std::endl;
88 auto pAconverted = Kratos::make_unique<DistributedCsrMatrix<TDataType, TIndexType>>(kratos_comm);
90 MPI_Comm amgcl_raw_comm = rA.comm();
92 KRATOS_ERROR <<
"MPI communicator mismatch between the communicator passed to the conversion function and the one used internally by amgcl" << std::endl;
95 pAconverted->pGetRowNumbering() = Kratos::make_unique<DistributedNumbering<IndexType>>(kratos_comm,rA.local()->nrows);
96 pAconverted->pGetColNumbering() = Kratos::make_unique<DistributedNumbering<IndexType>>(kratos_comm,rA.local()->ncols);
99 const auto& comm_pattern = rA.cpat();
100 for(TIndexType
i=0;
i<rA.remote()->nnz; ++
i)
102 TIndexType
id = rA.remote()->col[
i];
103 TIndexType local_id = comm_pattern.local_index(
id);
104 pAconverted->GetOffDiagonalLocalIds()[id] = local_id;
105 rA.remote()->col[
i] = local_id;
109 pAconverted->GetOffDiagonalGlobalIds().resize(pAconverted->GetOffDiagonalLocalIds().size());
111 for(
auto item : pAconverted->GetOffDiagonalLocalIds())
113 pAconverted->GetOffDiagonalGlobalIds()[item.second] = item.first;
117 pAconverted->GetDiagonalBlock().SetColSize(rA.local()->ncols);
118 pAconverted->GetOffDiagonalBlock().SetColSize(pAconverted->GetOffDiagonalGlobalIds().size());
121 pAconverted->pGetDiagonalBlock() = std::move(AmgclCSRConversionUtilities::ConvertToCsrMatrix<TDataType,TIndexType>(*(rA.local().get())));
124 pAconverted->pGetOffDiagonalBlock() = std::move(AmgclCSRConversionUtilities::ConvertToCsrMatrix<TDataType,TIndexType>(*(rA.remote().get())));
127 pAconverted->pGetVectorImporter() = Kratos::make_unique<DistributedVectorImporter<TDataType,IndexType>>(
128 kratos_comm,pAconverted->GetOffDiagonalGlobalIds(),
129 pAconverted->GetColNumbering()
143 template<
class TDataType,
class TIndexType >
150 bool move_to_backend=
false;
152 const auto pAamgcl = ConvertToAmgcl<TDataType,TIndexType>(rA, offdiag_global_index2, move_to_backend);
154 const auto pAamgcl_transpose = transpose(*pAamgcl);
156 return ConvertToCsrMatrix<TDataType,TIndexType>(*pAamgcl_transpose, comm);
Definition: amgcl_distributed_csr_conversion_utilities.h:39
static DistributedCsrMatrix< TDataType, TIndexType >::Pointer Transpose(const DistributedCsrMatrix< TDataType, TIndexType > &rA)
Definition: amgcl_distributed_csr_conversion_utilities.h:144
static Kratos::shared_ptr< amgcl::mpi::distributed_matrix< amgcl::backend::builtin< double > > > ConvertToAmgcl(const DistributedCsrMatrix< TDataType, TIndexType > &rA, DenseVector< TIndexType > &global_index2, bool MoveToBackend=true)
Definition: amgcl_distributed_csr_conversion_utilities.h:47
static DistributedCsrMatrix< TDataType, TIndexType >::UniquePointer ConvertToCsrMatrix(amgcl::mpi::distributed_matrix< amgcl::backend::builtin< double >> &rA, const DataCommunicator &kratos_comm)
Definition: amgcl_distributed_csr_conversion_utilities.h:80
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
This class implements "serial" CSR matrix, including capabilities for FEM assembly.
Definition: distributed_csr_matrix.h:58
TIndexType local_size1() const
Definition: distributed_csr_matrix.h:314
CsrMatrix< TDataType, TIndexType > & GetOffDiagonalBlock()
Definition: distributed_csr_matrix.h:352
const DataCommunicator & GetComm() const
Definition: distributed_csr_matrix.h:329
DenseVector< TIndexType > GetOffDiagonalIndex2DataInGlobalNumbering() const
Definition: distributed_csr_matrix.h:431
CsrMatrix< TDataType, TIndexType > & GetDiagonalBlock()
Definition: distributed_csr_matrix.h:348
Definition: amatrix_interface.h:41
iterator begin()
Definition: amatrix_interface.h:241
static MPI_Comm GetMPICommunicator(const DataCommunicator &rDataCommunicator)
Get the underlying MPI_Comm instance.
Definition: mpi_data_communicator.cpp:431
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_ERROR
Definition: exception.h:161
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
integer i
Definition: TensorModule.f:17