source: ThirdParty/mpqc_open/src/lib/chemistry/qc/mbptr12/transform_ikjy.cc

Candidate_v1.6.1
Last change on this file was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 8.4 KB
Line 
1//
2// transform_ikjy.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#ifdef __GNUG__
29#pragma implementation
30#endif
31
32#include <stdexcept>
33
34#include <util/class/scexception.h>
35#include <util/misc/formio.h>
36#include <util/state/state_bin.h>
37#include <util/ref/ref.h>
38#include <math/scmat/local.h>
39#include <chemistry/qc/mbptr12/transform_ikjy.h>
40#include <chemistry/qc/mbptr12/r12ia_memgrp.h>
41#include <chemistry/qc/mbptr12/r12ia_node0file.h>
42#ifdef HAVE_MPIIO
43 #include <chemistry/qc/mbptr12/r12ia_mpiiofile.h>
44#endif
45#include <chemistry/qc/mbptr12/transform_123inds.h>
46
47using namespace std;
48using namespace sc;
49
50inline int max(int a,int b) { return (a > b) ? a : b;}
51
52/*-----------
53 TwoBodyMOIntsTransform_ikjy
54 -----------*/
55static ClassDesc TwoBodyMOIntsTransform_ikjy_cd(
56 typeid(TwoBodyMOIntsTransform_ikjy),"TwoBodyMOIntsTransform_ikjy",1,"public TwoBodyMOIntsTransform",
57 0, 0, create<TwoBodyMOIntsTransform_ikjy>);
58
59TwoBodyMOIntsTransform_ikjy::TwoBodyMOIntsTransform_ikjy(const std::string& name, const Ref<MOIntsTransformFactory>& factory,
60 const Ref<MOIndexSpace>& space1, const Ref<MOIndexSpace>& space2,
61 const Ref<MOIndexSpace>& space3, const Ref<MOIndexSpace>& space4) :
62 TwoBodyMOIntsTransform(name,factory,space1,space2,space3,space4)
63{
64 init_vars();
65}
66
67TwoBodyMOIntsTransform_ikjy::TwoBodyMOIntsTransform_ikjy(StateIn& si) : TwoBodyMOIntsTransform(si)
68{
69 init_vars();
70}
71
72TwoBodyMOIntsTransform_ikjy::~TwoBodyMOIntsTransform_ikjy()
73{
74}
75
76void
77TwoBodyMOIntsTransform_ikjy::save_data_state(StateOut& so)
78{
79 TwoBodyMOIntsTransform::save_data_state(so);
80}
81
82//////////////////////////////////////////////////////
83// Compute required (dynamic) memory
84// for a given batch size of the transformation
85//
86// Only arrays allocated before exiting the loop over
87// i-batches are included here - only these arrays
88// affect the batch size.
89//////////////////////////////////////////////////////
90distsize_t
91TwoBodyMOIntsTransform_ikjy::compute_transform_dynamic_memory_(int ni) const
92{
93 int nproc = msg_->n();
94 int nthread = thr_->nthread();
95
96 int rank2 = space2_->rank();
97 int rank3 = space3_->rank();
98 int nbasis2 = space2_->basis()->nbasis();
99 int nbasis4 = space4_->basis()->nbasis();
100 int nfuncmax3 = space3_->basis()->max_nfunction_in_shell();
101 int nfuncmax4 = space4_->basis()->max_nfunction_in_shell();
102
103 // If basis3 == basis4 then permutational symmetry will be used in second step
104 bool basis3_eq_basis4 = (space3_->basis() == space4_->basis());
105
106 // compute nij as nij on node 0, since nij on node 0 is >= nij on other nodes
107 int nij = compute_nij(ni, rank3, nproc, 0);
108
109 distsize_t memsize = sizeof(double)*(num_te_types_*((distsize_t)nthread * ni * nbasis2 * nfuncmax3 * nfuncmax4 // iqrs
110 + (distsize_t)ni * rank2 * nfuncmax3 * nfuncmax4 // ikrs
111 + (distsize_t)nij * rank2 * nbasis4 // ikjs - buffer of 3 q.t. and higher
112 // transformed integrals
113 )
114 + (distsize_t)rank2 * nfuncmax4 // ks
115 + (distsize_t)rank2 * nbasis4 // kx
116 );
117 return memsize;
118}
119
120const size_t
121TwoBodyMOIntsTransform_ikjy::memgrp_blksize() const
122{
123 const int nbasis4 = space4_->basis()->nbasis();
124 const int rank4 = space4_->rank();
125 const int dim4 = (nbasis4 > rank4) ? nbasis4 : rank4;
126 return space2_->rank()*dim4*sizeof(double);
127}
128
129void
130TwoBodyMOIntsTransform_ikjy::init_acc()
131{
132 if (ints_acc_.nonnull())
133 return;
134
135 int nij = compute_nij(batchsize_, space3_->rank(), msg_->n(), msg_->me());
136 alloc_mem((size_t)num_te_types_*nij*memgrp_blksize());
137
138 switch (ints_method_) {
139
140 case MOIntsTransformFactory::mem_only:
141 if (npass_ > 1)
142 throw std::runtime_error("TwoBodyMOIntsTransform_ikjy::init_acc() -- cannot use MemoryGrp-based accumulator in multi-pass transformations");
143 ints_acc_ = new R12IntsAcc_MemoryGrp(mem_, num_te_types_, space1_->rank(), space3_->rank(), space2_->rank(), space4_->rank()); // Hack to avoid using nfzc and nocc
144 break;
145
146 case MOIntsTransformFactory::mem_posix:
147 if (npass_ == 1) {
148 ints_acc_ = new R12IntsAcc_MemoryGrp(mem_, num_te_types_, space1_->rank(), space3_->rank(), space2_->rank(), space4_->rank());
149 break;
150 }
151 // else use the next case
152
153 case MOIntsTransformFactory::posix:
154 ints_acc_ = new R12IntsAcc_Node0File(mem_, (file_prefix_+"."+name_).c_str(), num_te_types_,
155 space1_->rank(), space3_->rank(), space2_->rank(), space4_->rank());
156 break;
157
158#if HAVE_MPIIO
159 case MOIntsTransformFactory::mem_mpi:
160 if (npass_ == 1) {
161 ints_acc_ = new R12IntsAcc_MemoryGrp(mem_, num_te_types_, space1_->rank(), space3_->rank(), space2_->rank(), space4_->rank());
162 break;
163 }
164 // else use the next case
165
166 case MOIntsTransformFactory::mpi:
167 ints_acc_ = new R12IntsAcc_MPIIOFile_Ind(mem_, (file_prefix_+"."+name_).c_str(), num_te_types_,
168 space1_->rank(), space3_->rank(), space2_->rank(), space4_->rank());
169 break;
170#endif
171
172 default:
173 throw std::runtime_error("TwoBodyMOIntsTransform_ikjy::init_acc() -- invalid integrals store method");
174 }
175}
176
177void
178TwoBodyMOIntsTransform_ikjy::check_int_symm(double threshold) const throw (ProgrammingError)
179{
180 Ref<R12IntsAcc> iacc = ints_acc();
181 if (!iacc->is_committed())
182 throw ProgrammingError("TwoBodyMOIntsTransform_ikjy::check_int_symm() is called but integrals not computed yet",
183 __FILE__, __LINE__);
184
185 int num_te_types = iacc->num_te_types();
186 int ni = iacc->ni();
187 int nj = iacc->nj();
188 int nk = iacc->nx();
189 int ny = iacc->ny();
190 vector<int> isyms = space1_->mosym();
191 vector<int> jsyms = space3_->mosym();
192 vector<int> ksyms = space2_->mosym();
193 vector<int> ysyms = space4_->mosym();
194
195 int me = msg_->me();
196 vector<int> twi_map;
197 int ntasks_with_ints = iacc->tasks_with_access(twi_map);
198 if (!iacc->has_access(me))
199 return;
200
201 int ij=0;
202 for(int i=0; i<ni; i++) {
203 int isym = isyms[i];
204 for(int j=0; j<nj; j++, ij++) {
205 int jsym = jsyms[j];
206 if (ij%ntasks_with_ints != twi_map[me])
207 continue;
208
209 for(int t=0; t<num_te_types; t++) {
210 const double* ints = iacc->retrieve_pair_block(i,j,static_cast<R12IntsAcc::tbint_type>(t));
211 int ky=0;
212 for(int k=0; k<nk; k++) {
213 int ksym = ksyms[k];
214 for(int y=0; y<ny; y++, ky++) {
215 int ysym = ysyms[y];
216 if ( (isym^jsym^ksym^ysym) != 0 && fabs(ints[ky]) > threshold) {
217 ExEnv::outn() << scprintf("Integral type=%d i=%d k=%d j=%d y=%d should be zero\n",t,i,k,j,y);
218 throw ProgrammingError("TwoBodyMOIntsTransform_ikjy::check_int_symm() -- nonzero nonsymmetric integrals are detected",
219 __FILE__, __LINE__);
220 }
221 }
222 }
223 iacc->release_pair_block(i,j,static_cast<R12IntsAcc::tbint_type>(t));
224 }
225 }
226 }
227}
228
229/*void
230TwoBodyMOIntsTransform_ikjy::compute()
231{
232 init_acc();
233
234 Ref<ThreadLock> lock = thr_->new_lock();
235 Ref<Integral> int_factory = factory_->integral();
236 int_factory->set_basis(space1_->basis(),space2_->basis(),space3_->basis(),space4_->basis());
237 Ref<TwoBodyInt> tbint = int_factory->grt();
238 Ref<TwoBodyMOIntsTransform> this_tform = this;
239 TwoBodyMOIntsTransform_123Inds* tform_123 = new TwoBodyMOIntsTransform_123Inds(this_tform,0,1,lock,tbint,-100.0,0);
240 tform_123->run();
241}*/
242
243/////////////////////////////////////////////////////////////////////////////
244
245// Local Variables:
246// mode: c++
247// c-file-style: "CLJ-CONDENSED"
248// End:
Note: See TracBrowser for help on using the repository browser.