MPQC  3.0.0-alpha
fockbuild.h
1 //
2 // fockbuild.h --- a generic Fock matrix builder
3 //
4 // Based on code gbuild.h:
5 // Copyright (C) 1996 Limit Point Systems, Inc.
6 //
7 // Author: Curtis Janssen <cljanss@ca.sandia.gov>
8 // Maintainer: SNL
9 //
10 // This file is part of the SC Toolkit.
11 //
12 // The SC Toolkit is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Library General Public License as published by
14 // the Free Software Foundation; either version 2, or (at your option)
15 // any later version.
16 //
17 // The SC Toolkit is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Library General Public License for more details.
21 //
22 // You should have received a copy of the GNU Library General Public License
23 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
24 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 //
26 // The U.S. Government is granted a limited license as per AL 91-7.
27 //
28 
29 #ifndef _chemistry_qc_lcao_fockbuild_h
30 #define _chemistry_qc_lcao_fockbuild_h
31 
32 #include <mpqc_config.h>
33 #include <util/misc/regtime.h>
34 #include <util/group/thread.h>
35 #include <util/group/message.h>
36 #include <chemistry/qc/basis/integral.h>
37 
38 #include <util/group/actmsg.h>
39 #include <chemistry/qc/lcao/fockdist.h>
40 
41 namespace sc {
42 
43 class FockBuildMatrix: public RefCount {
44  private:
45  void operator = (const FockBuildMatrix&) {}
46  FockBuildMatrix() {}
47  protected:
48  Ref<MessageGrp> msg_;
49  int nI_, nJ_;
50  int nproc_;
51  int me_;
52 
53  Ref<FockBlocks> blocks1_;
54  Ref<FockBlocks> blocks2_;
55  public:
57  FockBuildMatrix(const Ref<MessageGrp> &msg);
58 
59  const Ref<MessageGrp> &messagegrp() const { return msg_; }
60 
61  inline int block_offset(int I, int J) const {
62  if (!symmetric()) {
63  return I * blocks2_->nblock() + J;
64  }
65  else {
66  if (J > I) {
67  std::cout << "shell_block_offset: noncanonical indices: "
68  << I << ", " << J << std::endl;
69  abort();
70  }
71  return (I*(I+1))/2 + J;
72  }
73  }
74  inline int n_block() const {
75  if (!symmetric()) {
76  return blocks1_->nblock() * blocks2_->nblock();
77  }
78  else {
79  return (blocks1_->nblock()*(blocks1_->nblock()+1))/2;
80  }
81  }
82  inline int block_owning_proc(int I, int J) const {
83  return block_offset(I,J)%nproc_;
84  }
85  inline bool block_is_owner(int I, int J) const {
86  return block_owning_proc(I,J) == me_;
87  }
88 
89  inline int shell_block_offset(int I, int J) const {
90  if (!symmetric()) {
91  return I * nJ_ + J;
92  }
93  else {
94  if (J > I) {
95  std::cout << "shell_block_offset: noncanonical indices: "
96  << I << ", " << J << std::endl;
97  abort();
98  }
99  return (I*(I+1))/2 + J;
100  }
101  }
102  inline int n_shell_block() const {
103  if (!symmetric()) {
104  return nI_ * nJ_;
105  }
106  else {
107  return (nI_*(nI_+1))/2;
108  }
109  }
110  inline int shell_block_owning_proc(int I, int J) const {
111  return block_owning_proc(blocks1_->shell_to_block(I),
112  blocks2_->shell_to_block(J));
113  }
114  inline bool shell_block_is_owner(int I, int J) const {
115  return shell_block_owning_proc(I,J) == me_;
116  }
117 
118  virtual bool symmetric() const = 0;
119  // This will average the off diagonal elements in each
120  // diagonal block, iff the matrix is symmetric.
121  virtual void fix_diagonal_blocks() const = 0;
122  virtual void clear() = 0;
123  // These allocate data to hold the SCMatrix. The data is only
124  // copied if copy is true, otherwise it is zeroed.
125  virtual void scmat_to_data(const RefSymmSCMatrix &m,
126  const Ref<GaussianBasisSet> &b, bool copy) = 0;
127  virtual void scmat_to_data(const RefSCMatrix &m,
128  const Ref<GaussianBasisSet> &b1,
129  const Ref<GaussianBasisSet> &b2, bool copy) = 0;
130  // This copies the held data back into the SCMatrix.
131  virtual void data_to_scmat() const = 0;
132  virtual void prefetch_block(int I, int J, int ifetch, int nfetch) = 0;
133  virtual void finish_prefetch_block() = 0;
134  virtual double *shell_block(int Ish, int Jsh) const = 0;
135  virtual double *block(int Ish, int Jsh) const = 0;
136  virtual FockBuildMatrix *copy(int unique_id,
137  bool copy_data = false) const = 0;
139  virtual void zero_data() = 0;
141  virtual void accum(const Ref<FockBuildMatrix> &fbm) = 0;
143  virtual void accum_remote(const Ref<MessageGrp> &) = 0;
145  virtual void print() const;
147  virtual void flush();
148 
149  virtual void set_fockblocks(const Ref<FockBlocks> &b1,
150  const Ref<FockBlocks> &b2);
151 
152  const Ref<FockBlocks> &blocks1() { return blocks1_; }
153  const Ref<FockBlocks> &blocks2() { return blocks2_; }
154 
155 };
156 
158  double **blockpointers_;
161  RefSCMatrix rectmat_;
162  RefSymmSCMatrix symmmat_;
163  int ndata_;
166  bool owns_data_;
167 
168  void data_to_symmat() const;
169  void data_to_rectmat() const;
170  public:
173  bool copy_data = false);
175  bool symmetric() const;
176  void fix_diagonal_blocks() const;
177  void clear();
178  void scmat_to_data(const RefSymmSCMatrix &m,
179  const Ref<GaussianBasisSet> &b, bool copy);
180  void scmat_to_data(const RefSCMatrix &m,
181  const Ref<GaussianBasisSet> &b1,
182  const Ref<GaussianBasisSet> &b2, bool copy);
183  void data_to_scmat() const;
184  void prefetch_block(int I, int J, int ifetch, int nfetch);
185  void finish_prefetch_block();
186  double *shell_block(int Ish, int Jsh) const;
187  double *block(int Ish, int Jsh) const;
188  FockBuildMatrix *copy(int unique_id, bool copy_data = false) const;
189  void zero_data();
190  void accum(const Ref<FockBuildMatrix> &fbm);
191  void accum_remote(const Ref<MessageGrp> &);
192  virtual void print() const;
193 };
194 
195 class FockContribution;
196 
199  Ref<MessageGrp> return_msg_;
200  public:
201  FockBuildAMG(const Ref<MessageGrp>& msg,
202  const Ref<ThreadGrp>& thr,
203  const Ref<FockContribution>& fc);
204  const Ref<FockContribution> &contrib() const {
205  return fc_;
206  }
207  const Ref<MessageGrp> &return_messagegrp() const {
208  return return_msg_;
209  }
210 };
211 
212 class FockBuildAM: public ActiveMessage {
213  protected:
214  int matrix_, I_, J_, nIJ_;
215  double *data_;
216  int use_shell_blocks_;
217  public:
218  FockBuildAM(int matrix);
219  ~FockBuildAM();
220  virtual FockBuildAM* copy() = 0;
221  FockBuildAM(StateIn &s);
222  void save_data_state(StateOut &s);
223  void set_info(int I, int J, int nIJ, double *data,
224  bool use_shell_blocks) {
225  I_ = I;
226  J_ = J;
227  nIJ_ = nIJ;
228  data_ = data;
229  use_shell_blocks_ = use_shell_blocks;
230  }
231 };
232 
233 class FockBuildOp: public RefCount {
234  private:
235  int msg_type_;
236  bool need_read_;
237  bool need_write_;
238  bool use_shell_blocks_;
239  Ref<FockBuildAMG> fbamg_;
240  Ref<FockBuildAM> fbam_;
241  Ref<StateSend> statesend_;
242  public:
243  FockBuildOp(int unique_id,
244  bool need_read,
245  bool need_write,
246  bool use_shell_blocks,
247  const Ref<FockBuildAMG> &fbamg,
248  const Ref<FockBuildAM>& fbam);
249  void process_write(int node, int I, int J, int nIJ, double *data);
250  void process_read(int node, int I, int J, int nIJ, double *data);
251  void begin_prefetch(int node, int I, int J, int nIJ, int ifetch, int nfetch,
252  double *data, MessageGrp::MessageHandle &mh);
253  void finish_prefetch(MessageGrp::MessageHandle &mh);
254  bool need_read() const { return need_read_; }
255  bool need_write() const { return need_write_; }
256  FockBuildOp *copy(int unique_id) const;
257  Ref<MessageGrp> messagegrp() const {
258  return fbamg_->messagegrp();
259  }
260  Ref<MessageGrp> return_messagegrp() const {
261  return fbamg_->return_messagegrp();
262  }
263 };
264 
266  double **blockpointers_;
269  RefSCMatrix rectmat_;
270  RefSymmSCMatrix symmmat_;
271  int ndata_;
274  bool owns_data_;
275 
276  bool prefetch_blocks_;
277 
278  Ref<FockBuildOp> fockbuildop_;
279 
280  class IJ_t {
281  uint64_t ij_;
282  public:
283  IJ_t(const IJ_t&IJ) { ij_ = IJ.ij_; }
284  IJ_t(int i, int j) { ij_ = uint64_t(i)<<32|j; }
285  int i() const { return ij_>>32; }
286  int j() const { return ij_&0xffffffff; }
287  bool operator < (const IJ_t&IJ) const { return ij_ < IJ.ij_; }
288  bool operator > (const IJ_t&IJ) const { return ij_ > IJ.ij_; }
289  bool operator >= (const IJ_t&IJ) const { return ij_ >= IJ.ij_; }
290  bool operator <= (const IJ_t&IJ) const { return ij_ <= IJ.ij_; }
291  bool operator == (const IJ_t&IJ) const { return ij_ == IJ.ij_; }
292  void operator = (const IJ_t&IJ) { ij_ = IJ.ij_; }
293  };
294  typedef std::pair<double*,MessageGrp::MessageHandle> FetchData_t;
295 
296  mutable std::map<IJ_t,FetchData_t> prefetched_block_cache_;
297  mutable std::map<IJ_t,double*> block_cache_;
298  mutable std::map<IJ_t,double*> shell_block_cache_;
299 
300  std::map<IJ_t,double*> local_blocks_;
301  std::map<IJ_t,double*> local_shell_blocks_;
302 
303  void clear_cache();
304 
305  void data_to_symmat() const;
306  void data_to_rectmat() const;
307 
308  double *fetch_block(int I, int J) const;
309  int block_size(int iblock, int jblock) const;
310  void insert_shell_block_pointers(int iblock,int jblock,
311  double *data,
312  std::map<IJ_t,double*> &) const;
313  void blockpointers_to_local_blocks();
314  void local_blocks_to_blockpointers() const;
315  public:
316  DistFockBuildMatrix(bool prefetch_blocks,
317  const Ref<FockBuildOp> &fockbuildop);
319  int unique_id,
320  bool copy_data = false);
322  bool symmetric() const;
323  void fix_diagonal_blocks() const;
324  void clear();
325  void scmat_to_data(const RefSymmSCMatrix &m,
326  const Ref<GaussianBasisSet> &b, bool copy);
327  void scmat_to_data(const RefSCMatrix &m,
328  const Ref<GaussianBasisSet> &b1,
329  const Ref<GaussianBasisSet> &b2, bool copy);
330  void data_to_scmat() const;
331  void prefetch_block(int I, int J, int ifetch, int nfetch);
332  void finish_prefetch_block();
333  double *shell_block(int Ish, int Jsh) const;
334  double *block(int Ish, int Jsh) const;
335  FockBuildMatrix *copy(int unique_id, bool copy_data = false) const;
336  void zero_data();
337  void accum(const Ref<FockBuildMatrix> &fbm);
338  void accum_remote(const Ref<MessageGrp> &);
339  void flush();
340 };
341 
342 class FockContribution: public RefCount {
343  protected:
344  double nint_;
345  public:
348  virtual ~FockContribution();
354  virtual void contrib_e_J(double factor,
355  int I, int J, int K, int L,
356  int nI, int nJ, int nK, int nL,
357  const double * RESTRICT buf) = 0;
362  virtual void contrib_e_K(double factor,
363  int I, int J, int K, int L,
364  int nI, int nJ, int nK, int nL,
365  const double * RESTRICT buf) = 0;
366  virtual void contrib_p12_p13p24_J(double factor,
367  int I, int J, int K, int L,
368  int nI, int nJ, int nK, int nL,
369  const double * RESTRICT buf) = 0;
370  virtual void contrib_p12_p13p24_K(double factor,
371  int I, int J, int K, int L,
372  int nI, int nJ, int nK, int nL,
373  const double * RESTRICT buf) = 0;
374  virtual void contrib_p34_p13p24_J(double factor,
375  int I, int J, int K, int L,
376  int nI, int nJ, int nK, int nL,
377  const double * RESTRICT buf) = 0;
378  virtual void contrib_p34_p13p24_K(double factor,
379  int I, int J, int K, int L,
380  int nI, int nJ, int nK, int nL,
381  const double * RESTRICT buf) = 0;
382  virtual void contrib_p12_p34_J(double factor,
383  int I, int J, int K, int L,
384  int nI, int nJ, int nK, int nL,
385  const double * RESTRICT buf) = 0;
386  virtual void contrib_p12_p34_K(double factor,
387  int I, int J, int K, int L,
388  int nI, int nJ, int nK, int nL,
389  const double * RESTRICT buf) = 0;
390  virtual void contrib_p34_J(double factor,
391  int I, int J, int K, int L,
392  int nI, int nJ, int nK, int nL,
393  const double * RESTRICT buf) = 0;
394  virtual void contrib_p34_K(double factor,
395  int I, int J, int K, int L,
396  int nI, int nJ, int nK, int nL,
397  const double * RESTRICT buf) = 0;
398  virtual void contrib_p13p24_J(double factor,
399  int I, int J, int K, int L,
400  int nI, int nJ, int nK, int nL,
401  const double * RESTRICT buf) = 0;
402  virtual void contrib_p13p24_K(double factor,
403  int I, int J, int K, int L,
404  int nI, int nJ, int nK, int nL,
405  const double * RESTRICT buf) = 0;
406  virtual void contrib_all_J(double factor,
407  int I, int J, int K, int L,
408  int nI, int nJ, int nK, int nL,
409  const double * RESTRICT buf) = 0;
410  virtual void contrib_all_K(double factor,
411  int I, int J, int K, int L,
412  int nI, int nJ, int nK, int nL,
413  const double * RESTRICT buf) = 0;
414  virtual Ref<FockContribution> clone() = 0;
415 
416  virtual void set_fmat(int i, const RefSCMatrix &) = 0;
417  virtual void set_fmat(int i, const RefSymmSCMatrix &) = 0;
418 
419  virtual void set_jmat(int i, const RefSCMatrix &) = 0;
420  virtual void set_jmat(int i, const RefSymmSCMatrix &) = 0;
421 
422  virtual void set_kmat(int i, const RefSCMatrix &) = 0;
423  virtual void set_kmat(int i, const RefSymmSCMatrix &) = 0;
424 
425  virtual void set_pmat(int i, const RefSymmSCMatrix &) = 0;
426 
427  virtual double *jmat_shell_block(int i, int Ish, int Jsh) = 0;
428  virtual double *kmat_shell_block(int i, int Ish, int Jsh) = 0;
429  virtual const double *pmat_shell_block(int i, int Ish, int Jsh) = 0;
430 
431  virtual double *jmat_block(int i, int Ish, int Jsh) = 0;
432  virtual double *kmat_block(int i, int Ish, int Jsh) = 0;
433  virtual const double *pmat_block(int i, int Ish, int Jsh) = 0;
434 
437  virtual signed char *compute_pmax() const = 0;
438 
440  virtual void copy_matrices(int unique_id) = 0;
445  virtual void accum(const Ref<FockContribution> &) = 0;
449  virtual void accum_remote(const Ref<MessageGrp> &) = 0;
451  virtual void update() = 0;
452 
453  double nint() const { return nint_; }
454  double &nint() { return nint_; }
455 
456  virtual void activate() = 0;
457  virtual void sync() = 0;
458  virtual void deactivate() = 0;
459 
460  virtual void flush() = 0;
461 
462  virtual void prefetch_blocks(int I, int J, int ifetch, int nfetch) = 0;
463  virtual void finish_prefetch_blocks() = 0;
464 
465  virtual void set_fockblocks(const Ref<FockBlocks> &blocks_f1,
466  const Ref<FockBlocks> &blocks_f2,
467  const Ref<FockBlocks> &blocks_p) = 0;
468 
469  virtual Ref<ThreadLock> &get_lock(int i, int I, int J) = 0;
470 };
471 
492  protected:
493  int nfmat_;
494  std::vector<Ref<FockBuildMatrix> > jmats_;
495  std::vector<Ref<FockBuildMatrix> > kmats_;
496  std::vector<bool> k_is_j_;
497  int npmat_;
498  std::vector<Ref<FockBuildMatrix> > pmats_;
499  Ref<GaussianBasisSet> f_b1_, f_b2_, p_b_;
500  bool f_b1_equiv_f_b2;
501  int nlocks_;
502  std::vector<Ref<ThreadLock> > locks_;
503  std::string fockbuildmatrixtype_;
504  bool use_shell_blocks_;
505 
506  Ref<FockBuildAMG> fbamg_;
507 
508  FockBuildMatrix *fockbuildmatrix(int matrix,
509  const std::string &type,
510  const Ref<MessageGrp> &msg,
511  const Ref<FockBuildAMG> &);
512 
513  class JLocator {
514  public:
515  double *operator()(GenericFockContribution *owner,
516  int i, int I, int J) {
517  return owner->jmat_shell_block(i,I,J);
518  }
519  };
520 
521  class KLocator {
522  public:
523  double *operator()(GenericFockContribution *owner,
524  int i, int I, int J) {
525  return owner->kmat_shell_block(i,I,J);
526  }
527  };
528 
529  template <class Locator>
530  class JKBlock {
531  GenericFockContribution *owner_;
532  double *data_;
533  int i_, I_, J_, nIJ_;
534  public:
536  int i, int I, int J, int nI, int nJ) {
537  i_ = i;
538  I_ = I;
539  J_ = J;
540  nIJ_ = nI*nJ;
541  owner_ = owner;
542  data_ = owner_->alloc_scratch(nIJ_);
543  }
544  ~JKBlock() {
545  Locator l;
546  int ilock, jlock;
547  if (owner_->use_shell_blocks()) {
548  ilock = I_;
549  jlock = J_;
550  }
551  else {
552  ilock = owner_->jmat(i_)->blocks1()->shell_to_block(I_);
553  jlock = owner_->jmat(i_)->blocks2()->shell_to_block(J_);
554  }
555  const Ref<ThreadLock> &lock(
556  owner_->get_lock(i_,ilock,jlock));
557  lock->lock();
558  double *real_data = l(owner_,i_,I_,J_);
559 // std::cout << MessageGrp::get_default_messagegrp()->me()
560 // << ": writing back F block " << I_ << " " << J_
561 // << ": contrib[0] = " << data_[0]
562 // << " @ " << data_
563 // << " oldvalue[0] = " << real_data[0]
564 // << " @ " << real_data
565 // << " summedvalue[0] = " << real_data[0] + data_[0]
566 // << std::endl;
567  for (int i=0; i<nIJ_; i++) {
568 // std::cout << " data_[" << i << "] = "
569 // << scprintf("%12.9f", data_[i])
570 // << std::endl;
571  real_data[i] += data_[i];
572  }
573 // for (int i=0; i<nIJ_; i++) {
574 // std::cout << " real_data[" << i << "] = "
575 // << scprintf("%12.9f", real_data[i])
576 // << std::endl;
577 // }
578  lock->unlock();
579  owner_->free_scratch(data_);
580  }
581  double *data() { return data_; }
582  };
583 
584  class PBlock {
585  GenericFockContribution *owner_;
586  const double *data_;
587  public:
589  int i, int I, int J, int nI, int nJ) {
590  owner_ = owner;
591  data_ = owner_->pmat_shell_block(i,I,J);
592  }
593  ~PBlock() {}
594  const double *data() { return data_; }
595  };
596 
597  GenericFockContribution(int nfmat, int npmat,
598  const Ref<GaussianBasisSet> &f_b1,
599  const Ref<GaussianBasisSet> &f_b2,
600  const Ref<GaussianBasisSet> &p_b,
601  const std::string &fockbuildmatrixtype);
602 
603  void pmax_contrib(const Ref<FockBuildMatrix> &mat,
604  signed char *pmax) const;
605 
606  public:
607  double *jmat_shell_block(int i, int I, int J) {
608  return jmats_[i]->shell_block(I,J);
609  }
610  bool jmat_symmetric(int i) const { return jmats_[i]->symmetric(); }
611  double *kmat_shell_block(int i, int I, int J) {
612  return kmats_[i]->shell_block(I,J);
613  }
614  bool kmat_symmetric(int i) const { return kmats_[i]->symmetric(); }
615  const double *pmat_shell_block(int i, int I, int J) {
616  return pmats_[i]->shell_block(I,J);
617  }
618 
619  double *jmat_block(int i, int I, int J) {
620  return jmats_[i]->block(I,J);
621  }
622  double *kmat_block(int i, int I, int J) {
623  return kmats_[i]->block(I,J);
624  }
625  const double *pmat_block(int i, int I, int J) {
626  return pmats_[i]->block(I,J);
627  }
628 
629  Ref<ThreadLock> &get_lock(int i, int Ish, int Jsh) {
630  int hash = (i+(Ish+1)*(Jsh+1))%nlocks_;
631  return locks_[hash];
632  }
633 
634  double *alloc_scratch(int size) {
635  double *data = new double[size];
636  memset(data,0,sizeof(double)*size);
637  return data;
638  }
639 
640  void free_scratch(double *data) {
641  delete[] data;
642  }
643 
644  void set_fmat(int i, const RefSCMatrix &);
645  void set_fmat(int i, const RefSymmSCMatrix &);
646 
647  void set_jmat(int i, const RefSCMatrix &);
648  void set_jmat(int i, const RefSymmSCMatrix &);
649 
650  void set_kmat(int i, const RefSCMatrix &);
651  void set_kmat(int i, const RefSymmSCMatrix &);
652 
653  void set_pmat(int i, const RefSymmSCMatrix &);
654 
655  void copy_matrices(int unique_id);
656  void accum(const Ref<FockContribution> &);
657  void accum_remote(const Ref<MessageGrp> &);
658  void update();
659 
660  signed char* compute_pmax() const;
661 
662  ~GenericFockContribution();
663 
664  void activate();
665  void sync();
666  void deactivate();
667 
668  void prefetch_blocks(int I, int J, int ifetch, int nfetch);
669  void finish_prefetch_blocks();
670 
671  void set_fockblocks(const Ref<FockBlocks> &blocks_f1,
672  const Ref<FockBlocks> &blocks_f2,
673  const Ref<FockBlocks> &blocks_p);
674 
675  void flush();
676 
677  const Ref<FockBuildMatrix> &jmat(int i) { return jmats_[i]; }
678  const Ref<FockBuildMatrix> &kmat(int i) { return kmats_[i]; }
679  const Ref<FockBuildMatrix> &pmat(int i) { return pmats_[i]; }
680 
681  bool use_shell_blocks() const { return use_shell_blocks_; }
682 };
683 
687 class FockBuildThread : public Thread {
688  protected:
689  Ref<FockDistribution> fockdist_;
690  Ref<FockContribution> contrib_;
691  Ref<ThreadLock> lock_;
692  Ref<Integral> integral_;
693  double accuracy_;
694  Ref<MessageGrp> msg_;
695  int nthread_;
696  int threadnum_;
697  const signed char *pmax_;
698  Ref<RegionTimer> timer_;
699  bool prefetch_blocks_;
700  bool compute_J_;
701  bool compute_K_;
702  double coef_K_;
703 
704  int can_sym_offset(int i, int j) { return (i*(i+1))/2 + j; }
705  int gen_sym_offset(int i, int j) {
706  if (i>=j) { return can_sym_offset(i,j); }
707  else { return can_sym_offset(j,i); }
708  }
709  public:
711  FockBuildThread(const Ref<FockDistribution> &fockdist,
712  const Ref<MessageGrp> &msg,
713  int nthread,
714  int threadnum,
715  bool prefetch_blocks,
716  const Ref<ThreadLock> &lock,
717  const Ref<Integral> &integral,
718  bool compute_J,
719  bool compute_K,
720  double coef_K);
721  void set_contrib(const Ref<FockContribution>&c) { contrib_ = c; }
722  void set_accuracy(double acc) { accuracy_ = acc; }
723  void set_compute_J(bool compute_J) { compute_J_ = compute_J; }
724  void set_compute_K(bool compute_K) { compute_K_ = compute_K; }
725  void set_coef_K(double coef_K) { coef_K_ = coef_K; }
726  void set_pmax(const signed char *pmax) { pmax_ = pmax; }
727  const Ref<RegionTimer> get_timer() const { return timer_; }
728 };
729 
734  Ref<GaussianBasisSet> basis_;
735  Ref<FockBlocks> blocks_;
736  Ref<PetiteList> pl_;
737  Ref<TwoBodyInt> eri_;
738  void prefetch_blocks(const Ref<FockDist> &dist,
739  int iblock, int jblock, int kblock, int lblock);
740  public:
743  const Ref<MessageGrp> &msg,
744  int nthread,
745  int threadnum,
746  bool prefetch_blocks,
747  const Ref<ThreadLock> &lock,
748  const Ref<Integral> &integral,
749  const Ref<PetiteList> &pl,
750  const Ref<GaussianBasisSet> &basis1,
751  const Ref<GaussianBasisSet> &basis2/*not used*/,
752  const Ref<GaussianBasisSet> &basis3/*not used*/,
753  const Ref<FockBlocks> &blocks1,
754  const Ref<FockBlocks> &blocks2/*not used*/,
755  const Ref<FockBlocks> &blocks3/*not used*/,
756  bool compute_J,
757  bool compute_K,
758  double coef_K);
759  void run();
760 };
761 
766  Ref<GaussianBasisSet> basis1_;
767  Ref<GaussianBasisSet> basis2_;
768  Ref<GaussianBasisSet> basis3_;
769  Ref<PetiteList> pl_;
770 
771  void run_J();
772  void run_K();
773 
774  Ref<TwoBodyInt> eri_J_;
775  Ref<TwoBodyInt> eri_K_;
776 
777  public:
780  const Ref<MessageGrp> &msg,
781  int nthread,
782  int threadnum,
783  bool prefetch_blocks,
784  const Ref<ThreadLock> &lock,
785  const Ref<Integral> &integral,
786  const Ref<PetiteList> &pl,
787  const Ref<GaussianBasisSet> &basis1,
788  const Ref<GaussianBasisSet> &basis2,
789  const Ref<GaussianBasisSet> &basis3,
790  const Ref<FockBlocks> &blocks1,
791  const Ref<FockBlocks> &blocks2,
792  const Ref<FockBlocks> &blocks3,
793  bool compute_J,
794  bool compute_K,
795  double coef_K);
796  void run();
797 };
798 
805 class FockBuild: public RefCount {
806  Ref<FockDistribution> fockdist_;
807  Ref<FockContribution> contrib_;
808  Ref<GaussianBasisSet> b_f1_;
809  Ref<GaussianBasisSet> b_f2_;
811  Ref<MessageGrp> msg_;
812  Ref<ThreadGrp> thr_;
813  Ref<Integral> integral_;
814  double accuracy_;
815  Ref<PetiteList> pl_;
816  bool prefetch_blocks_;
817 
818  Ref<FockBlocks> fb_f1_;
819  Ref<FockBlocks> fb_f2_;
820  Ref<FockBlocks> fb_p_;
821 
822  bool compute_J_;
823  bool compute_K_;
824  double coef_K_;
825 
826  typedef FockBuildThread* (*FBT_CTOR)(const Ref<FockDistribution> &fockdist,
827  const Ref<MessageGrp> &msg,
828  int nthread,
829  int threadnum,
830  bool prefetch_blocks,
831  const Ref<ThreadLock> &lock,
832  const Ref<Integral> &integral,
833  const Ref<PetiteList> &pl,
834  const Ref<GaussianBasisSet> &basis1,
835  const Ref<GaussianBasisSet> &basis2,
836  const Ref<GaussianBasisSet> &basis3,
837  const Ref<FockBlocks> &blocks1,
838  const Ref<FockBlocks> &blocks2,
839  const Ref<FockBlocks> &blocks3,
840  bool compute_J,
841  bool compute_K,
842  double coef_K);
843 
844 
845  // Build for the any case. The thread constructing function is passed in.
846  FockBuildThread **thread_;
847  void init_threads(FBT_CTOR);
848  void init_threads();
849  void done_threads();
850 
851  public:
860  FockBuild(const Ref<FockDistribution> &fockdist,
861  const Ref<FockContribution> &contrib,
862  bool prefetch_blocks,
863  const Ref<GaussianBasisSet> &b_f1,
864  const Ref<GaussianBasisSet> &b_f2 = 0,
865  const Ref<GaussianBasisSet> &b_p = 0,
869  virtual ~FockBuild();
870 
872  void build();
873 
874  const Ref<FockContribution> &contrib() const { return contrib_; }
875  void set_accuracy(double acc) { accuracy_ = acc; }
876 
877  void set_compute_J(bool compute_J) { compute_J_ = compute_J; }
878  void set_compute_K(bool compute_K) { compute_K_ = compute_K; }
879  void set_coef_K(double coef_K) { coef_K_ = coef_K; }
880  bool compute_J() const { return compute_J_; }
881  bool compute_K() const { return compute_K_; }
882  double coef_K() const { return coef_K_; }
883 };
884 
885 }
886 
887 #endif
888 
889 // Local Variables:
890 // mode: c++
891 // c-file-style: "CLJ"
892 // End:
sc::MessageGrp::get_default_messagegrp
static MessageGrp * get_default_messagegrp()
Returns the default message group.
sc::GenericFockContribution::copy_matrices
void copy_matrices(int unique_id)
Copy matrices to allow multiple threads to coexist.
sc::RefSymmSCMatrix
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition: matrix.h:265
sc::GenericFockContribution
The GenericFockContribution class provides much of the infrastructure needed by FockContribution spec...
Definition: fockbuild.h:491
sc::FockBuildThread::FockBuildThread
FockBuildThread(const Ref< FockDistribution > &fockdist, const Ref< MessageGrp > &msg, int nthread, int threadnum, bool prefetch_blocks, const Ref< ThreadLock > &lock, const Ref< Integral > &integral, bool compute_J, bool compute_K, double coef_K)
Each thread must be given a unique contribution, c.
sc::FockBuildThread
The FockBuildThread class is used to actually build the Fock matrix.
Definition: fockbuild.h:687
sc::MessageGrp::MessageHandle
Definition: message.h:135
sc::RefSCMatrix
The RefSCMatrix class is a smart pointer to an SCMatrix specialization.
Definition: matrix.h:135
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
mpqc::matrix
Matrix class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:21
sc::DistFockBuildMatrix::flush
void flush()
Flush the buffer cache (if it exists).
sc::Thread
The Thread abstract class defines an interface which must be implemented by classes wishing to be run...
Definition: thread.h:75
sc::DistFockBuildMatrix
Definition: fockbuild.h:265
sc::FockBuildThread_F12_P33::FockBuildThread_F12_P33
FockBuildThread_F12_P33(const Ref< FockDistribution > &fockdist, const Ref< MessageGrp > &msg, int nthread, int threadnum, bool prefetch_blocks, const Ref< ThreadLock > &lock, const Ref< Integral > &integral, const Ref< PetiteList > &pl, const Ref< GaussianBasisSet > &basis1, const Ref< GaussianBasisSet > &basis2, const Ref< GaussianBasisSet > &basis3, const Ref< FockBlocks > &blocks1, const Ref< FockBlocks > &blocks2, const Ref< FockBlocks > &blocks3, bool compute_J, bool compute_K, double coef_K)
Each thread must be given a unique contribution, c.
sc::FockBuildOp
Definition: fockbuild.h:233
sc::GenericFockContribution::KLocator
Definition: fockbuild.h:521
sc::ActiveMessageGrp
ActiveMessageGrp provides an implemention of active messages that sends objects derived from ActiveMe...
Definition: actmsg.h:87
sc::FockBuildAM::save_data_state
void save_data_state(StateOut &s)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::GenericFockContribution::compute_pmax
signed char * compute_pmax() const
Compute the maximum of the density in each block.
sc::FockBuildMatrix::zero_data
virtual void zero_data()=0
Zero out the data.
sc::GenericFockContribution::JKBlock
Definition: fockbuild.h:530
sc::ReplFockBuildMatrix::accum_remote
void accum_remote(const Ref< MessageGrp > &)
Accumulate remote contributions.
sc::GenericFockContribution::accum_remote
void accum_remote(const Ref< MessageGrp > &)
Sum the Fock matrix contributions from different processors.
sc::ActiveMessage
Derivatives of ActiveMessage can be constructed in one process and executed in another by using Activ...
Definition: actmsg.h:46
sc::StateIn
Definition: statein.h:79
sc::FockBuildMatrix::print
virtual void print() const
The default print member does nothing.
sc::FockBuildThread_F12_P33
This is used to build the Fock matrix when none of the basis sets are equivalent.
Definition: fockbuild.h:765
sc::FockContribution::accum
virtual void accum(const Ref< FockContribution > &)=0
Sum the Fock matrix contributions from different threads.
sc::GenericFockContribution::PBlock
Definition: fockbuild.h:584
sc::FockBuildAM
Definition: fockbuild.h:212
sc::FockBuildThread_F11_P11
The FockBuildThread class is used to actually build the Fock matrix.
Definition: fockbuild.h:733
sc::FockContribution::contrib_e_J
virtual void contrib_e_J(double factor, int I, int J, int K, int L, int nI, int nJ, int nK, int nL, const double *RESTRICT buf)=0
This routine does not permute any indices.
sc::FockBuildMatrix::accum_remote
virtual void accum_remote(const Ref< MessageGrp > &)=0
Accumulate remote contributions.
sc::FockContribution
Definition: fockbuild.h:342
sc::Integral::get_default_integral
static Integral * get_default_integral()
Returns the default Integral factory.
sc::FockBuildThread_F11_P11::FockBuildThread_F11_P11
FockBuildThread_F11_P11(const Ref< FockDistribution > &fockdist, const Ref< MessageGrp > &msg, int nthread, int threadnum, bool prefetch_blocks, const Ref< ThreadLock > &lock, const Ref< Integral > &integral, const Ref< PetiteList > &pl, const Ref< GaussianBasisSet > &basis1, const Ref< GaussianBasisSet > &basis2, const Ref< GaussianBasisSet > &basis3, const Ref< FockBlocks > &blocks1, const Ref< FockBlocks > &blocks2, const Ref< FockBlocks > &blocks3, bool compute_J, bool compute_K, double coef_K)
Each thread must be given a unique contribution, c.
sc::FockContribution::copy_matrices
virtual void copy_matrices(int unique_id)=0
Copy matrices to allow multiple threads to coexist.
sc::GenericFockContribution::accum
void accum(const Ref< FockContribution > &)
Sum the Fock matrix contributions from different threads.
sc::ReplFockBuildMatrix::accum
void accum(const Ref< FockBuildMatrix > &fbm)
Accumulate fbm into this.
sc::FockBuild::FockBuild
FockBuild(const Ref< FockDistribution > &fockdist, const Ref< FockContribution > &contrib, bool prefetch_blocks, const Ref< GaussianBasisSet > &b_f1, const Ref< GaussianBasisSet > &b_f2=0, const Ref< GaussianBasisSet > &b_p=0, const Ref< MessageGrp > &msg=MessageGrp::get_default_messagegrp(), const Ref< ThreadGrp > &thr=ThreadGrp::get_default_threadgrp(), const Ref< Integral > &integral=Integral::get_default_integral())
Create a FockBuild object using b_f1 as the Fock matrix row dimension basis, b_f2 as the Fock matrix ...
sc::FockBuildMatrix
Definition: fockbuild.h:43
sc::GenericFockContribution::jmats_
std::vector< Ref< FockBuildMatrix > > jmats_
the number of Fock matrices
Definition: fockbuild.h:494
sc::ReplFockBuildMatrix::print
virtual void print() const
The default print member does nothing.
sc::FockContribution::compute_pmax
virtual signed char * compute_pmax() const =0
Compute the maximum of the density in each block.
sc::FockBuildMatrix::flush
virtual void flush()
Flush the buffer cache (if it exists).
sc::StateOut
Definition: stateout.h:71
sc::DistFockBuildMatrix::accum
void accum(const Ref< FockBuildMatrix > &fbm)
Accumulate fbm into this.
sc::FockBuild
The FockBuild class works with the FockBuildThread class to generate Fock matrices for both closed sh...
Definition: fockbuild.h:805
sc::FockBuild::build
void build()
Contruct the Fock matrices.
mpqc::ci::operator<
bool operator<(const Space< Spin > &a, const Space< Spin > &b)
Compare two spaces by their rank.
Definition: subspace.hpp:44
sc::FockContribution::accum_remote
virtual void accum_remote(const Ref< MessageGrp > &)=0
Sum the Fock matrix contributions from different processors.
sc::GenericFockContribution::update
void update()
Push the internal Fock matrix data back into the original object.
sc::FockBuildThread_F11_P11::run
void run()
This is called with the Thread is run from a ThreadGrp.
sc::GenericFockContribution::JLocator
Definition: fockbuild.h:513
sc::GenericFockContribution::pmats_
std::vector< Ref< FockBuildMatrix > > pmats_
the number of density matrices
Definition: fockbuild.h:498
sc::RefCount
The base class for all reference counted objects.
Definition: ref.h:192
sc::ThreadGrp::get_default_threadgrp
static ThreadGrp * get_default_threadgrp()
Returns the default ThreadGrp.
sc::DistFockBuildMatrix::zero_data
void zero_data()
Zero out the data.
sc::operator==
bool operator==(const Atom &a, const Atom &b)
sc::DistFockBuildMatrix::accum_remote
void accum_remote(const Ref< MessageGrp > &)
Accumulate remote contributions.
sc::FockContribution::update
virtual void update()=0
Push the internal Fock matrix data back into the original object.
sc::FockBuildThread_F12_P33::run
void run()
This is called with the Thread is run from a ThreadGrp.
sc::FockBuildMatrix::accum
virtual void accum(const Ref< FockBuildMatrix > &fbm)=0
Accumulate fbm into this.
sc::FockContribution::contrib_e_K
virtual void contrib_e_K(double factor, int I, int J, int K, int L, int nI, int nJ, int nK, int nL, const double *RESTRICT buf)=0
This routine does not permute any indices.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::ReplFockBuildMatrix::zero_data
void zero_data()
Zero out the data.
sc::ReplFockBuildMatrix
Definition: fockbuild.h:157
sc::FockBuildAMG
Definition: fockbuild.h:197

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