24 static const bool is_hybrid =
false;
25 static const bool is_mpi =
true;
27 template <
typename Distribution,
typename VectorT>
29 Distribution
const& dist ALIEN_UNUSED_PARAM,
const VectorT& x, VectorT& y)
31 typedef typename VectorT::ValueType ValueType;
33 x.scalarizedLocalSize(), (ValueType*)x.getDataPtr(), 1, y.getDataPtr(), 1);
36 template <
typename Distribution,
typename VectorT>
38 Distribution
const& dist,
const VectorT& x, Integer stride_x, VectorT& y, Integer stride_y)
40 typedef typename VectorT::ValueType ValueType;
41 cblas::copy(dist.localSize(), (ValueType*)x.getDataPtr(), stride_x, y.getDataPtr(), stride_y);
44 template <
typename Distribution,
typename VectorT>
45 static void axpy(Distribution
const& dist ALIEN_UNUSED_PARAM,
46 typename VectorT::ValueType alpha,
const VectorT& x, VectorT& y)
48 cblas::axpy(x.scalarizedLocalSize(), alpha, x.getDataPtr(), 1, y.getDataPtr(), 1);
51 template <
typename Distribution,
typename VectorT>
52 static void axpy(Distribution
const& dist,
53 typename VectorT::ValueType alpha,
59 cblas::axpy(x.scalarizedLocalSize(), alpha, x.getDataPtr(), stride_x, y.getDataPtr(), stride_y);
61 template <
typename Distribution,
typename VectorT>
62 static void scal(Distribution
const& dist ALIEN_UNUSED_PARAM,
63 typename VectorT::ValueType alpha, VectorT& x)
65 cblas::scal(x.scalarizedLocalSize(), alpha, x.getDataPtr(), 1);
68 template <
typename Distribution,
typename VectorT>
69 static void pointwiseMult(Distribution
const& dist,
74 auto local_size = x.scalarizedLocalSize();
75 auto x_ptr = x.getDataPtr();
76 auto y_ptr = y.getDataPtr();
77 auto z_ptr = z.getDataPtr();
78 for (std::size_t i = 0; i < local_size; ++i) {
79 z_ptr[i] = x_ptr[i] * y_ptr[i];
80#ifdef PRINT_DEBUG_INFO
81 std::cout<<
"X Y Z ["<<i<<
"] : "<<x_ptr[i]<<
"*"<<y_ptr[i]<<
"="<<z_ptr[i]<<std::endl ;
86 template <
typename Distribution,
typename VectorT>
87 static void assign(Distribution
const& dist,
88 typename VectorT::ValueType alpha,
91 auto local_size = y.scalarizedLocalSize();
92 auto y_ptr = y.getDataPtr();
93 for (std::size_t i = 0; i < local_size; ++i) {
98 template <
typename Distribution,
typename VectorT>
99 static typename VectorT::ValueType dot(
100 Distribution
const& dist,
const VectorT& x,
const VectorT& y)
102 typedef typename VectorT::ValueType ValueType;
103 ValueType value = cblas::dot(x.scalarizedLocalSize(), (ValueType*)x.getDataPtr(), 1,
104 (ValueType*)y.getDataPtr(), 1);
105 if (dist.isParallel()) {
106 return Arccore::MessagePassing::mpAllReduce(
107 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, value);
112 template <
typename Distribution,
typename VectorT>
113 static typename VectorT::ValueType nrm0(Distribution
const& dist,
const VectorT& x)
115 typedef typename VectorT::ValueType ValueType;
116 auto local_size = x.scalarizedLocalSize();
117 auto x_ptr = x.getDataPtr();
118 ValueType value = ValueType() ;
119 for(std::size_t i = 0; i < local_size; ++i)
120 value += (std::abs(x_ptr[i])>0?1:0) ;
122 if (dist.isParallel()) {
123 value = Arccore::MessagePassing::mpAllReduce(
124 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, value);
129 template <
typename Distribution,
typename VectorT>
130 static typename VectorT::ValueType nrm1(Distribution
const& dist,
const VectorT& x)
132 typedef typename VectorT::ValueType ValueType;
133 typename VectorT::ValueType value = cblas::nrm1(x.scalarizedLocalSize(),
134 (ValueType*)x.getDataPtr(), 1);
135 if (dist.isParallel()) {
136 value = Arccore::MessagePassing::mpAllReduce(
137 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, value);
142 template <
typename Distribution,
typename VectorT>
143 static typename VectorT::ValueType nrm2(Distribution
const& dist,
const VectorT& x)
145 typedef typename VectorT::ValueType ValueType;
146 typename VectorT::ValueType value = cblas::dot(x.scalarizedLocalSize(),
147 (ValueType*)x.getDataPtr(), 1, (ValueType*)x.getDataPtr(), 1);
148 if (dist.isParallel()) {
149 value = Arccore::MessagePassing::mpAllReduce(
150 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, value);
152 return std::sqrt(value);
155 template <
typename Distribution,
typename VectorT>
156 static typename VectorT::ValueType nrmInf(Distribution
const& dist,
const VectorT& x)
158 typedef typename VectorT::ValueType ValueType;
159 auto local_size = x.scalarizedLocalSize();
160 auto x_ptr = x.getDataPtr();
161 ValueType value = ValueType() ;
162 for(std::size_t i = 0; i < local_size; ++i)
163 value = std::max(value,std::abs(x_ptr[i])) ;
165 if (dist.isParallel()) {
166 value = Arccore::MessagePassing::mpAllReduce(
167 dist.parallelMng(), Arccore::MessagePassing::ReduceMax, value);
172 template <
typename Distribution,
typename MatrixT>
173 static typename MatrixT::ValueType matrix_nrm2(Distribution
const& dist,
const MatrixT& x)
175 typedef typename MatrixT::ValueType ValueType;
176 typename MatrixT::ValueType value = cblas::dot(x.getProfile().getNnz(),
177 (ValueType*)x.data(), 1, (ValueType*)x.data(), 1);
178 if (dist.isParallel()) {
179 value = Arccore::MessagePassing::mpAllReduce(
180 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, value);
182 return std::sqrt(value);