MPQC  3.0.0-alpha
fockdist.h
1 
2 #ifndef _chemistry_qc_lcao_fockdist_h
3 #define _chemistry_qc_lcao_fockdist_h
4 
5 #include <vector>
6 #include <util/misc/scint.h>
7 #include <util/group/message.h>
8 #include <util/group/thread.h>
9 #include <chemistry/qc/basis/basis.h>
10 #include <chemistry/qc/basis/petite.h>
11 
12 namespace sc {
13 
14 class FockBlocks: public sc::RefCount {
15  int nblock_;
16  std::vector<int> begin_;
17  std::vector<int> end_;
18  std::vector<int> shell_to_block_;
19  public:
20  typedef enum { Shell, Atom } Method;
21 
23 
24  int nblock() const { return nblock_; }
25  int begin(int iblock) const {return begin_[iblock];}
26  int end(int iblock) const {return end_[iblock];}
27  int size(int iblock) const {return end_[iblock]-begin_[iblock];}
28  int shell_to_block(int ishell) const { return shell_to_block_[ishell]; }
29 };
30 
31 class FockDist: public sc::RefCount {
32  protected:
33  sc::Ref<FockBlocks> blocks_;
34 
37  int nthread_, mythread_;
38  int nproc_, myproc_;
39  // This returns true if any of the shells in block i are in p1.
40  bool in_p1(int i);
41  public:
43  const sc::Ref<FockBlocks> &,
44  const sc::Ref<sc::PetiteList> &pl,
46  int nthread, int mythread);
47  virtual ~FockDist();
48  virtual void init() = 0;
49  // This only returns canonical block indices. When symmetry is used,
50  // this returns only blocks in_p1. This can be done, since only blocks
51  // comprised of shells on the same atom are used. Checks for p2 and p4
52  // must be done on individual shell indices, since the results of those
53  // checks depend on the particular shell number, even for shells on
54  // the same atom.
55  virtual bool get_blocks(int &i, int &j, int &k, int &l) = 0;
56  int nblock() const { return blocks_->nblock(); }
57  int begin(int iblock) const {return blocks_->begin(iblock);}
58  int end(int iblock) const {return blocks_->end(iblock);}
59  int size(int iblock) const {return blocks_->size(iblock);}
60  const sc::Ref<FockBlocks> &fockblocks() const { return blocks_; }
61  // Returns true if a given shell quartet will always end up on the same
62  // node/thread.
63  virtual bool fixed_integral_map() = 0;
64 };
65 
66 class FockDistStatic: public FockDist {
67  protected:
68  int i_, j_, k_, l_;
69  int nglobalthread_, myglobalthread_;
70  public:
72  const sc::Ref<FockBlocks> &,
73  const sc::Ref<sc::PetiteList> &pl,
75  int nthread, int mythread);
76  ~FockDistStatic();
77  void init();
78  bool fixed_integral_map();
79 };
80 
82  private:
83  bool next_block();
84  bool next_block(int n);
85  public:
87  const sc::Ref<FockBlocks> &,
88  const sc::Ref<sc::PetiteList> &pl,
90  int nthread, int mythread);
91  ~FockDistStatic4();
92  bool get_blocks(int&,int&,int&,int&);
93 };
94 
96  private:
97  bool next_block();
98  public:
100  const sc::Ref<FockBlocks> &,
101  const sc::Ref<sc::PetiteList> &pl,
102  const sc::Ref<sc::MessageGrp> &,
103  int nthread, int mythread);
104  ~FockDistStatic2();
105  bool get_blocks(int&,int&,int&,int&);
106 };
107 
108 class FockDistDynamic: public FockDist {
109  protected:
110  typedef std::multimap<std::pair<int,int>, std::pair<int,int>, std::greater<std::pair<int,int> > > pairmap_t;
111 
112  pairmap_t ijmap_, klmap_;
113  pairmap_t::const_iterator ij_iter_, kl_iter_;
114 
115  // If there are not enough processors to use dynamic load balancing,
116  // then static load balancing must be used. These members support
117  // static load balancing.
118  FockDist *static_;
119  bool static_distribution() { return static_ != 0; }
120  public:
122  const sc::Ref<FockBlocks> &,
123  const sc::Ref<sc::PetiteList> &pl,
124  const sc::Ref<sc::MessageGrp> &,
125  int nthread, int mythread,
126  const signed char *pmax,
128  int l2tol);
129  ~FockDistDynamic();
130  bool fixed_integral_map();
131 };
132 
134  protected:
135  int i_, j_;
136 
137  bool next_block();
138  void run_server();
139  bool server_get_blocks(int&,int&);
140  public:
142  const sc::Ref<FockBlocks> &,
143  const sc::Ref<sc::PetiteList> &pl,
144  const sc::Ref<sc::MessageGrp> &,
145  int nthread, int mythread,
146  const signed char *pmax,
148  int l2tol);
149  ~FockDistDynamic2();
150  bool get_blocks(int&,int&,int&,int&);
151  void init();
152 };
153 
155  protected:
156  typedef std::vector<std::pair<int,int> > pairvec_t;
157  pairvec_t ijvec_, klvec_;
158  int a_, b_; // this are the iterators used to compute ij and kl
159  int a_end_, b_end_;
160  int nij_, nkl_;
161 
162  sc::MessageGrp::MessageHandle recv_handle_;
163  sc::MessageGrp::MessageHandle send_handle_;
164  bool requested_work_;
165  int work_[4];
166 
167  bool next_block();
168  void run_server();
169  bool server_get_blocks(int&,int&,int&,int&);
170  bool ijkl(int &i, int &j, int &k, int &l);
171  public:
173  const sc::Ref<FockBlocks> &,
174  const sc::Ref<sc::PetiteList> &pl,
175  const sc::Ref<sc::MessageGrp> &,
176  int nthread, int mythread,
177  const signed char *pmax,
179  int l2tol);
180  ~FockDistDynamic4();
181  bool get_blocks(int&,int&,int&,int&);
182  void init();
183 };
184 
187 class FockDistribution: virtual public sc::SavableState {
189  int dynamic_;
191  int nindex_;
193  int shell_;
195  int cache_integrals_;
196  public:
197  FockDistribution(bool dynamic = 0, bool shell = 1, int nindex = 4,
198  bool cache_integrals = 1);
201  ~FockDistribution();
205  const sc::Ref<FockBlocks> &,
206  const sc::Ref<sc::PetiteList> &pl,
207  const sc::Ref<sc::MessageGrp> &,
208  int nthread, int mythread,
209  const signed char *pmax,
211  int l2tol);
212  void print(std::ostream&o=sc::ExEnv::out0()) const;
213  bool cache_integrals() const { return cache_integrals_; }
214 };
215 
216 }
217 
218 #endif
sc::FockDistribution::print
void print(std::ostream &o=sc::ExEnv::out0()) const
Print the object.
sc::FockDistDynamic2
Definition: fockdist.h:133
sc::FockDistDynamic
Definition: fockdist.h:108
sc::MessageGrp::MessageHandle
Definition: message.h:135
sc::Ref< sc::GaussianBasisSet >
sc::Atom
Atom represents an atom in a Molecule.
Definition: atom.h:47
sc::StateIn
Definition: statein.h:79
sc::FockDist
Definition: fockdist.h:31
sc::FockDistribution
FockDistribution is a factory for constructing the desired FockDist specialization.
Definition: fockdist.h:187
sc::StateOut
Definition: stateout.h:71
sc::FockDistribution::save_data_state
void save_data_state(sc::StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::FockDistStatic4
Definition: fockdist.h:81
sc::FockDistDynamic4
Definition: fockdist.h:154
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::SavableState
Base class for objects that can save/restore state.
Definition: state.h:45
sc::RefCount
The base class for all reference counted objects.
Definition: ref.h:192
sc::FockBlocks
Definition: fockdist.h:14
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::FockDistStatic
Definition: fockdist.h:66
sc::FockDistStatic2
Definition: fockdist.h:95

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