MPQC  3.0.0-alpha
arraydef.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_lmp2_arraydef_h
26 #define _chemistry_qc_lmp2_arraydef_h
27 
28 #include <iomanip>
29 
30 namespace sc {
31 
32 namespace sma2 {
33  template <int N>
34  inline void Array<N>::print_local(std::ostream&o) const {
36  aiter = blocks_.begin();
37  aiter != blocks_.end();
38  aiter++) {
39  const BlockInfo<N> &info = aiter->first;
40  const double *data = aiter->second;
41  BlockIter<N> iter(indices(),aiter->first);
42  bool first = true;
43  for (iter.start(); iter.ready(); iter++) {
44  o << " ";
45  for (int i=0; i<N; i++) {
46  o << " " << iter.index(i)
47  + index(i).block_offset(info.block(i));
48  }
49  o << " = ";
50  if (allocated_) {
51  o << std::showpoint << std::fixed
52  << std::setw(11) << std::setprecision(8)
53  << data[iter.offset()];
54  }
55  else {
56  o << "unallocated";
57  }
58  o << " offset: ";
59  for (int i=0; i<N; i++) {
60  o << " " << iter.index(i);
61  }
62  if (first) {
63  o << " block: ";
64  info.print(o);
65  first = false;
66  }
67  o << std::endl;
68  }
69  }
70  }
71  template <int N>
72  inline void Array<N>::print(const sc::Ref<sc::MessageGrp> &grp,
73  bool distributed, std::ostream&o) const {
74 // if (grp.null() || grp->me() == 0) {
75 // for (int i = 0; i < N; i++) {
76 // indices_[i].print(o);
77 // }
78 // }
79  if (grp && distributed) {
80  if (grp->me() == 0) o << "array " << name_ << ":" << std::endl;
81  for (int i=0; i<grp->n(); i++) {
82  if (grp->me() == i) {
83  o << "node " << i << ":" << std::endl;
84  print_local(o);
85  o << std::flush;
86  }
87  grp->sync();
88  sleep(1);
89  }
90  }
91  else if (grp.null() || (grp && grp->n() == 1)) {
92  print_local(o);
93  }
94  }
95 
96  template <int N, class V>
97  void
98  apply_denominator(Array<N> &array, double denominator_offset,
99  const std::vector<V> &eigenvalues)
100  {
101  if (N != eigenvalues.size()) {
102  throw std::runtime_error("apply_denominator: eigenvalues.size() != N");
103  }
104  bool inited = false;
105  const bool print_factor_info = false;
106  double smallest_factor = 0.0;
107  double largest_factor = 0.0;
108  const typename Array<N>::blockmap_t &bmap = array.blockmap();
109  for (typename Array<N>::blockmap_t::const_iterator bmapiter = bmap.begin();
110  bmapiter != bmap.end();
111  bmapiter++) {
112  const BlockInfo<N> &binfo = bmapiter->first;
113  double *data = bmapiter->second;
114  int off[N];
115  for (int i=0; i<N; i++) {
116  off[i] = array.index(i).block_offset(binfo.block(i));
117  }
118  BlockIter<N> biter(array.indices(),binfo);
119  for (biter.start(); biter.ready(); biter++) {
120  int offset = biter.offset();
121  double denom = denominator_offset;
122  for (int i=0; i<N; i++) {
123  denom += (*eigenvalues[i])[biter.index(i) + off[i]];
124  }
125  data[offset] /= denom;
126  if (print_factor_info) {
127  if (!inited) {
128  largest_factor = smallest_factor = denom;
129  inited = true;
130  }
131  if (smallest_factor > denom) smallest_factor = denom;
132  if (largest_factor < denom) largest_factor = denom;
133  }
134  }
135  }
136 
137  if (inited && print_factor_info) {
138  sc::ExEnv::out0() << sc::indent
139  << "The denominators are in the range ["
140  << smallest_factor
141  << ", "
142  << largest_factor
143  << "]"
144  << std::endl;
145  }
146  }
147 
148 }
149 
150 }
151 
152 #endif
sc::Ref< sc::MessageGrp >
sc::sma2::BlockIter::start
void start()
Initialize the iterator.
Definition: sma.h:2211
sc::sma2::BlockInfo
BlockInfo stores info about a block of data.
Definition: sma.h:200
sc::sma2::BlockIter
BlockIter loops through the all the indices within a block.
Definition: sma.h:2189
sc::MessageGrp::me
int me()
Returns my processor number. In the range [0,n()).
Definition: message.h:194
sc::sma2::Array
Implements a block sparse tensor.
Definition: sma.h:1088
sc::Ref::null
bool null() const
Return true if this is a reference to a null object.
Definition: ref.h:423
sc::MessageGrp::n
int n()
Returns the number of processors.
Definition: message.h:192
sc::MessageGrp::sync
virtual void sync()
Synchronize all of the processors.
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::sma2::Array::print_local
void print_local(std::ostream &o=sc::ExEnv::outn()) const
Print the array.
Definition: arraydef.h:34
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::sma2::BlockIter::ready
bool ready() const
Returns true if the iterator is valid.
Definition: sma.h:2213

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