fml  0.1-0
Fused Matrix Library
add.hh
1 // This file is part of fml which is released under the Boost Software
2 // License, Version 1.0. See accompanying file LICENSE or copy at
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #ifndef FML_MPI_LINALG_ADD_H
6 #define FML_MPI_LINALG_ADD_H
7 #pragma once
8 
9 
10 #include "../../_internals/linalgutils.hh"
11 
12 #include "../mpimat.hh"
13 
14 #include "internals/err.hh"
15 #include "internals/pblas.hh"
16 
17 
18 namespace fml
19 {
20 namespace linalg
21 {
40  template <typename REAL>
41  void add(const bool transx, const bool transy, const REAL alpha, const REAL beta, const mpimat<REAL> &x, const mpimat<REAL> &y, mpimat<REAL> &ret)
42  {
43  err::check_grid(x, y, ret);
44 
45  len_t m, n;
46  fml::linalgutils::matadd_params(transx, transy, x.nrows(), x.ncols(), y.nrows(), y.ncols(), &m, &n);
47 
48  if (ret.nrows() != m || ret.ncols() != n)
49  ret.resize(m, n);
50 
51  char ctransx = transx ? 'T' : 'N';
52  char ctransy = transy ? 'T' : 'N';
53 
54  fml::pblas::geadd(ctransy, m, n, beta, y.data_ptr(), y.desc_ptr(), (REAL) 0.0f, ret.data_ptr(), ret.desc_ptr());
55  fml::pblas::geadd(ctransx, m, n, alpha, x.data_ptr(), x.desc_ptr(), (REAL) 1.0f, ret.data_ptr(), ret.desc_ptr());
56  }
57 
58 
59 
61  template <typename REAL>
62  mpimat<REAL> add(const bool transx, const bool transy, const REAL alpha, const REAL beta, const mpimat<REAL> &x, const mpimat<REAL> &y)
63  {
64  err::check_grid(x, y);
65 
66  len_t m, n;
67  fml::linalgutils::matadd_params(transx, transy, x.nrows(), x.ncols(), y.nrows(), y.ncols(), &m, &n);
68 
69  const grid g = x.get_grid();
70  mpimat<REAL> ret(g, m, n, x.bf_rows(), x.bf_cols());
71  add(transx, transy, alpha, beta, x, y, ret);
72  return ret;
73  }
74 }
75 }
76 
77 
78 #endif
fml::mpimat::resize
void resize(len_t nrows, len_t ncols)
Resize the internal object storage.
Definition: mpimat.hh:326
fml::grid
2-dimensional MPI process grid.
Definition: grid.hh:70
fml::mpimat
Matrix class for data distributed over MPI in the 2-d block cyclic format.
Definition: mpimat.hh:40
fml::unimat::nrows
len_t nrows() const
Number of rows.
Definition: unimat.hh:36
fml::unimat::ncols
len_t ncols() const
Number of columns.
Definition: unimat.hh:38
fml::unimat::data_ptr
REAL * data_ptr()
Pointer to the internal array.
Definition: unimat.hh:40
fml
Core namespace.
Definition: dimops.hh:10
fml::linalg::add
void add(const bool transx, const bool transy, const REAL alpha, const REAL beta, const cpumat< REAL > &x, const cpumat< REAL > &y, cpumat< REAL > &ret)
Returns alpha*op(x) + beta*op(y) where op(A) is A or A^T.
Definition: add.hh:35