util.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2020 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * David Williams-Young
19  * Computational Research Division, Lawrence Berkeley National Laboratory
20  *
21  * util.h
22  * Created: 19 June, 2020
23  *
24  */
25 #ifndef TILEDARRAY_MATH_LINALG_SCALAPACK_UTIL_H__INCLUDED
26 #define TILEDARRAY_MATH_LINALG_SCALAPACK_UTIL_H__INCLUDED
27 
28 #include <TiledArray/config.h>
29 #if TILEDARRAY_HAS_SCALAPACK
30 
33 
35 
36 inline scalapackpp::TransposeFlag to_scalapackpp_transposeflag(Op t) {
37  switch (t) {
38  case Op::NoTrans:
39  return scalapackpp::TransposeFlag::NoTranspose;
40  case Op::Trans:
41  return scalapackpp::TransposeFlag::Transpose;
42  case Op::ConjTrans:
43  return scalapackpp::TransposeFlag::ConjTranspose;
44  default:
45  abort();
46  }
47 }
48 
49 template <typename T>
50 void zero_triangle(blacspp::Triangle tri, scalapack::BlockCyclicMatrix<T>& A,
51  bool zero_diag = false) {
52  auto zero_el = [&](size_t I, size_t J) {
53  if (A.dist().i_own(I, J)) {
54  auto [i, j] = A.dist().local_indx(I, J);
55  A.local_mat()(i, j) = 0.;
56  }
57  };
58 
59  auto [M, N] = A.dims();
60 
61  // Zero the lower triangle
62  if (tri == blacspp::Triangle::Lower) {
63  if (zero_diag)
64  for (size_t j = 0; j < N; ++j)
65  for (size_t i = j; i < M; ++i) zero_el(i, j);
66  else
67  for (size_t j = 0; j < N; ++j)
68  for (size_t i = j + 1; i < M; ++i) zero_el(i, j);
69 
70  // Zero the upper triangle
71  } else {
72  if (zero_diag)
73  for (size_t j = 0; j < N; ++j)
74  for (size_t i = 0; i <= std::min(j, M); ++i) zero_el(i, j);
75  else
76  for (size_t j = 0; j < N; ++j)
77  for (size_t i = 0; i < std::min(j, M); ++i) zero_el(i, j);
78  }
79 }
80 
81 namespace detail {
82 inline std::size_t& default_block_size_accessor() {
83  static std::size_t block_size = 128;
84  return block_size;
85 }
86 } // namespace detail
87 
88 inline std::size_t default_block_size() {
90 }
91 
92 inline void set_default_block_size(std::size_t NB) {
93  TA_ASSERT(NB > 0);
95 }
96 
97 } // namespace TiledArray::math::linalg::scalapack
98 
99 #endif // TILEDARRAY_HAS_SCALAPACK
100 #endif // TILEDARRAY_MATH_LINALG_SCALAPACK_UTIL_H__INCLUDED
std::size_t & default_block_size_accessor()
Definition: util.h:82
std::size_t default_block_size()
Definition: util.h:88
void zero_triangle(blacspp::Triangle tri, scalapack::BlockCyclicMatrix< T > &A, bool zero_diag=false)
Definition: util.h:50
KroneckerDeltaTile< _N >::numeric_type min(const KroneckerDeltaTile< _N > &arg)
void set_default_block_size(std::size_t NB)
Definition: util.h:92
scalapackpp::TransposeFlag to_scalapackpp_transposeflag(Op t)
Definition: util.h:36
#define TA_ASSERT(EXPR,...)
Definition: error.h:39