MPQC  3.0.0-alpha
analyze_array.h
1 
2 /*
3  * Copyright 2009 Sandia Corporation. Under the terms of Contract
4  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5  * retains certain rights in this software.
6  *
7  * This file is a part of the MPQC LMP2 library.
8  *
9  * The MPQC LMP2 library is free software: you can redistribute it
10  * and/or modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation, either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this program. If not, see
21  * <http://www.gnu.org/licenses/>.
22  *
23  */
24 
25 #ifndef _chemistry_qc_analyze_array_h
26 #define _chemistry_qc_analyze_array_h
27 
28 #include <chemistry/qc/lmp2/sma.h>
29 #include <util/group/message.h>
30 
31 namespace sc {
32 
39 template <int N>
40 void
41 analyze_array(typename sma2::Array<N> &array, const char *name,
42  const sc::Ref<sc::MessageGrp> &grp = 0, bool distributed = false)
43 {
44  if ((distributed && grp && grp->n() == 1)
45  || grp.null()) {
46  distributed = false;
47  }
48  double n_block_max_total = 1;
49  double n_element_max_total = 1;
50  for (int i=0; i<N; i++) {
51  n_block_max_total *= array.index(i).nblock();
52  n_element_max_total *= array.index(i).nindex();
53  }
54  double n_block_max = n_block_max_total;
55  double n_element_max = n_element_max_total;
56  if (distributed) {
57  n_block_max /= grp->n();
58  n_element_max /= grp->n();
59  }
60  double nblock = array.n_block();
61  double nelement = array.n_element();
62  double nblock_total = nblock;
63  double nelement_total = nelement;
64  if (distributed) {
65  grp->sum(nblock_total);
66  grp->sum(nelement_total);
67  grp->max(nblock);
68  grp->max(nelement);
69  }
70  sc::ExEnv::out0() << sc::indent
71  << sc::scprintf(
72  " %10s %5.0f of %5.0f blocks %10.0f of %10.0f elements locally",
73  name, nblock, n_block_max, nelement, n_element_max)
74  << std::endl;
75  if (distributed) {
76  sc::ExEnv::out0() << sc::indent
77  << sc::scprintf(
78  " %10s %5.0f of %5.0f blocks %10.0f of %10.0f elements globally", name, nblock_total, n_block_max_total, nelement_total,
79  n_element_max_total)
80  << std::endl;
81  }
82 #if USE_STL_MULTIMAP
83  sc::ExEnv::out0() << sc::indent
84  << sc::scprintf(
85  " uses %11.3f MB for data locally",
86  nelement*sizeof(double)*1e-6)
87  << std::endl;
88 #else
89  sc::ExEnv::out0() << sc::indent
90  << sc::scprintf(
91  " uses %11.3f MB for data and %11.3f MB for the map locally",
92  nelement*sizeof(double)*1e-6,
93  nblock*sizeof(AVLMMapNode<sma2::BlockInfo<N>,double*>)*1e-6)
94  << std::endl;
95 #endif
96 }
97 
98 }
99 
100 #endif
sc::sma2::Array::n_element
size_t n_element() const
Returns the number of elements contained in blocks.
Definition: sma.h:1692
sc::sma2::Array::index
const Range & index(int i) const
Gets the i'th Range.
Definition: sma.h:1503
sc::Ref< sc::MessageGrp >
sc::sma2::BlockInfo
BlockInfo stores info about a block of data.
Definition: sma.h:200
sc::sma2::Array
Implements a block sparse tensor.
Definition: sma.h:1088
sc::AVLMMapNode
Definition: avlmmap.h:42
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::sma2::Array::n_block
int n_block() const
Returns the number of blocks.
Definition: sma.h:1688
sc::analyze_array
void analyze_array(typename sma2::Array< N > &array, const char *name, const sc::Ref< sc::MessageGrp > &grp=0, bool distributed=false)
Prints out information about an Array.
Definition: analyze_array.h:41
sc::scprintf
This class allows printf-like output to be sent to an ostream.
Definition: formio.h:97
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:23:58 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.