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.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);
153void SimpleCSRInternalLinearAlgebra::endDistAddLMult(Real alpha,
158#ifdef ALIEN_USE_PERF_TIMER
159 SentryType s(m_timer,
"CSR-AddLMult");
161 Internal::SimpleCSRMatrixMultT<Real>(ma).endDistAddLMult(alpha, vx, vr);
164void SimpleCSRInternalLinearAlgebra::addUMult(Real alpha,
169#ifdef ALIEN_USE_PERF_TIMER
170 SentryType s(m_timer,
"CSR-AddUMult");
172 Internal::SimpleCSRMatrixMultT<Real>(ma).addUMult(alpha, vx, vr);
175void SimpleCSRInternalLinearAlgebra::endDistAddUMult(Real alpha,
180#ifdef ALIEN_USE_PERF_TIMER
181 SentryType s(m_timer,
"CSR-endDistAddUMult");
183 Internal::SimpleCSRMatrixMultT<Real>(ma).endDistAddUMult(alpha, vx, vr);
186void SimpleCSRInternalLinearAlgebra::lowerUpperSynchronize(
const CSRMatrix& ma,
189#ifdef ALIEN_USE_PERF_TIMER
190 SentryType s(m_timer,
"CSR-luSynchronize");
192 Internal::SimpleCSRMatrixMultT<Real>(ma).lowerUpperSynchronize(vr, vr);
195void SimpleCSRInternalLinearAlgebra::upperLowerSynchronize(
const CSRMatrix& ma,
198#ifdef ALIEN_USE_PERF_TIMER
199 SentryType s(m_timer,
"CSR-ulSynchronize");
201 Internal::SimpleCSRMatrixMultT<Real>(ma).upperLowerSynchronize(vr, vr);
204void SimpleCSRInternalLinearAlgebra::multDiag(
const CSRMatrix& ma, CSRVector& vr)
const
206#ifdef ALIEN_USE_PERF_TIMER
207 SentryType s(m_timer,
"CSR-MULTDIAG");
209 Internal::SimpleCSRMatrixMultT<Real>(ma).multDiag(vr);
212void SimpleCSRInternalLinearAlgebra::computeDiag(
const CSRMatrix& ma, CSRVector& vr)
const
214#ifdef ALIEN_USE_PERF_TIMER
215 SentryType s(m_timer,
"CSR-DIAG");
217 Internal::SimpleCSRMatrixMultT<Real>(ma).computeDiag(vr);
220void SimpleCSRInternalLinearAlgebra::multInvDiag(
const CSRMatrix& ma, CSRVector& vr)
const
222#ifdef ALIEN_USE_PERF_TIMER
223 SentryType s(m_timer,
"CSR-MULTINVDIAG");
225 Internal::SimpleCSRMatrixMultT<Real>(ma).multInvDiag(vr);
228void SimpleCSRInternalLinearAlgebra::computeInvDiag(
const CSRMatrix& ma, CSRVector& vr)
const
230#ifdef ALIEN_USE_PERF_TIMER
231 SentryType s(m_timer,
"CSR-INVDIAG");
233 Internal::SimpleCSRMatrixMultT<Real>(ma).computeInvDiag(vr);
238void SimpleCSRInternalLinearAlgebra::axpy(Real alpha,
const CSRVector& vx, CSRVector& vr)
const
240#ifdef ALIEN_USE_PERF_TIMER
241 SentryType s(m_timer,
"CSR-AXPY");
243 CBLASMPIKernel::axpy(vx.distribution(), alpha, vx, vr);
248void SimpleCSRInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
249 CSRVector& y ALIEN_UNUSED_PARAM,
250 const CSRVector& x ALIEN_UNUSED_PARAM)
const
252 throw NotImplementedException(
253 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
258void SimpleCSRInternalLinearAlgebra::copy(
const CSRVector& vx, CSRVector& vr)
const
260#ifdef ALIEN_USE_PERF_TIMER
261 SentryType s(m_timer,
"CSR-COPY");
263 CBLASMPIKernel::copy(vx.distribution(), vx, vr);
266void SimpleCSRInternalLinearAlgebra::axpy(Real alpha,
270 Integer stride_r)
const
272#ifdef ALIEN_USE_PERF_TIMER
273 SentryType s(m_timer,
"CSR-AXPY");
275 CBLASMPIKernel::axpy(vx.distribution(), alpha, vx, stride_x, vr, stride_r);
279void SimpleCSRInternalLinearAlgebra::axpy(Real alpha,
282 ConstArrayView<Integer> strides_r)
const
284#ifdef ALIEN_USE_PERF_TIMER
285 SentryType s(m_timer,
"CSR-AXPY");
287 CBLASMPIKernel::axpy(vr.distribution(), alpha, vx, vr, strides_r);
291void SimpleCSRInternalLinearAlgebra::aypx([[maybe_unused]] Real alpha,
292 [[maybe_unused]] CSRVector& y,
293 [[maybe_unused]] Integer stride_y,
294 [[maybe_unused]]
const CSRVector& x,
295 [[maybe_unused]] Integer stride_x)
const
297 throw NotImplementedException(
298 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
301void SimpleCSRInternalLinearAlgebra::copy(
const Vector& vx,
304 Integer stride_r)
const
306#ifdef ALIEN_USE_PERF_TIMER
307 SentryType s(m_timer,
"CSR-COPY");
309 CBLASMPIKernel::copy(vx.distribution(), vx, stride_x, vr, stride_r);
313void SimpleCSRInternalLinearAlgebra::copy(
const Vector& vx,
314 ConstArrayView<Integer> strides_x,
317#ifdef ALIEN_USE_PERF_TIMER
318 SentryType s(m_timer,
"CSR-COPY");
320 CBLASMPIKernel::copy(vr.distribution(), vx, strides_x, vr);
323void SimpleCSRInternalLinearAlgebra::copy(
const Vector& vx,
325 ConstArrayView<Integer> strides_r)
const
327#ifdef ALIEN_USE_PERF_TIMER
328 SentryType s(m_timer,
"CSR-COPY");
330 CBLASMPIKernel::copy(vr.distribution(), vx, vr, strides_r);
334Real SimpleCSRInternalLinearAlgebra::dot(
const CSRVector& vx,
const CSRVector& vy)
const
336#ifdef ALIEN_USE_PERF_TIMER
337 SentryType s(m_timer,
"CSR-DOT");
339 return CBLASMPIKernel::dot(vx.distribution(), vx, vy);
342void SimpleCSRInternalLinearAlgebra::dot(
const CSRVector& vx,
344 SimpleCSRInternalLinearAlgebra::FutureType& res)
const
346#ifdef ALIEN_USE_PERF_TIMER
347 SentryType s(m_timer,
"CSR-DOT-F");
349 res() = CBLASMPIKernel::dot(vx.distribution(), vx, vy);
354void SimpleCSRInternalLinearAlgebra::scal(Real alpha, CSRVector& vx)
const
356#ifdef ALIEN_USE_PERF_TIMER
357 SentryType s(m_timer,
"CSR-SCAL");
359 CBLASMPIKernel::scal(vx.distribution(), alpha, vx);
362void SimpleCSRInternalLinearAlgebra::scal(CSRVector
const& vx, CSRMatrix& a)
const
364#ifdef ALIEN_USE_PERF_TIMER
365 SentryType s(m_timer,
"CSR-SCAL");
370void SimpleCSRInternalLinearAlgebra::diagonal(
371const CSRMatrix& a, CSRVector& diag)
const
373#ifdef ALIEN_USE_PERF_TIMER
374 SentryType s(m_timer,
"CSR-DIAG");
376 Internal::SimpleCSRMatrixMultT<Real>(a).computeDiag(diag);
379void SimpleCSRInternalLinearAlgebra::reciprocal(CSRVector& x ALIEN_UNUSED_PARAM)
const
381 throw NotImplementedException(
382 A_FUNCINFO,
"SimpleCSRLinearAlgebra::reciprocal not implemented");
385void SimpleCSRInternalLinearAlgebra::pointwiseMult(
const CSRVector& vx,
389#ifdef ALIEN_USE_PERF_TIMER
390 SentryType s(m_timer,
"CSR-XYZ");
392 CBLASMPIKernel::pointwiseMult(vx.distribution(), vx, vy, vz);
395void SimpleCSRInternalLinearAlgebra::assign(CSRVector& vx, Real alpha)
const
397#ifdef ALIEN_USE_PERF_TIMER
398 SentryType s(m_timer,
"CSR-ASSIGN");
400 CBLASMPIKernel::assign(vx.distribution(), alpha, vx);
403Integer SimpleCSRInternalLinearAlgebra::computeCxr(
const CSRMatrix& a, CSRMatrix& cxr_a)
const
405 auto block_size = a.blockSize() ;
406 cxr_a.setBlockSize(1) ;
411Integer SimpleCSRInternalLinearAlgebra::computeCxr(
const CSRMatrix& a,
413 UniqueArray<Integer>& strides)
const
415 auto block_size = a.blockSize() ;
416 cxr_a.setBlockSize(1) ;
418 const ISpace& space = a.rowSpace();
419 const MatrixDistribution& dist = a.distribution();
421 bool elliptic_split_tag_found = false ;
423 Integer domain_offset = dist.rowOffset();
424 Integer local_size = dist.localRowSize();
426 UniqueArray<Integer> filter(local_size);
428 for (Integer i = 0; i < space.nbField(); ++i)
430 const UniqueArray<Integer>& indices = space.field(i);
431 if (space.fieldLabel(i) ==
"Elliptic" and not indices.empty())
433 elliptic_split_tag_found =
true;
434 for (Integer j = 0; j < indices.size(); ++j)
436 const Integer index = indices[j];
438 filter[index - domain_offset] = 1 ;
442 cxr_a.copy(a,filter,strides) ;
447Integer SimpleCSRInternalLinearAlgebra::computeCxr(
const CSRMatrix& a,
const CSRVector& diag, CSRMatrix& cxr_a)
const
449 auto block_size = a.blockSize() ;
450 cxr_a.setBlockSize(1) ;
452 cxr_a.scal(diag.data());
457SimpleCSRInternalLinearAlgebraExpr::SimpleCSRInternalLinearAlgebraExpr()
458: IInternalLinearAlgebraExpr<CSRMatrix, CSRVector>()
463SimpleCSRInternalLinearAlgebraExpr::~SimpleCSRInternalLinearAlgebraExpr() {}
468Real SimpleCSRInternalLinearAlgebraExpr::norm0(
const CSRVector& vx)
const
470 return CBLASMPIKernel::nrm0(vx.distribution(), vx);
475Real SimpleCSRInternalLinearAlgebraExpr::norm1(
const CSRVector& vx)
const
477 return CBLASMPIKernel::nrm1(vx.distribution(), vx);
482Real SimpleCSRInternalLinearAlgebraExpr::norm2(
const CSRVector& vx)
const
484 return CBLASMPIKernel::nrm2(vx.distribution(), vx);
489Real SimpleCSRInternalLinearAlgebraExpr::normInf(
const CSRVector& vx)
const
491 return CBLASMPIKernel::nrmInf(vx.distribution(), vx);
496Real SimpleCSRInternalLinearAlgebraExpr::norm2(
const CSRMatrix& mx)
const
498#ifdef ALIEN_USE_PERF_TIMER
499 SentryType s(m_timer,
"MATRIX-CSR-NORM2");
501 return CBLASMPIKernel::matrix_nrm2(mx.distribution(), mx);
505void SimpleCSRInternalLinearAlgebraExpr::mult(
506const CSRMatrix& ma,
const CSRVector& vx, CSRVector& vr)
const
508 Internal::SimpleCSRMatrixMultT<Real>(ma).mult(vx, vr);
511void SimpleCSRInternalLinearAlgebraExpr::mult(
512const CSRMatrix& ma,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
514 Internal::SimpleCSRMatrixMultT<Real>(ma).mult(vx, vr);
519void SimpleCSRInternalLinearAlgebraExpr::axpy(Real alpha,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
521 cblas::axpy(vx.size(), alpha, dataPtr(vx), 1, dataPtr(vr), 1);
524void SimpleCSRInternalLinearAlgebraExpr::axpy(Real alpha,
const CSRVector& vx, CSRVector& vr)
const
526 CBLASMPIKernel::axpy(vx.distribution(), alpha, vx, vr);
531void SimpleCSRInternalLinearAlgebraExpr::aypx(Real alpha, UniqueArray<Real>& vy, UniqueArray<Real>
const& vx)
const
533 throw NotImplementedException(
534 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
537void SimpleCSRInternalLinearAlgebraExpr::aypx(Real alpha ALIEN_UNUSED_PARAM,
538 CSRVector& y ALIEN_UNUSED_PARAM,
const CSRVector& x ALIEN_UNUSED_PARAM)
const
540 throw NotImplementedException(
541 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
546void SimpleCSRInternalLinearAlgebraExpr::copy(
547const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
549 cblas::copy(vx.size(), dataPtr(vx), 1, dataPtr(vr), 1);
552void SimpleCSRInternalLinearAlgebraExpr::copy(
const CSRVector& vx, CSRVector& vr)
const
554 CBLASMPIKernel::copy(vx.distribution(), vx, vr);
557void SimpleCSRInternalLinearAlgebraExpr::copy(
const CSRMatrix& ma, CSRMatrix& mr)
const
559#ifdef ALIEN_USE_PERF_TIMER
560 SentryType s(m_timer,
"MATRIX-CSR-COPY");
565void SimpleCSRInternalLinearAlgebraExpr::add(
const CSRMatrix& ma, CSRMatrix& mr)
const
567#ifdef ALIEN_USE_PERF_TIMER
568 SentryType s(m_timer,
"MATRIX-CSR-ADD");
571 cblas::axpy(mr.getProfile().getNnz(), 1, (CSRMatrix::ValueType*)ma.data(), 1, mr.data(), 1);
574void SimpleCSRInternalLinearAlgebraExpr::scal(Real alpha, CSRMatrix& mr)
const
576#ifdef ALIEN_USE_PERF_TIMER
577 SentryType s(m_timer,
"MATRIX-CSR-SCAL");
580 cblas::scal(mr.getProfile().getNnz(), alpha, mr.data(), 1);
585Real SimpleCSRInternalLinearAlgebraExpr::dot(
586Integer local_size,
const UniqueArray<Real>& vx,
const UniqueArray<Real>& vy)
const
588 return cblas::dot(local_size, dataPtr(vx), 1, dataPtr(vy), 1);
591Real SimpleCSRInternalLinearAlgebraExpr::dot(
const CSRVector& vx,
const CSRVector& vy)
const
593 return CBLASMPIKernel::dot(vx.distribution(), vx, vy);
597void SimpleCSRInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, UniqueArray<Real>& x ALIEN_UNUSED_PARAM)
const
599 throw NotImplementedException(
600 A_FUNCINFO,
"SimpleCSRLinearAlgebra::scal not implemented");
603void SimpleCSRInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, CSRVector& x ALIEN_UNUSED_PARAM)
const
605 throw NotImplementedException(
606 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
609void SimpleCSRInternalLinearAlgebraExpr::diagonal(
610const CSRMatrix& a ALIEN_UNUSED_PARAM, CSRVector& x ALIEN_UNUSED_PARAM)
const
612 throw NotImplementedException(
613 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
616void SimpleCSRInternalLinearAlgebraExpr::reciprocal(CSRVector& x ALIEN_UNUSED_PARAM)
const
618 throw NotImplementedException(
619 A_FUNCINFO,
"SimpleCSRLinearAlgebra::aypx not implemented");
622void SimpleCSRInternalLinearAlgebraExpr::pointwiseMult(
const CSRVector& x ALIEN_UNUSED_PARAM,
623 const CSRVector& y ALIEN_UNUSED_PARAM, CSRVector& w ALIEN_UNUSED_PARAM)
const
625 throw NotImplementedException(
626 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 --