MPQC  3.0.0-alpha
distarray4.h
1 //
2 // distarray4.h
3 //
4 // Copyright (C) 2002 Edward Valeev
5 //
6 // Author: Edward Valeev <evaleev@vt.edu>
7 // Maintainer: EV
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _chemistry_qc_mbptr12_distarray4_h
29 #define _chemistry_qc_mbptr12_distarray4_h
30 
31 #include <vector>
32 #include <util/ref/ref.h>
33 #include <util/state/state.h>
34 #include <util/state/statein.h>
35 #include <util/state/stateout.h>
36 #include <util/group/memory.h>
37 #include <util/group/message.h>
38 
39 namespace sc {
40 
41  enum DistArray4Storage {DistArray4Storage_XY, DistArray4Storage_YX};
42 
44  public:
45  static const DistArray4Dimensions& default_dim() { return default_dim_; }
46  DistArray4Dimensions(int num_te_types, int n1, int n2, int n3, int n4,
47  DistArray4Storage storage = DistArray4Storage_XY) :
48  num_te_types_(num_te_types), n1_(n1), n2_(n2), n3_(n3), n4_(n4),
49  storage_(storage)
50  {
51  }
52  int num_te_types() const { return num_te_types_; }
53  int n1() const { return n1_; }
54  int n2() const { return n2_; }
55  int n3() const { return n3_; }
56  int n4() const { return n4_; }
57  DistArray4Storage storage() const { return storage_; }
58  private:
59  static DistArray4Dimensions default_dim_;
60  int num_te_types_;
61  int n1_;
62  int n2_;
63  int n3_;
64  int n4_;
65  DistArray4Storage storage_;
66  };
67  bool operator==(const DistArray4Dimensions& A,
68  const DistArray4Dimensions& B);
69 
71 
94 class DistArray4: virtual public SavableState {
95  public:
96  // mem will be used to fetch data
97  DistArray4(int num_te_types, int ni, int nj, int nx, int ny,
98  DistArray4Storage storage = DistArray4Storage_XY);
100  virtual ~DistArray4();
101  void save_data_state(StateOut&);
102 
105  virtual Ref<DistArray4> clone(const DistArray4Dimensions& dim = DistArray4Dimensions::default_dim()) =0;
106 
108  typedef unsigned int tbint_type;
109  static const unsigned int max_num_te_types = 14;
110 
112  int num_te_types() const { return num_te_types_; };
114  int ni() const { return ni_; }
116  int nj() const { return nj_; }
118  int nx() const { return nx_; }
120  int ny() const { return ny_; }
122  const DistArray4Storage& storage() const { return storage_; }
124  size_t blocksize() const { return blocksize_; };
125  // same as blocksize(), but in bytes
126  size_t blksize() const { return blksize_; }
127 
129  virtual void activate() { active_ = true; }
131  virtual void deactivate() { active_ = false; }
133  virtual bool data_persistent() const =0;
140  virtual const double * retrieve_pair_block(int i, int j, tbint_type oper_type,
141  double* buf = 0) const =0;
144  virtual void retrieve_pair_subblock(int i, int j, tbint_type oper_type,
145  int xstart, int xfence, int ystart, int yfence,
146  double* buf) const =0;
148  virtual void release_pair_block(int i, int j, tbint_type oper_type) const =0;
154  virtual void store_pair_block(int i, int j, tbint_type oper_type, const double* ints) =0;
157  virtual void store_pair_subblock(int i, int j, tbint_type oper_type,
158  int xstart, int xfence, int ystart, int yfence,
159  const double* ints) =0;
160 
161  int ij_index(int i, int j) const { return i*nj_ + j; };
162 
164  virtual bool is_avail(int i, int j) const =0;
166  virtual bool is_local(int i, int j) const =0;
168  virtual bool has_access(int proc) const =0;
172  int tasks_with_access(std::vector<int>& twa_map) const;
173 
174  const Ref<MessageGrp>& msg() const { return msg_; }
175 
176  // return active_
177  bool active() const { return active_; }
178 
179  private:
181  static const int classdebug_ = 0;
182 
183  int num_te_types_; // Number of types of integrals in a block
184  Ref<MessageGrp> msg_;
185  int ni_, nj_;
186  int nx_, ny_;
187  DistArray4Storage storage_;
188  size_t nxy_; // nx_ * ny_ - the number of integrals of one type in a block
189  size_t blksize_; // the same in bytes
190  size_t blocksize_; // hence the size of the block of num_te_types of integrals is blksize_ * num_te_types
191 
192  bool active_;
193 
194  protected:
195  // return nxy_
196  size_t nxy() const { return nxy_; }
198  int ntasks() const { return msg_->n(); }
200  int me() const { return msg_->me(); }
202  int classdebug() const { return classdebug_; }
203 
204 };
205 
206 Ref<DistArray4> make_distarray4(int num_te_types, int ni, int nj, int nx, int ny,
207  DistArray4Storage storage = DistArray4Storage_XY);
208 
210 Ref<DistArray4>
211 extract(const Ref<DistArray4>& A,
212  unsigned int te_type,
213  double scale = 1.0);
214 
217 Ref<DistArray4> permute23(const Ref<DistArray4>& src);
218 
221 Ref<DistArray4> permute34(const Ref<DistArray4>& src);
222 
224 Ref<DistArray4> permute12(const Ref<DistArray4>& src);
225 
226 
228 void
229 axpy(const Ref<DistArray4>& X,
230  double a,
231  const Ref<DistArray4>& Y,
232  double scale = 1.0);
233 
239 void antisymmetrize(const Ref<DistArray4>& A);
240 
246 void symmetrize(const Ref<DistArray4>& A);
247 
249 void contract34(Ref<DistArray4>& braket,
250  double scale,
251  const Ref<DistArray4>& bra,
252  unsigned int intsetidx_bra,
253  const Ref<DistArray4>& ket,
254  unsigned int intsetidx_ket,
255  int debug = 0);
256 
257 class RefSCMatrix;
258 
261 void contract34_DA4_RefMat(Ref<DistArray4>& braket,
262  double scale,
263  const Ref<DistArray4>& bra,
264  unsigned int intsetidx_bra,
265  const RefSCMatrix& ket,
266  const int MatBra1Dim, const int MatBra2Dim);
267 
268 
276 
277 
278 void contract_DA4_RefMat_k2b2_34(Ref<DistArray4>& braket,
279  double scale,
280  const Ref<DistArray4>& bra,
281  unsigned int intsetidx_bra,
282  const RefSCMatrix& ket,
283  const int MatBra1Dim, const int MatBra2Dim);
284 
285 
291 
292 void contract_DA4_RefMat_k1b2_34(Ref<DistArray4>& braket,
293  double scale,
294  const Ref<DistArray4>& bra,
295  unsigned int intsetidx_bra,
296  const RefSCMatrix& ket,
297  const int MatBra1Dim, const int MatBra2Dim);
298 
299 
301 void contract3(const Ref<DistArray4>& ijxy, const RefSCMatrix& T, Ref<DistArray4>& ijzy);
302 
304 void contract4(const Ref<DistArray4>& ijxy, const RefSCMatrix& T, Ref<DistArray4>& ijxz);
305 
306 
307 
309 RefSCMatrix &
310 operator<<(RefSCMatrix& dst,
311  const Ref<DistArray4>& src);
312 
314 RefSCMatrix &
315 copy_to_RefSCMat(RefSCMatrix& dst,
316  const Ref<DistArray4>& src, const int tensor_type);
317 
318 RefSCMatrix
319 copy_to_RefSCMat(const Ref<DistArray4>& src, int tensor_index);
320 
321 
322 
323 
324 
325 
326 
327 namespace detail {
328 
341  void store_memorygrp(Ref<DistArray4>& acc, Ref<MemoryGrp>& mem, int i_offset,
342  int ni, const size_t blksize_memgrp = 0);
343 
347  void restore_memorygrp(Ref<DistArray4>& acc, Ref<MemoryGrp>& mem, int i_offset,
348  int ni, DistArray4Storage storage, const size_t blksize_memgrp = 0);
349 
350 }
351 
352 }
353 
354 #endif
355 
356 // Local Variables:
357 // mode: c++
358 // c-file-style: "CLJ"
359 // End:
sc::contract_DA4_RefMat_k2b2_34
void contract_DA4_RefMat_k2b2_34(Ref< DistArray4 > &braket, double scale, const Ref< DistArray4 > &bra, unsigned int intsetidx_bra, const RefSCMatrix &ket, const int MatBra1Dim, const int MatBra2Dim)
Contract X^Aj_ik = DA^Ax_iy * M^jk_xy; This is written for spin free[2]R12, where rdm matrices can be...
sc::DistArray4::clone
virtual Ref< DistArray4 > clone(const DistArray4Dimensions &dim=DistArray4Dimensions::default_dim())=0
how to clone.
sc::extract
Ref< DistArray4 > extract(const Ref< DistArray4 > &A, unsigned int te_type, double scale=1.0)
extracts te_type from A
sc::DistArray4::nj
int nj() const
Rank of index space j.
Definition: distarray4.h:116
sc::DistArray4::tasks_with_access
int tasks_with_access(std::vector< int > &twa_map) const
Returns the total number of tasks with access to integrals.
sc::contract3
void contract3(const Ref< DistArray4 > &ijxy, const RefSCMatrix &T, Ref< DistArray4 > &ijzy)
contracts ijxy with T_xz to produce ijzy
sc::DistArray4
DistArray4 contains a set of one or more distributed dense 4-index arrays.
Definition: distarray4.h:94
sc::DistArray4::num_te_types
int num_te_types() const
The number of types of integrals that are being handled together.
Definition: distarray4.h:112
sc::contract34_DA4_RefMat
void contract34_DA4_RefMat(Ref< DistArray4 > &braket, double scale, const Ref< DistArray4 > &bra, unsigned int intsetidx_bra, const RefSCMatrix &ket, const int MatBra1Dim, const int MatBra2Dim)
contracts ijxy("bra") with klxy ("ket", a RefSCMatrix) to produce ijkl ("braket"); The last two argum...
sc::DistArray4::store_pair_block
virtual void store_pair_block(int i, int j, tbint_type oper_type, const double *ints)=0
Stores an ij pair block of integrals.
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::DistArray4::me
int me() const
rank of this task
Definition: distarray4.h:200
sc::DistArray4::store_pair_subblock
virtual void store_pair_subblock(int i, int j, tbint_type oper_type, int xstart, int xfence, int ystart, int yfence, const double *ints)=0
Stores an rectangular subblock of ij block of integrals.
sc::symmetrize
void symmetrize(const Ref< GPetiteList2 > &plist2, const Ref< Integral > &integral, const RefSymmSCMatrix &skel, const RefSymmSCMatrix &sym)
Uses plist2 to convert the "skeleton" matrix into the full matrix. Only applicable when the two basis...
sc::DistArray4::release_pair_block
virtual void release_pair_block(int i, int j, tbint_type oper_type) const =0
Releases the buffer that holds ij block of integrals. If it was allocated by DistArray4,...
sc::DistArray4::deactivate
virtual void deactivate()
call this after operations on this object are finished. May destroy data (see data_persistent()).
Definition: distarray4.h:131
sc::DistArray4::ny
int ny() const
Rank of index space y.
Definition: distarray4.h:120
sc::DistArray4::ntasks
int ntasks() const
total number of tasks
Definition: distarray4.h:198
sc::StateIn
Definition: statein.h:79
sc::permute23
Ref< DistArray4 > permute23(const Ref< DistArray4 > &src)
creates an array in which indices 2 and 3 are permuted
sc::DistArray4::has_access
virtual bool has_access(int proc) const =0
Does this task have access to all blocks?
sc::DistArray4::retrieve_pair_block
virtual const double * retrieve_pair_block(int i, int j, tbint_type oper_type, double *buf=0) const =0
Retrieves an ij block of integrals.
sc::contract4
void contract4(const Ref< DistArray4 > &ijxy, const RefSCMatrix &T, Ref< DistArray4 > &ijxz)
contracts ijxy with T_yz to produce ijxz
sc::DistArray4::is_local
virtual bool is_local(int i, int j) const =0
Is this block stored locally? If true, this implies that it can be retrieved efficiently (compare to ...
sc::operator<<
std::vector< unsigned int > operator<<(const GaussianBasisSet &B, const GaussianBasisSet &A)
computes a map from basis functions in A to the equivalent basis functions in B.
sc::DistArray4::storage
const DistArray4Storage & storage() const
physical storage of the integrals. The default storage is XY. Storage is not mutable.
Definition: distarray4.h:122
sc::StateOut
Definition: stateout.h:71
sc::copy_to_RefSCMat
RefSCMatrix & copy_to_RefSCMat(RefSCMatrix &dst, const Ref< DistArray4 > &src, const int tensor_type)
copy a specific tensor to RefSCMatrix
sc::permute12
Ref< DistArray4 > permute12(const Ref< DistArray4 > &src)
creates an array in which indices 1 and 2 are permuted
sc::DistArray4::data_persistent
virtual bool data_persistent() const =0
if this returns false, call to deactivate may destroy data
sc::DistArray4::ni
int ni() const
Rank of index space i.
Definition: distarray4.h:114
sc::DistArray4::tbint_type
unsigned int tbint_type
Types of two-body operators that DistArray4 understands.
Definition: distarray4.h:108
sc::DistArray4Dimensions
Definition: distarray4.h:43
sc::contract_DA4_RefMat_k1b2_34
void contract_DA4_RefMat_k1b2_34(Ref< DistArray4 > &braket, double scale, const Ref< DistArray4 > &bra, unsigned int intsetidx_bra, const RefSCMatrix &ket, const int MatBra1Dim, const int MatBra2Dim)
Contract X^Aj_ik = DA^Ax_yi * M^jk_xy; procedure: DA'^Ax_iy <- DA^Ax_yi from permute34 DA''^Ai_xy <- ...
sc::permute34
Ref< DistArray4 > permute34(const Ref< DistArray4 > &src)
creates an array in which indices 3 and 4 are permuted
sc::SavableState
Base class for objects that can save/restore state.
Definition: state.h:45
sc::DistArray4::is_avail
virtual bool is_avail(int i, int j) const =0
Can this block be accessed via retrieve_pair_block from this task?
sc::DistArray4::retrieve_pair_subblock
virtual void retrieve_pair_subblock(int i, int j, tbint_type oper_type, int xstart, int xfence, int ystart, int yfence, double *buf) const =0
Retrieves a rectangular subblock of ij block of integrals.
sc::operator==
bool operator==(const Atom &a, const Atom &b)
sc::antisymmetrize
void antisymmetrize(RefSCMatrix &Aanti, const RefSCMatrix &A, const Ref< OrbitalSpace > &bra, const Ref< OrbitalSpace > &ket, bool accumulate=false)
Antisymmetrizes 4-index quantity <ij|A|kl> -> <ij|A|kl> - <ij|A|lk> and saves to Aanti.
sc::DistArray4::nx
int nx() const
Rank of index space x.
Definition: distarray4.h:118
sc::contract34
void contract34(Ref< DistArray4 > &braket, double scale, const Ref< DistArray4 > &bra, unsigned int intsetidx_bra, const Ref< DistArray4 > &ket, unsigned int intsetidx_ket, int debug=0)
contracts ijxy ("bra") with klxy ("ket") to produce ijkl ("braket")
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::DistArray4::classdebug
int classdebug() const
return debug level for this class
Definition: distarray4.h:202
sc::DistArray4::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::DistArray4::activate
virtual void activate()
call this before operations on this object can begin
Definition: distarray4.h:129
sc::axpy
void axpy(const Ref< DistArray4 > &X, double a, const Ref< DistArray4 > &Y, double scale=1.0)
axpy followed by scaling: Y += a*X; Y *= scale.
sc::DistArray4::blocksize
size_t blocksize() const
Size of each block of the integrals of one type, in double words.
Definition: distarray4.h:124

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