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);
45 template <
typename Distribution,
typename VectorT>
46 static void copy([[maybe_unused]] Distribution
const& dist,
48 ConstArrayView<Integer> strides,
51 typedef typename VectorT::ValueType ValueType;
52 std::size_t local_size = y.scalarizedLocalSize();
53 auto x_ptr = x.getDataPtr();
54 auto y_ptr = y.getDataPtr();
55 for (std::size_t i = 0; i < local_size; ++i)
57 y_ptr[i] = x_ptr[strides[i]] ;
61 template <
typename Distribution,
typename VectorT>
62 static void copy([[maybe_unused]] Distribution
const& dist,
65 ConstArrayView<Integer> strides)
67 typedef typename VectorT::ValueType ValueType;
68 std::size_t local_size = x.scalarizedLocalSize();
69 auto x_ptr = x.getDataPtr();
70 auto y_ptr = y.getDataPtr();
71 for (std::size_t i = 0; i < local_size; ++i)
73 y_ptr[strides[i]] = x_ptr[i] ;
78 template <
typename Distribution,
typename VectorT>
79 static void axpy(Distribution
const& dist ALIEN_UNUSED_PARAM,
80 typename VectorT::ValueType alpha,
const VectorT& x, VectorT& y)
82 cblas::axpy(x.scalarizedLocalSize(), alpha, x.getDataPtr(), 1, y.getDataPtr(), 1);
85 template <
typename Distribution,
typename VectorT>
86 static void axpy(Distribution
const& dist,
87 typename VectorT::ValueType alpha,
93 cblas::axpy(x.scalarizedLocalSize(), alpha, x.getDataPtr(), stride_x, y.getDataPtr(), stride_y);
96 template <
typename Distribution,
typename VectorT>
97 static void axpy([[maybe_unused]] Distribution
const& dist,
98 typename VectorT::ValueType alpha,
101 ConstArrayView<Integer> strides)
103 typedef typename VectorT::ValueType ValueType;
104 std::size_t local_size = x.scalarizedLocalSize();
105 auto x_ptr = x.getDataPtr();
106 auto y_ptr = y.getDataPtr();
107 for (std::size_t i = 0; i < local_size; ++i)
109 y_ptr[strides[i]] += alpha * x_ptr[i] ;
113 template <
typename Distribution,
typename VectorT>
114 static void scal(Distribution
const& dist ALIEN_UNUSED_PARAM,
115 typename VectorT::ValueType alpha, VectorT& x)
117 cblas::scal(x.scalarizedLocalSize(), alpha, x.getDataPtr(), 1);
120 template <
typename Distribution,
typename VectorT>
121 static void pointwiseMult(Distribution
const& dist,
126 auto local_size = x.scalarizedLocalSize();
127 auto x_ptr = x.getDataPtr();
128 auto y_ptr = y.getDataPtr();
129 auto z_ptr = z.getDataPtr();
130 for (Integer i = 0; i < local_size; ++i) {
131 z_ptr[i] = x_ptr[i] * y_ptr[i];
132#ifdef PRINT_DEBUG_INFO
133 std::cout<<
"X Y Z ["<<i<<
"] : "<<x_ptr[i]<<
"*"<<y_ptr[i]<<
"="<<z_ptr[i]<<std::endl ;
138 template <
typename Distribution,
typename VectorT>
139 static void assign(Distribution
const& dist,
140 typename VectorT::ValueType alpha,
143 auto local_size = y.scalarizedLocalSize();
144 auto y_ptr = y.getDataPtr();
145 for (Integer i = 0; i < local_size; ++i) {
150 template <
typename Distribution,
typename VectorT>
151 static typename VectorT::ValueType dot(
152 Distribution
const& dist,
const VectorT& x,
const VectorT& y)
154 typedef typename VectorT::ValueType ValueType;
155 ValueType value = cblas::dot(x.scalarizedLocalSize(), (ValueType*)x.getDataPtr(), 1,
156 (ValueType*)y.getDataPtr(), 1);
157 if (dist.isParallel()) {
158 value = Arccore::MessagePassing::mpAllReduce(dist.parallelMng(),
159 Arccore::MessagePassing::ReduceSum, value);
164 template <
typename Distribution,
typename VectorT>
165 static typename VectorT::ValueType nrm0(Distribution
const& dist,
const VectorT& x)
167 typedef typename VectorT::ValueType ValueType;
168 std::size_t local_size = x.scalarizedLocalSize();
169 auto x_ptr = x.getDataPtr();
170 ValueType value = ValueType() ;
171 for(std::size_t i = 0; i < local_size; ++i)
172 value += (std::abs(x_ptr[i])>0?1:0) ;
174 if (dist.isParallel()) {
175 value = Arccore::MessagePassing::mpAllReduce(
176 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, value);
181 template <
typename Distribution,
typename VectorT>
182 static typename VectorT::ValueType nrm1(Distribution
const& dist,
const VectorT& x)
184 typedef typename VectorT::ValueType ValueType;
185 typename VectorT::ValueType value = cblas::nrm1(x.scalarizedLocalSize(),
186 (ValueType*)x.getDataPtr(), 1);
187 if (dist.isParallel()) {
188 value = Arccore::MessagePassing::mpAllReduce(
189 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, value);
194 template <
typename Distribution,
typename VectorT>
195 static typename VectorT::ValueType nrm2(Distribution
const& dist,
const VectorT& x)
197 typedef typename VectorT::ValueType ValueType;
198 typename VectorT::ValueType value = cblas::dot(x.scalarizedLocalSize(),
199 (ValueType*)x.getDataPtr(), 1, (ValueType*)x.getDataPtr(), 1);
200 if (dist.isParallel()) {
201 value = Arccore::MessagePassing::mpAllReduce(
202 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, value);
204 return std::sqrt(value);
207 template <
typename Distribution,
typename VectorT>
208 static typename VectorT::ValueType nrmInf(Distribution
const& dist,
const VectorT& x)
210 typedef typename VectorT::ValueType ValueType;
211 std::size_t local_size = x.scalarizedLocalSize();
212 auto x_ptr = x.getDataPtr();
213 ValueType value = ValueType() ;
214 for(std::size_t i = 0; i < local_size; ++i)
215 value = std::max(value,std::abs(x_ptr[i])) ;
217 if (dist.isParallel()) {
218 value = Arccore::MessagePassing::mpAllReduce(
219 dist.parallelMng(), Arccore::MessagePassing::ReduceMax, value);
224 template <
typename Distribution,
typename MatrixT>
225 static typename MatrixT::ValueType matrix_nrm2(Distribution
const& dist,
const MatrixT& x)
227 typedef typename MatrixT::ValueType ValueType;
228 typename MatrixT::ValueType value = cblas::dot(x.getProfile().getNnz(),
229 (ValueType*)x.data(), 1, (ValueType*)x.data(), 1);
230 if (dist.isParallel()) {
231 value = Arccore::MessagePassing::mpAllReduce(
232 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, value);
234 return std::sqrt(value);