fml  0.1-0
Fused Matrix Library
chol.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_CHOL_H
6 #define FML_MPI_LINALG_CHOL_H
7 #pragma once
8 
9 
10 #include <stdexcept>
11 
12 #include "../../_internals/linalgutils.hh"
13 
14 #include "../internals/bcutils.hh"
15 #include "../internals/mpi_utils.hh"
16 
17 #include "../mpimat.hh"
18 
19 #include "internals/scalapack.hh"
20 
21 
22 namespace fml
23 {
24 namespace linalg
25 {
45  template <typename REAL>
46  void chol(mpimat<REAL> &x)
47  {
48  const len_t n = x.nrows();
49  if (n != x.ncols())
50  throw std::runtime_error("'x' must be a square matrix");
51 
52  int info = 0;
53  fml::scalapack::potrf('L', n, x.data_ptr(), x.desc_ptr(), &info);
54 
55  if (info < 0)
56  fml::linalgutils::check_info(info, "potrf");
57  else if (info > 0)
58  throw std::runtime_error("chol: leading minor of order " + std::to_string(info) + " is not positive definite");
59 
60  fml::mpi_utils::tri2zero('U', false, x.get_grid(), n, n, x.data_ptr(), x.desc_ptr());
61  }
62 }
63 }
64 
65 
66 #endif
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::chol
void chol(cpumat< REAL > &x)
Compute the Choleski factorization.
Definition: chol.hh:46