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::lowerUpperSynchronize(
const CSRMatrix& ma,
166#ifdef ALIEN_USE_PERF_TIMER
167 SentryType s(m_timer,
"CSR-luSynchronize");
169 Internal::SimpleCSRMatrixMultT<Real>(ma).lowerUpperSynchronize(vr, vr);
172void SimpleCSRInternalLinearAlgebra::upperLowerSynchronize(
const CSRMatrix& ma,
175#ifdef ALIEN_USE_PERF_TIMER
176 SentryType s(m_timer,
"CSR-ulSynchronize");
178 Internal::SimpleCSRMatrixMultT<Real>(ma).upperLowerSynchronize(vr, vr);
181void SimpleCSRInternalLinearAlgebra::multDiag(
const CSRMatrix& ma, CSRVector& vr)
const
183#ifdef ALIEN_USE_PERF_TIMER
184 SentryType s(m_timer,
"CSR-MULTDIAG");
186 Internal::SimpleCSRMatrixMultT<Real>(ma).multDiag(vr);
189void SimpleCSRInternalLinearAlgebra::computeDiag(
const CSRMatrix& ma, CSRVector& vr)
const
191#ifdef ALIEN_USE_PERF_TIMER
192 SentryType s(m_timer,
"CSR-DIAG");
194 Internal::SimpleCSRMatrixMultT<Real>(ma).computeDiag(vr);
197void SimpleCSRInternalLinearAlgebra::multInvDiag(
const CSRMatrix& ma, CSRVector& vr)
const
199#ifdef ALIEN_USE_PERF_TIMER
200 SentryType s(m_timer,
"CSR-MULTINVDIAG");
202 Internal::SimpleCSRMatrixMultT<Real>(ma).multInvDiag(vr);
205void SimpleCSRInternalLinearAlgebra::computeInvDiag(
const CSRMatrix& ma, CSRVector& vr)
const
207#ifdef ALIEN_USE_PERF_TIMER
208 SentryType s(m_timer,
"CSR-INVDIAG");
210 Internal::SimpleCSRMatrixMultT<Real>(ma).computeInvDiag(vr);
215void SimpleCSRInternalLinearAlgebra::axpy(Real alpha,
const CSRVector& vx, CSRVector& vr)
const
217#ifdef ALIEN_USE_PERF_TIMER
218 SentryType s(m_timer,
"CSR-AXPY");
220 CBLASMPIKernel::axpy(vx.distribution(), alpha, vx, vr);
225void SimpleCSRInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
226 CSRVector& y ALIEN_UNUSED_PARAM,
227 const CSRVector& x ALIEN_UNUSED_PARAM)
const
229 throw NotImplementedException(
230 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
235void SimpleCSRInternalLinearAlgebra::copy(
const CSRVector& vx, CSRVector& vr)
const
237#ifdef ALIEN_USE_PERF_TIMER
238 SentryType s(m_timer,
"CSR-COPY");
240 CBLASMPIKernel::copy(vx.distribution(), vx, vr);
243void SimpleCSRInternalLinearAlgebra::axpy(Real alpha,
247 Integer stride_r)
const
249#ifdef ALIEN_USE_PERF_TIMER
250 SentryType s(m_timer,
"CSR-AXPY");
252 CBLASMPIKernel::axpy(vx.distribution(), alpha, vx, stride_x, vr, stride_r);
257void SimpleCSRInternalLinearAlgebra::aypx([[maybe_unused]] Real alpha,
258 [[maybe_unused]] CSRVector& y,
259 [[maybe_unused]] Integer stride_y,
260 [[maybe_unused]]
const CSRVector& x,
261 [[maybe_unused]] Integer stride_x)
const
263 throw NotImplementedException(
264 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
267void SimpleCSRInternalLinearAlgebra::copy(
const Vector& vx,
270 Integer stride_r)
const
272 CBLASMPIKernel::copy(vx.distribution(), vx, stride_x, vr, stride_r);
276Real SimpleCSRInternalLinearAlgebra::dot(
const CSRVector& vx,
const CSRVector& vy)
const
278#ifdef ALIEN_USE_PERF_TIMER
279 SentryType s(m_timer,
"CSR-DOT");
281 return CBLASMPIKernel::dot(vx.distribution(), vx, vy);
284void SimpleCSRInternalLinearAlgebra::dot(
const CSRVector& vx,
286 SimpleCSRInternalLinearAlgebra::FutureType& res)
const
288#ifdef ALIEN_USE_PERF_TIMER
289 SentryType s(m_timer,
"CSR-DOT-F");
291 res() = CBLASMPIKernel::dot(vx.distribution(), vx, vy);
296void SimpleCSRInternalLinearAlgebra::scal(Real alpha, CSRVector& vx)
const
298#ifdef ALIEN_USE_PERF_TIMER
299 SentryType s(m_timer,
"CSR-SCAL");
301 CBLASMPIKernel::scal(vx.distribution(), alpha, vx);
304void SimpleCSRInternalLinearAlgebra::scal(CSRVector
const& vx, CSRMatrix& a)
const
306#ifdef ALIEN_USE_PERF_TIMER
307 SentryType s(m_timer,
"CSR-SCAL");
312void SimpleCSRInternalLinearAlgebra::diagonal(
313const CSRMatrix& a, CSRVector& diag)
const
315#ifdef ALIEN_USE_PERF_TIMER
316 SentryType s(m_timer,
"CSR-DIAG");
318 Internal::SimpleCSRMatrixMultT<Real>(a).computeDiag(diag);
321void SimpleCSRInternalLinearAlgebra::reciprocal(CSRVector& x ALIEN_UNUSED_PARAM)
const
323 throw NotImplementedException(
324 A_FUNCINFO,
"SimpleCSRLinearAlgebra::reciprocal not implemented");
327void SimpleCSRInternalLinearAlgebra::pointwiseMult(
const CSRVector& vx,
331#ifdef ALIEN_USE_PERF_TIMER
332 SentryType s(m_timer,
"CSR-XYZ");
334 CBLASMPIKernel::pointwiseMult(vx.distribution(), vx, vy, vz);
337void SimpleCSRInternalLinearAlgebra::assign(CSRVector& vx, Real alpha)
const
339#ifdef ALIEN_USE_PERF_TIMER
340 SentryType s(m_timer,
"CSR-ASSIGN");
342 CBLASMPIKernel::assign(vx.distribution(), alpha, vx);
345Integer SimpleCSRInternalLinearAlgebra::computeCxr(
const CSRMatrix& a, CSRMatrix& cxr_a)
const
347 auto block_size = a.blockSize() ;
348 cxr_a.setBlockSize(1) ;
353Integer SimpleCSRInternalLinearAlgebra::computeCxr(
const CSRMatrix& a,
const CSRVector& diag, CSRMatrix& cxr_a)
const
355 auto block_size = a.blockSize() ;
356 cxr_a.setBlockSize(1) ;
358 cxr_a.scal(diag.data());
363SimpleCSRInternalLinearAlgebraExpr::SimpleCSRInternalLinearAlgebraExpr()
364: IInternalLinearAlgebraExpr<CSRMatrix, CSRVector>()
369SimpleCSRInternalLinearAlgebraExpr::~SimpleCSRInternalLinearAlgebraExpr() {}
374Real SimpleCSRInternalLinearAlgebraExpr::norm0(
const CSRVector& vx)
const
376 return CBLASMPIKernel::nrm0(vx.distribution(), vx);
381Real SimpleCSRInternalLinearAlgebraExpr::norm1(
const CSRVector& vx)
const
383 return CBLASMPIKernel::nrm1(vx.distribution(), vx);
388Real SimpleCSRInternalLinearAlgebraExpr::norm2(
const CSRVector& vx)
const
390 return CBLASMPIKernel::nrm2(vx.distribution(), vx);
395Real SimpleCSRInternalLinearAlgebraExpr::normInf(
const CSRVector& vx)
const
397 return CBLASMPIKernel::nrmInf(vx.distribution(), vx);
402Real SimpleCSRInternalLinearAlgebraExpr::norm2(
const CSRMatrix& mx)
const
404#ifdef ALIEN_USE_PERF_TIMER
405 SentryType s(m_timer,
"MATRIX-CSR-NORM2");
407 return CBLASMPIKernel::matrix_nrm2(mx.distribution(), mx);
411void SimpleCSRInternalLinearAlgebraExpr::mult(
412const CSRMatrix& ma,
const CSRVector& vx, CSRVector& vr)
const
414 Internal::SimpleCSRMatrixMultT<Real>(ma).mult(vx, vr);
417void SimpleCSRInternalLinearAlgebraExpr::mult(
418const CSRMatrix& ma,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
420 Internal::SimpleCSRMatrixMultT<Real>(ma).mult(vx, vr);
425void SimpleCSRInternalLinearAlgebraExpr::axpy(Real alpha,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
427 cblas::axpy(vx.size(), alpha, dataPtr(vx), 1, dataPtr(vr), 1);
430void SimpleCSRInternalLinearAlgebraExpr::axpy(Real alpha,
const CSRVector& vx, CSRVector& vr)
const
432 CBLASMPIKernel::axpy(vx.distribution(), alpha, vx, vr);
437void SimpleCSRInternalLinearAlgebraExpr::aypx(Real alpha, UniqueArray<Real>& vy, UniqueArray<Real>
const& vx)
const
439 throw NotImplementedException(
440 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
443void SimpleCSRInternalLinearAlgebraExpr::aypx(Real alpha ALIEN_UNUSED_PARAM,
444 CSRVector& y ALIEN_UNUSED_PARAM,
const CSRVector& x ALIEN_UNUSED_PARAM)
const
446 throw NotImplementedException(
447 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
452void SimpleCSRInternalLinearAlgebraExpr::copy(
453const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
455 cblas::copy(vx.size(), dataPtr(vx), 1, dataPtr(vr), 1);
458void SimpleCSRInternalLinearAlgebraExpr::copy(
const CSRVector& vx, CSRVector& vr)
const
460 CBLASMPIKernel::copy(vx.distribution(), vx, vr);
463void SimpleCSRInternalLinearAlgebraExpr::copy(
const CSRMatrix& ma, CSRMatrix& mr)
const
465#ifdef ALIEN_USE_PERF_TIMER
466 SentryType s(m_timer,
"MATRIX-CSR-COPY");
471void SimpleCSRInternalLinearAlgebraExpr::add(
const CSRMatrix& ma, CSRMatrix& mr)
const
473#ifdef ALIEN_USE_PERF_TIMER
474 SentryType s(m_timer,
"MATRIX-CSR-ADD");
477 cblas::axpy(mr.getProfile().getNnz(), 1, (CSRMatrix::ValueType*)ma.data(), 1, mr.data(), 1);
480void SimpleCSRInternalLinearAlgebraExpr::scal(Real alpha, CSRMatrix& mr)
const
482#ifdef ALIEN_USE_PERF_TIMER
483 SentryType s(m_timer,
"MATRIX-CSR-SCAL");
486 cblas::scal(mr.getProfile().getNnz(), alpha, mr.data(), 1);
491Real SimpleCSRInternalLinearAlgebraExpr::dot(
492Integer local_size,
const UniqueArray<Real>& vx,
const UniqueArray<Real>& vy)
const
494 return cblas::dot(local_size, dataPtr(vx), 1, dataPtr(vy), 1);
497Real SimpleCSRInternalLinearAlgebraExpr::dot(
const CSRVector& vx,
const CSRVector& vy)
const
499 return CBLASMPIKernel::dot(vx.distribution(), vx, vy);
503void SimpleCSRInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, UniqueArray<Real>& x ALIEN_UNUSED_PARAM)
const
505 throw NotImplementedException(
506 A_FUNCINFO,
"SimpleCSRLinearAlgebra::scal not implemented");
509void SimpleCSRInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, CSRVector& x ALIEN_UNUSED_PARAM)
const
511 throw NotImplementedException(
512 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
515void SimpleCSRInternalLinearAlgebraExpr::diagonal(
516const CSRMatrix& a ALIEN_UNUSED_PARAM, CSRVector& x ALIEN_UNUSED_PARAM)
const
518 throw NotImplementedException(
519 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
522void SimpleCSRInternalLinearAlgebraExpr::reciprocal(CSRVector& x ALIEN_UNUSED_PARAM)
const
524 throw NotImplementedException(
525 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
528void SimpleCSRInternalLinearAlgebraExpr::pointwiseMult(
const CSRVector& x ALIEN_UNUSED_PARAM,
529 const CSRVector& y ALIEN_UNUSED_PARAM, CSRVector& w ALIEN_UNUSED_PARAM)
const
531 throw NotImplementedException(
532 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 --