5 #ifndef FML_MPI_LINALG_LINALG_MISC_H
6 #define FML_MPI_LINALG_LINALG_MISC_H
12 #include "../../cpu/cpuvec.hh"
14 #include "../mpimat.hh"
16 #include "linalg_qr.hh"
17 #include "linalg_svd.hh"
42 template <
typename REAL>
46 throw std::runtime_error(
"'x' must be a square matrix");
69 const len_t m_local = x.nrows_local();
70 const len_t n_local = x.ncols_local();
74 const grid g = x.get_grid();
76 for (len_t i=0; i<m_local; i++)
78 len_t gi = fml::bcutils::l2g(i, x.bf_rows(), g.
nprow(), g.
myrow());
80 if (ipiv[i] != (gi + 1))
84 for (len_t j=0; j<n_local; j++)
86 for (len_t i=0; i<m_local; i++)
88 len_t gi = fml::bcutils::l2g(i, x.bf_rows(), g.
nprow(), g.
myrow());
89 len_t gj = fml::bcutils::l2g(j, x.bf_cols(), g.
npcol(), g.
mycol());
93 const REAL d = a[i + m_local*j];
107 sgn = (sgn<0 ? 1 : 0);
109 sgn = (sgn%2==0 ? 1 : -1);
126 template <
typename REAL>
130 const len_t minmn = std::min(x.
nrows(), x.
ncols());
131 const len_t m_local = x.nrows_local();
132 const int mb = x.bf_rows();
133 const int nb = x.bf_cols();
134 const grid g = x.get_grid();
137 for (len_t gi=0; gi<minmn; gi++)
139 const len_local_t i = fml::bcutils::g2l(gi, mb, g.
nprow());
140 const len_local_t j = fml::bcutils::g2l(gi, nb, g.
npcol());
142 const int pr = fml::bcutils::g2p(gi, mb, g.
nprow());
143 const int pc = fml::bcutils::g2p(gi, nb, g.
npcol());
146 tr += x_d[i + m_local*j];