1 | //
|
---|
2 | // exchange.cc
|
---|
3 | //
|
---|
4 | // Copyright (C) 2004 Edward Valeev
|
---|
5 | //
|
---|
6 | // Author: Edward Valeev <edward.valeev@chemistry.gatech.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 | #include <stdexcept>
|
---|
29 | #include <stdlib.h>
|
---|
30 | #include <string.h>
|
---|
31 | #include <math.h>
|
---|
32 | #include <limits.h>
|
---|
33 |
|
---|
34 | #include <scconfig.h>
|
---|
35 | #include <util/misc/formio.h>
|
---|
36 | #include <util/misc/timer.h>
|
---|
37 | #include <util/class/class.h>
|
---|
38 | #include <util/state/state.h>
|
---|
39 | #include <util/state/state_text.h>
|
---|
40 | #include <util/state/state_bin.h>
|
---|
41 | #include <math/scmat/matrix.h>
|
---|
42 | #include <chemistry/molecule/molecule.h>
|
---|
43 | #include <chemistry/qc/basis/integral.h>
|
---|
44 | #include <chemistry/qc/mbptr12/blas.h>
|
---|
45 | #include <chemistry/qc/mbptr12/r12ia.h>
|
---|
46 | #include <chemistry/qc/mbptr12/vxb_eval_info.h>
|
---|
47 | #include <chemistry/qc/mbptr12/pairiter.h>
|
---|
48 | #include <chemistry/qc/mbptr12/r12int_eval.h>
|
---|
49 |
|
---|
50 | using namespace std;
|
---|
51 | using namespace sc;
|
---|
52 |
|
---|
53 | RefSCMatrix
|
---|
54 | R12IntEval::exchange_(const Ref<MOIndexSpace>& occ_space, const Ref<MOIndexSpace>& bra_space,
|
---|
55 | const Ref<MOIndexSpace>& ket_space)
|
---|
56 | {
|
---|
57 | Ref<MessageGrp> msg = r12info()->msg();
|
---|
58 | const int num_te_types = 1;
|
---|
59 | enum te_types {eri=0};
|
---|
60 |
|
---|
61 | tim_enter("exchange");
|
---|
62 |
|
---|
63 | int me = msg->me();
|
---|
64 | int nproc = msg->n();
|
---|
65 | ExEnv::out0() << endl << indent
|
---|
66 | << "Entered exchange matrix evaluator" << endl;
|
---|
67 | ExEnv::out0() << incindent;
|
---|
68 |
|
---|
69 | // Do the AO->MO transform
|
---|
70 | Ref<MOIntsTransformFactory> tfactory = r12info_->tfactory();
|
---|
71 | // Gaussians are real, hence occ_space and bra_space can be swapped
|
---|
72 | tfactory->set_spaces(occ_space,bra_space,
|
---|
73 | occ_space,ket_space);
|
---|
74 | Ref<TwoBodyMOIntsTransform> mxny_tform = tfactory->twobody_transform_13("(mx|ny)");
|
---|
75 | mxny_tform->set_num_te_types(num_te_types);
|
---|
76 | mxny_tform->compute();
|
---|
77 | Ref<R12IntsAcc> mnxy_acc = mxny_tform->ints_acc();
|
---|
78 |
|
---|
79 | const int nocc = occ_space->rank();
|
---|
80 | const int nbra = bra_space->rank();
|
---|
81 | const int nket = ket_space->rank();
|
---|
82 | const int nbraket = nbra*nket;
|
---|
83 |
|
---|
84 | ExEnv::out0() << indent << "Begin computation of exchange matrix" << endl;
|
---|
85 | if (debug_) {
|
---|
86 | ExEnv::out0() << indent << "nbra = " << nbra << endl;
|
---|
87 | ExEnv::out0() << indent << "nket = " << nket << endl;
|
---|
88 | ExEnv::out0() << indent << "nocc = " << nocc << endl;
|
---|
89 | }
|
---|
90 |
|
---|
91 | // Compute the number of tasks that have full access to the integrals
|
---|
92 | // and split the work among them
|
---|
93 | vector<int> proc_with_ints;
|
---|
94 | int nproc_with_ints = tasks_with_ints_(mnxy_acc,proc_with_ints);
|
---|
95 |
|
---|
96 | //////////////////////////////////////////////////////////////
|
---|
97 | //
|
---|
98 | // Evaluation of the exchange matrix proceeds as follows:
|
---|
99 | //
|
---|
100 | // loop over batches of mm, 0<=m<nocc
|
---|
101 | // load (mmxy)=(xm|my) into memory
|
---|
102 | //
|
---|
103 | // loop over xy, 0<=x<nbra, 0<=y<nket
|
---|
104 | // compute K[x][y] += (mmxy)
|
---|
105 | // end xy loop
|
---|
106 | // end mm loop
|
---|
107 | //
|
---|
108 | /////////////////////////////////////////////////////////////////////////////////
|
---|
109 |
|
---|
110 | double* K_xy = new double[nbraket];
|
---|
111 | memset(K_xy,0,nbraket*sizeof(double));
|
---|
112 | if (mnxy_acc->has_access(me)) {
|
---|
113 |
|
---|
114 | for(int m=0; m<nocc; m++) {
|
---|
115 |
|
---|
116 | const int mm = m*nocc+m;
|
---|
117 | const int mm_proc = mm%nproc_with_ints;
|
---|
118 | if (mm_proc != proc_with_ints[me])
|
---|
119 | continue;
|
---|
120 |
|
---|
121 | if (debug_)
|
---|
122 | ExEnv::outn() << indent << "task " << me << ": working on (m) = " << m << " " << endl;
|
---|
123 |
|
---|
124 | // Get (|1/r12|) integrals
|
---|
125 | tim_enter("MO ints retrieve");
|
---|
126 | const double *mmxy_buf_eri = mnxy_acc->retrieve_pair_block(m,m,R12IntsAcc::eri);
|
---|
127 | tim_exit("MO ints retrieve");
|
---|
128 |
|
---|
129 | if (debug_)
|
---|
130 | ExEnv::outn() << indent << "task " << me << ": obtained mm block" << endl;
|
---|
131 |
|
---|
132 | const double one = 1.0;
|
---|
133 | const int unit_stride = 1;
|
---|
134 | F77_DAXPY(&nbraket,&one,mmxy_buf_eri,&unit_stride,K_xy,&unit_stride);
|
---|
135 |
|
---|
136 | mnxy_acc->release_pair_block(m,m,R12IntsAcc::eri);
|
---|
137 | }
|
---|
138 | }
|
---|
139 | // Tasks that don't do any work here still need to create these timers
|
---|
140 | tim_enter("MO ints retrieve");
|
---|
141 | tim_exit("MO ints retrieve");
|
---|
142 |
|
---|
143 | ExEnv::out0() << indent << "End of computation of exchange matrix" << endl;
|
---|
144 | mnxy_acc->deactivate();
|
---|
145 |
|
---|
146 | msg->sum(K_xy,nbraket);
|
---|
147 |
|
---|
148 | RefSCMatrix K(bra_space->coefs()->coldim(), ket_space->coefs()->coldim(), bra_space->coefs()->kit());
|
---|
149 | K.assign(K_xy);
|
---|
150 | delete[] K_xy;
|
---|
151 |
|
---|
152 | ExEnv::out0() << decindent;
|
---|
153 | ExEnv::out0() << indent << "Exited exchange matrix evaluator" << endl;
|
---|
154 | tim_exit("exchange");
|
---|
155 |
|
---|
156 | return K;
|
---|
157 | }
|
---|
158 |
|
---|
159 | ////////////////////////////////////////////////////////////////////////////
|
---|
160 |
|
---|
161 | // Local Variables:
|
---|
162 | // mode: c++
|
---|
163 | // c-file-style: "CLJ-CONDENSED"
|
---|
164 | // End:
|
---|