| 1 | //
 | 
|---|
| 2 | // transform_tbint.h
 | 
|---|
| 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 interface
 | 
|---|
| 30 | #endif
 | 
|---|
| 31 | 
 | 
|---|
| 32 | #ifndef _chemistry_qc_mbptr12_transformtbint_h
 | 
|---|
| 33 | #define _chemistry_qc_mbptr12_transformtbint_h
 | 
|---|
| 34 | 
 | 
|---|
| 35 | #include <string>
 | 
|---|
| 36 | #include <util/ref/ref.h>
 | 
|---|
| 37 | #include <util/class/scexception.h>
 | 
|---|
| 38 | #include <chemistry/qc/basis/distshpair.h>
 | 
|---|
| 39 | #include <chemistry/qc/mbptr12/r12ia.h>
 | 
|---|
| 40 | #include <chemistry/qc/mbptr12/moindexspace.h>
 | 
|---|
| 41 | #include <chemistry/qc/mbptr12/transform_factory.h>
 | 
|---|
| 42 | 
 | 
|---|
| 43 | using namespace std;
 | 
|---|
| 44 | 
 | 
|---|
| 45 | namespace sc {
 | 
|---|
| 46 | 
 | 
|---|
| 47 | class MOIntsTransformFactory;
 | 
|---|
| 48 | 
 | 
|---|
| 49 |   /** TwoBodyMOIntsTransform computes two-body integrals in MO basis
 | 
|---|
| 50 |       using parallel integrals-direct AO->MO transformation. */
 | 
|---|
| 51 | 
 | 
|---|
| 52 | class TwoBodyMOIntsTransform : virtual public SavableState {
 | 
|---|
| 53 | 
 | 
|---|
| 54 |   // Construct the integrals accumulator object
 | 
|---|
| 55 |   // This function depends on the particulars of the transformation
 | 
|---|
| 56 |   virtual void init_acc() = 0;
 | 
|---|
| 57 |   // Compute required dynamic memory for a given batch size
 | 
|---|
| 58 |   // implementation depends on the particulars of the concrete type
 | 
|---|
| 59 |   virtual distsize_t compute_transform_dynamic_memory_(int ni) const = 0;
 | 
|---|
| 60 | 
 | 
|---|
| 61 | protected:
 | 
|---|
| 62 |   /** By default, integrals smaller than zero_integral are considered zero.
 | 
|---|
| 63 |       This constant is only used in checking integrals, not computing them. */
 | 
|---|
| 64 |   static const double zero_integral = 1.0e-12;
 | 
|---|
| 65 |   /// Predefined enumerated type for the MO spaces
 | 
|---|
| 66 |   typedef struct {
 | 
|---|
| 67 |     enum {Space1, Space2, Space3, Space4};
 | 
|---|
| 68 |   } MOSpaces;
 | 
|---|
| 69 | 
 | 
|---|
| 70 |   std::string name_;
 | 
|---|
| 71 |   Ref<MOIntsTransformFactory> factory_;
 | 
|---|
| 72 | 
 | 
|---|
| 73 |   Ref<MolecularEnergy> top_mole_;   // Top-level molecular energy to enable checkpointing
 | 
|---|
| 74 |   Ref<MessageGrp> msg_;
 | 
|---|
| 75 |   Ref<MemoryGrp> mem_;
 | 
|---|
| 76 |   Ref<ThreadGrp> thr_;
 | 
|---|
| 77 |   // Integrals accumulator
 | 
|---|
| 78 |   Ref<R12IntsAcc> ints_acc_;
 | 
|---|
| 79 | 
 | 
|---|
| 80 |   Ref<MOIndexSpace> space1_;
 | 
|---|
| 81 |   Ref<MOIndexSpace> space2_;
 | 
|---|
| 82 |   Ref<MOIndexSpace> space3_;
 | 
|---|
| 83 |   Ref<MOIndexSpace> space4_;
 | 
|---|
| 84 | 
 | 
|---|
| 85 |   int num_te_types_;
 | 
|---|
| 86 |   size_t memory_;
 | 
|---|
| 87 |   bool dynamic_;
 | 
|---|
| 88 |   double print_percent_;
 | 
|---|
| 89 |   DistShellPair::SharedData spdata_;
 | 
|---|
| 90 |   int debug_;
 | 
|---|
| 91 |   MOIntsTransformFactory::StoreMethod ints_method_;
 | 
|---|
| 92 |   std::string file_prefix_;
 | 
|---|
| 93 | 
 | 
|---|
| 94 |   // These variables are never saved but computed every time in case environment
 | 
|---|
| 95 |   // has changed or it's a restart  
 | 
|---|
| 96 |   size_t mem_static_;
 | 
|---|
| 97 |   int batchsize_;
 | 
|---|
| 98 |   int npass_;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |   /// returns index in range of space1_ where to start the transformation
 | 
|---|
| 101 |   unsigned int restart_orbital() const;
 | 
|---|
| 102 |   
 | 
|---|
| 103 |   // Compute used static memory and batch size
 | 
|---|
| 104 |   void init_vars();
 | 
|---|
| 105 |   // Re-construct the integrals accumulator object
 | 
|---|
| 106 |   void reinit_acc();
 | 
|---|
| 107 |   // Allocate distributed memory
 | 
|---|
| 108 |   void alloc_mem(const size_t localmem);
 | 
|---|
| 109 |   // Deallocate distributed memory
 | 
|---|
| 110 |   void dealloc_mem();
 | 
|---|
| 111 | 
 | 
|---|
| 112 |   // Compute batchsize given the amount of used static memory and
 | 
|---|
| 113 |   // the number of i-orbitals
 | 
|---|
| 114 |   int compute_transform_batchsize_(size_t mem_static, int rank_i);
 | 
|---|
| 115 | 
 | 
|---|
| 116 |   // Compute the number of ij-pairs per this task
 | 
|---|
| 117 |   static int compute_nij(const int rank_i, const int rank_j, const int nproc, const int me);
 | 
|---|
| 118 | 
 | 
|---|
| 119 |   /** Generates a report on memory for the transform : user-specified limits, projected and actual use.
 | 
|---|
| 120 |       Assumes formatting info from ExEnv::out0().
 | 
|---|
| 121 |    */
 | 
|---|
| 122 |   void memory_report(std::ostream& os = ExEnv::out0()) const;
 | 
|---|
| 123 |   /** Generates a report on MO spaces for the transform.
 | 
|---|
| 124 |       Assumes formatting info from ExEnv::out0().
 | 
|---|
| 125 |    */
 | 
|---|
| 126 |   void mospace_report(std::ostream& os = ExEnv::out0()) const;
 | 
|---|
| 127 | 
 | 
|---|
| 128 |   /** Prints out standard header. Call at the beginning of compute().
 | 
|---|
| 129 |    */
 | 
|---|
| 130 |   void print_header(std::ostream& os = ExEnv::out0()) const;
 | 
|---|
| 131 |   /** Prints out standard footer. Call at the end of compute().
 | 
|---|
| 132 |    */
 | 
|---|
| 133 |   void print_footer(std::ostream& os = ExEnv::out0()) const;
 | 
|---|
| 134 |     
 | 
|---|
| 135 | public:
 | 
|---|
| 136 | 
 | 
|---|
| 137 |   TwoBodyMOIntsTransform(StateIn&);
 | 
|---|
| 138 |   TwoBodyMOIntsTransform(const std::string& name, const Ref<MOIntsTransformFactory>& factory,
 | 
|---|
| 139 |                          const Ref<MOIndexSpace>& space1, const Ref<MOIndexSpace>& space2,
 | 
|---|
| 140 |                          const Ref<MOIndexSpace>& space3, const Ref<MOIndexSpace>& space4);
 | 
|---|
| 141 |   ~TwoBodyMOIntsTransform();
 | 
|---|
| 142 | 
 | 
|---|
| 143 |   void save_data_state(StateOut&);
 | 
|---|
| 144 | 
 | 
|---|
| 145 |   /// Returns the name of the transform
 | 
|---|
| 146 |   std::string name() const {return name_;}
 | 
|---|
| 147 |   /// Returns a short label which uniquely identifies the type of transform
 | 
|---|
| 148 |   virtual std::string type() const =0;
 | 
|---|
| 149 |   /// Returns the MemoryGrp object
 | 
|---|
| 150 |   Ref<MemoryGrp> mem() const;
 | 
|---|
| 151 |   /// Returns the MessageGrp object
 | 
|---|
| 152 |   Ref<MessageGrp> msg() const;
 | 
|---|
| 153 |   /// Returns the integrals accumulator object
 | 
|---|
| 154 |   Ref<R12IntsAcc> ints_acc() const;
 | 
|---|
| 155 |   /// Returns MOIndexSpace object 1
 | 
|---|
| 156 |   Ref<MOIndexSpace> space1() const;
 | 
|---|
| 157 |   /// Returns MOIndexSpace object 2
 | 
|---|
| 158 |   Ref<MOIndexSpace> space2() const;
 | 
|---|
| 159 |   /// Returns MOIndexSpace object 3
 | 
|---|
| 160 |   Ref<MOIndexSpace> space3() const;
 | 
|---|
| 161 |   /// Returns MOIndexSpace object 4
 | 
|---|
| 162 |   Ref<MOIndexSpace> space4() const;
 | 
|---|
| 163 | 
 | 
|---|
| 164 |   /// Returns the update print frequency
 | 
|---|
| 165 |   double print_percent() const;
 | 
|---|
| 166 |   /// Returns the batchsize for each pass of the transformation
 | 
|---|
| 167 |   int batchsize() const;
 | 
|---|
| 168 |   /// Returns the debug level
 | 
|---|
| 169 |   int debug() const;
 | 
|---|
| 170 |   /// Returns whether to use dynamic load balancing
 | 
|---|
| 171 |   bool dynamic() const;
 | 
|---|
| 172 |   /// Returns the number of types of two body integrals computed
 | 
|---|
| 173 |   int num_te_types() const;
 | 
|---|
| 174 |   /** Returns the number of bytes allocated for each ij-block of integrals of one type
 | 
|---|
| 175 |       in MemoryGrp. It's guaranteed to be divisible by sizeof(double).
 | 
|---|
| 176 |     */
 | 
|---|
| 177 |   virtual const size_t memgrp_blksize() const =0;
 | 
|---|
| 178 |   
 | 
|---|
| 179 |   /// Specifies the top-level MolecularEnergy object to use for checkpointing
 | 
|---|
| 180 |   void set_top_mole(const Ref<MolecularEnergy>& top_mole) { top_mole_ = top_mole; }
 | 
|---|
| 181 | 
 | 
|---|
| 182 |   /** Specifies how many integral types computed by TwoBodyInt to be transformed
 | 
|---|
| 183 |       Default is 1. */
 | 
|---|
| 184 |   void set_num_te_types(const int num_te_types);
 | 
|---|
| 185 |   void set_memory(const size_t memory);
 | 
|---|
| 186 |   void set_debug(int debug) { debug_ = debug; }
 | 
|---|
| 187 |   void set_dynamic(bool dynamic) { dynamic_ = dynamic; }
 | 
|---|
| 188 |   void set_print_percent(double print_percent) { print_percent_ = print_percent; }
 | 
|---|
| 189 | 
 | 
|---|
| 190 |   /// Computes transformed integrals
 | 
|---|
| 191 |   virtual void compute() = 0;
 | 
|---|
| 192 |   /// Check symmetry of transformed integrals
 | 
|---|
| 193 |   virtual void check_int_symm(double threshold = TwoBodyMOIntsTransform::zero_integral) const throw (ProgrammingError) =0;
 | 
|---|
| 194 |   /// Make the transform obsolete. Next call to compute() will recompute
 | 
|---|
| 195 |   virtual void obsolete();
 | 
|---|
| 196 | 
 | 
|---|
| 197 |   /** Returns a that data that must be shared between all DistShellPair
 | 
|---|
| 198 |    * objects. */
 | 
|---|
| 199 |   DistShellPair::SharedData *shell_pair_data() { return &spdata_; }
 | 
|---|
| 200 | 
 | 
|---|
| 201 | };
 | 
|---|
| 202 | 
 | 
|---|
| 203 | }
 | 
|---|
| 204 | 
 | 
|---|
| 205 | #endif
 | 
|---|
| 206 | 
 | 
|---|
| 207 | // Local Variables:
 | 
|---|
| 208 | // mode: c++
 | 
|---|
| 209 | // c-file-style: "CLJ"
 | 
|---|
| 210 | // End:
 | 
|---|
| 211 | 
 | 
|---|
| 212 | 
 | 
|---|