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