12#include "SimpleCSRInternalLinearAlgebra.h"
13#include <alien/utils/Precomp.h>
15#include <arccore/base/NotImplementedException.h>
16#include <arccore/base/TraceInfo.h>
21#include "CBLASMPIKernel.h"
22#include "SimpleCSRMatrixMult.h"
29using namespace Arccore;
35SimpleCSRInternalLinearAlgebraFactory()
41SimpleCSRInternalLinearAlgebraExprFactory()
48namespace Internal = SimpleCSRInternal;
52SimpleCSRInternalLinearAlgebra::SimpleCSRInternalLinearAlgebra()
58SimpleCSRInternalLinearAlgebra::~SimpleCSRInternalLinearAlgebra()
60#ifdef ALIEN_USE_PERF_TIMER
61 m_timer.printInfo(
"SIMPLECSR-ALGEBRA");
67SimpleCSRInternalLinearAlgebra::ResourceType
68SimpleCSRInternalLinearAlgebra::resource(Matrix
const& A)
70 return std::make_tuple(&A.distribution().rowDistribution(),A.blockSize());
73void SimpleCSRInternalLinearAlgebra::allocate(ResourceType resource, Vector& v)
75 v.init(*std::get<0>(resource),std::get<1>(resource),
true);
78void SimpleCSRInternalLinearAlgebra::free(Vector& v)
83Real SimpleCSRInternalLinearAlgebra::norm0(
const CSRVector& vx)
const
85#ifdef ALIEN_USE_PERF_TIMER
86 SentryType s(m_timer,
"CSR-NORM0");
89 return CBLASMPIKernel::nrm0(vx.distribution(), vx);
94Real SimpleCSRInternalLinearAlgebra::norm1(
const CSRVector& vx)
const
96#ifdef ALIEN_USE_PERF_TIMER
97 SentryType s(m_timer,
"CSR-NORM1");
100 return CBLASMPIKernel::nrm1(vx.distribution(), vx);
105Real SimpleCSRInternalLinearAlgebra::norm2(
const CSRVector& vx)
const
107#ifdef ALIEN_USE_PERF_TIMER
108 SentryType s(m_timer,
"CSR-NORM2");
110 return CBLASMPIKernel::nrm2(vx.distribution(), vx);
115Real SimpleCSRInternalLinearAlgebra::normInf(
const CSRVector& vx)
const
117#ifdef ALIEN_USE_PERF_TIMER
118 SentryType s(m_timer,
"CSR-NORMINF");
120 return CBLASMPIKernel::nrmInf(vx.distribution(), vx);
125void SimpleCSRInternalLinearAlgebra::synchronize(
const CSRMatrix& ma,
128 Internal::SimpleCSRMatrixMultT<Real>(ma).synchronize(vx);
131void SimpleCSRInternalLinearAlgebra::mult(
const CSRMatrix& ma,
135#ifdef ALIEN_USE_PERF_TIMER
136 SentryType s(m_timer,
"CSR-SPMV");
138 Internal::SimpleCSRMatrixMultT<Real>(ma).mult(vx, vr);
141void SimpleCSRInternalLinearAlgebra::addLMult(Real alpha,
146#ifdef ALIEN_USE_PERF_TIMER
147 SentryType s(m_timer,
"CSR-AddLMult");
149 Internal::SimpleCSRMatrixMultT<Real>(ma).addLMult(alpha, vx, vr);
152void SimpleCSRInternalLinearAlgebra::addUMult(Real alpha,
157#ifdef ALIEN_USE_PERF_TIMER
158 SentryType s(m_timer,
"CSR-AddUMult");
160 Internal::SimpleCSRMatrixMultT<Real>(ma).addUMult(alpha, vx, vr);
163void SimpleCSRInternalLinearAlgebra::multDiag(
const CSRMatrix& ma, CSRVector& vr)
const
165#ifdef ALIEN_USE_PERF_TIMER
166 SentryType s(m_timer,
"CSR-MULTDIAG");
168 Internal::SimpleCSRMatrixMultT<Real>(ma).multDiag(vr);
171void SimpleCSRInternalLinearAlgebra::computeDiag(
const CSRMatrix& ma, CSRVector& vr)
const
173#ifdef ALIEN_USE_PERF_TIMER
174 SentryType s(m_timer,
"CSR-DIAG");
176 Internal::SimpleCSRMatrixMultT<Real>(ma).computeDiag(vr);
179void SimpleCSRInternalLinearAlgebra::multInvDiag(
const CSRMatrix& ma, CSRVector& vr)
const
181#ifdef ALIEN_USE_PERF_TIMER
182 SentryType s(m_timer,
"CSR-MULTINVDIAG");
184 Internal::SimpleCSRMatrixMultT<Real>(ma).multInvDiag(vr);
187void SimpleCSRInternalLinearAlgebra::computeInvDiag(
const CSRMatrix& ma, CSRVector& vr)
const
189#ifdef ALIEN_USE_PERF_TIMER
190 SentryType s(m_timer,
"CSR-INVDIAG");
192 Internal::SimpleCSRMatrixMultT<Real>(ma).computeInvDiag(vr);
197void SimpleCSRInternalLinearAlgebra::axpy(Real alpha,
const CSRVector& vx, CSRVector& vr)
const
199#ifdef ALIEN_USE_PERF_TIMER
200 SentryType s(m_timer,
"CSR-AXPY");
202 CBLASMPIKernel::axpy(vx.distribution(), alpha, vx, vr);
207void SimpleCSRInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
208 CSRVector& y ALIEN_UNUSED_PARAM,
209 const CSRVector& x ALIEN_UNUSED_PARAM)
const
211 throw NotImplementedException(
212 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
217void SimpleCSRInternalLinearAlgebra::copy(
const CSRVector& vx, CSRVector& vr)
const
219#ifdef ALIEN_USE_PERF_TIMER
220 SentryType s(m_timer,
"CSR-COPY");
222 CBLASMPIKernel::copy(vx.distribution(), vx, vr);
225void SimpleCSRInternalLinearAlgebra::axpy(Real alpha,
229 Integer stride_r)
const
231#ifdef ALIEN_USE_PERF_TIMER
232 SentryType s(m_timer,
"CSR-AXPY");
234 CBLASMPIKernel::axpy(vx.distribution(), alpha, vx, stride_x, vr, stride_r);
239void SimpleCSRInternalLinearAlgebra::aypx([[maybe_unused]] Real alpha,
240 [[maybe_unused]] CSRVector& y,
241 [[maybe_unused]] Integer stride_y,
242 [[maybe_unused]]
const CSRVector& x,
243 [[maybe_unused]] Integer stride_x)
const
245 throw NotImplementedException(
246 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
249void SimpleCSRInternalLinearAlgebra::copy(
const Vector& vx,
252 Integer stride_r)
const
254 CBLASMPIKernel::copy(vx.distribution(), vx, stride_x, vr, stride_r);
258Real SimpleCSRInternalLinearAlgebra::dot(
const CSRVector& vx,
const CSRVector& vy)
const
260#ifdef ALIEN_USE_PERF_TIMER
261 SentryType s(m_timer,
"CSR-DOT");
263 return CBLASMPIKernel::dot(vx.distribution(), vx, vy);
266void SimpleCSRInternalLinearAlgebra::dot(
const CSRVector& vx,
268 SimpleCSRInternalLinearAlgebra::FutureType& res)
const
270#ifdef ALIEN_USE_PERF_TIMER
271 SentryType s(m_timer,
"CSR-DOT-F");
273 res() = CBLASMPIKernel::dot(vx.distribution(), vx, vy);
278void SimpleCSRInternalLinearAlgebra::scal(Real alpha, CSRVector& vx)
const
280#ifdef ALIEN_USE_PERF_TIMER
281 SentryType s(m_timer,
"CSR-SCAL");
283 CBLASMPIKernel::scal(vx.distribution(), alpha, vx);
286void SimpleCSRInternalLinearAlgebra::scal(CSRVector
const& vx, CSRMatrix& a)
const
288#ifdef ALIEN_USE_PERF_TIMER
289 SentryType s(m_timer,
"CSR-SCAL");
294void SimpleCSRInternalLinearAlgebra::diagonal(
295const CSRMatrix& a, CSRVector& diag)
const
297#ifdef ALIEN_USE_PERF_TIMER
298 SentryType s(m_timer,
"CSR-DIAG");
300 Internal::SimpleCSRMatrixMultT<Real>(a).computeDiag(diag);
303void SimpleCSRInternalLinearAlgebra::reciprocal(CSRVector& x ALIEN_UNUSED_PARAM)
const
305 throw NotImplementedException(
306 A_FUNCINFO,
"SimpleCSRLinearAlgebra::reciprocal not implemented");
309void SimpleCSRInternalLinearAlgebra::pointwiseMult(
const CSRVector& vx,
313#ifdef ALIEN_USE_PERF_TIMER
314 SentryType s(m_timer,
"CSR-XYZ");
316 CBLASMPIKernel::pointwiseMult(vx.distribution(), vx, vy, vz);
319void SimpleCSRInternalLinearAlgebra::assign(CSRVector& vx, Real alpha)
const
321#ifdef ALIEN_USE_PERF_TIMER
322 SentryType s(m_timer,
"CSR-ASSIGN");
324 CBLASMPIKernel::assign(vx.distribution(), alpha, vx);
327Integer SimpleCSRInternalLinearAlgebra::computeCxr(
const CSRMatrix& a, CSRMatrix& cxr_a)
const
329 auto block_size = a.blockSize() ;
330 cxr_a.setBlockSize(1) ;
335Integer SimpleCSRInternalLinearAlgebra::computeCxr(
const CSRMatrix& a,
const CSRVector& diag, CSRMatrix& cxr_a)
const
337 auto block_size = a.blockSize() ;
338 cxr_a.setBlockSize(1) ;
340 cxr_a.scal(diag.data());
345SimpleCSRInternalLinearAlgebraExpr::SimpleCSRInternalLinearAlgebraExpr()
346: IInternalLinearAlgebraExpr<CSRMatrix, CSRVector>()
351SimpleCSRInternalLinearAlgebraExpr::~SimpleCSRInternalLinearAlgebraExpr() {}
356Real SimpleCSRInternalLinearAlgebraExpr::norm0(
const CSRVector& vx)
const
358 return CBLASMPIKernel::nrm0(vx.distribution(), vx);
363Real SimpleCSRInternalLinearAlgebraExpr::norm1(
const CSRVector& vx)
const
365 return CBLASMPIKernel::nrm1(vx.distribution(), vx);
370Real SimpleCSRInternalLinearAlgebraExpr::norm2(
const CSRVector& vx)
const
372 return CBLASMPIKernel::nrm2(vx.distribution(), vx);
377Real SimpleCSRInternalLinearAlgebraExpr::normInf(
const CSRVector& vx)
const
379 return CBLASMPIKernel::nrmInf(vx.distribution(), vx);
384Real SimpleCSRInternalLinearAlgebraExpr::norm2(
const CSRMatrix& mx)
const
386#ifdef ALIEN_USE_PERF_TIMER
387 SentryType s(m_timer,
"MATRIX-CSR-NORM2");
389 return CBLASMPIKernel::matrix_nrm2(mx.distribution(), mx);
393void SimpleCSRInternalLinearAlgebraExpr::mult(
394const CSRMatrix& ma,
const CSRVector& vx, CSRVector& vr)
const
396 Internal::SimpleCSRMatrixMultT<Real>(ma).mult(vx, vr);
399void SimpleCSRInternalLinearAlgebraExpr::mult(
400const CSRMatrix& ma,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
402 Internal::SimpleCSRMatrixMultT<Real>(ma).mult(vx, vr);
407void SimpleCSRInternalLinearAlgebraExpr::axpy(Real alpha,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
409 cblas::axpy(vx.size(), alpha, dataPtr(vx), 1, dataPtr(vr), 1);
412void SimpleCSRInternalLinearAlgebraExpr::axpy(Real alpha,
const CSRVector& vx, CSRVector& vr)
const
414 CBLASMPIKernel::axpy(vx.distribution(), alpha, vx, vr);
419void SimpleCSRInternalLinearAlgebraExpr::aypx(Real alpha, UniqueArray<Real>& vy, UniqueArray<Real>
const& vx)
const
421 throw NotImplementedException(
422 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
425void SimpleCSRInternalLinearAlgebraExpr::aypx(Real alpha ALIEN_UNUSED_PARAM,
426 CSRVector& y ALIEN_UNUSED_PARAM,
const CSRVector& x ALIEN_UNUSED_PARAM)
const
428 throw NotImplementedException(
429 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
434void SimpleCSRInternalLinearAlgebraExpr::copy(
435const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
437 cblas::copy(vx.size(), dataPtr(vx), 1, dataPtr(vr), 1);
440void SimpleCSRInternalLinearAlgebraExpr::copy(
const CSRVector& vx, CSRVector& vr)
const
442 CBLASMPIKernel::copy(vx.distribution(), vx, vr);
445void SimpleCSRInternalLinearAlgebraExpr::copy(
const CSRMatrix& ma, CSRMatrix& mr)
const
447#ifdef ALIEN_USE_PERF_TIMER
448 SentryType s(m_timer,
"MATRIX-CSR-COPY");
453void SimpleCSRInternalLinearAlgebraExpr::add(
const CSRMatrix& ma, CSRMatrix& mr)
const
455#ifdef ALIEN_USE_PERF_TIMER
456 SentryType s(m_timer,
"MATRIX-CSR-ADD");
459 cblas::axpy(mr.getProfile().getNnz(), 1, (CSRMatrix::ValueType*)ma.data(), 1, mr.data(), 1);
462void SimpleCSRInternalLinearAlgebraExpr::scal(Real alpha, CSRMatrix& mr)
const
464#ifdef ALIEN_USE_PERF_TIMER
465 SentryType s(m_timer,
"MATRIX-CSR-SCAL");
468 cblas::scal(mr.getProfile().getNnz(), alpha, mr.data(), 1);
473Real SimpleCSRInternalLinearAlgebraExpr::dot(
474Integer local_size,
const UniqueArray<Real>& vx,
const UniqueArray<Real>& vy)
const
476 return cblas::dot(local_size, dataPtr(vx), 1, dataPtr(vy), 1);
479Real SimpleCSRInternalLinearAlgebraExpr::dot(
const CSRVector& vx,
const CSRVector& vy)
const
481 return CBLASMPIKernel::dot(vx.distribution(), vx, vy);
485void SimpleCSRInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, UniqueArray<Real>& x ALIEN_UNUSED_PARAM)
const
487 throw NotImplementedException(
488 A_FUNCINFO,
"SimpleCSRLinearAlgebra::scal not implemented");
491void SimpleCSRInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, CSRVector& x ALIEN_UNUSED_PARAM)
const
493 throw NotImplementedException(
494 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
497void SimpleCSRInternalLinearAlgebraExpr::diagonal(
498const CSRMatrix& a ALIEN_UNUSED_PARAM, CSRVector& x ALIEN_UNUSED_PARAM)
const
500 throw NotImplementedException(
501 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
504void SimpleCSRInternalLinearAlgebraExpr::reciprocal(CSRVector& x ALIEN_UNUSED_PARAM)
const
506 throw NotImplementedException(
507 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
510void SimpleCSRInternalLinearAlgebraExpr::pointwiseMult(
const CSRVector& x ALIEN_UNUSED_PARAM,
511 const CSRVector& y ALIEN_UNUSED_PARAM, CSRVector& w ALIEN_UNUSED_PARAM)
const
513 throw NotImplementedException(
514 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
Internal linear algebra interface.
Internal linear algebra interface.
Linear algebra interface.
Linear algebra interface.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --