00001
00002 #ifndef _chemistry_qc_scf_fockdist_h
00003 #define _chemistry_qc_scf_fockdist_h
00004
00005 #include <vector>
00006 #include <util/misc/scint.h>
00007 #include <util/group/message.h>
00008 #include <util/group/thread.h>
00009 #include <chemistry/qc/basis/basis.h>
00010 #include <chemistry/qc/basis/petite.h>
00011
00012 namespace sc {
00013
00014 class FockBlocks: public sc::RefCount {
00015 int nblock_;
00016 std::vector<int> begin_;
00017 std::vector<int> end_;
00018 std::vector<int> shell_to_block_;
00019 public:
00020 typedef enum { Shell, Atom } Method;
00021
00022 FockBlocks(const sc::Ref<sc::GaussianBasisSet> &, Method);
00023
00024 int nblock() const { return nblock_; }
00025 int begin(int iblock) const {return begin_[iblock];}
00026 int end(int iblock) const {return end_[iblock];}
00027 int size(int iblock) const {return end_[iblock]-begin_[iblock];}
00028 int shell_to_block(int ishell) const { return shell_to_block_[ishell]; }
00029 };
00030
00031 class FockDist: public sc::RefCount {
00032 protected:
00033 sc::Ref<FockBlocks> blocks_;
00034
00035 sc::Ref<sc::MessageGrp> msg_;
00036 sc::Ref<sc::PetiteList> pl_;
00037 int nthread_, mythread_;
00038 int nproc_, myproc_;
00039
00040 bool in_p1(int i);
00041 public:
00042 FockDist(const sc::Ref<sc::GaussianBasisSet> &,
00043 const sc::Ref<FockBlocks> &,
00044 const sc::Ref<sc::PetiteList> &pl,
00045 const sc::Ref<sc::MessageGrp> &,
00046 int nthread, int mythread);
00047 virtual ~FockDist();
00048 virtual void init() = 0;
00049
00050
00051
00052
00053
00054
00055 virtual bool get_blocks(int &i, int &j, int &k, int &l) = 0;
00056 int nblock() const { return blocks_->nblock(); }
00057 int begin(int iblock) const {return blocks_->begin(iblock);}
00058 int end(int iblock) const {return blocks_->end(iblock);}
00059 int size(int iblock) const {return blocks_->size(iblock);}
00060 const sc::Ref<FockBlocks> &fockblocks() const { return blocks_; }
00061
00062
00063 virtual bool fixed_integral_map() = 0;
00064 };
00065
00066 class FockDistStatic: public FockDist {
00067 protected:
00068 int i_, j_, k_, l_;
00069 int nglobalthread_, myglobalthread_;
00070 public:
00071 FockDistStatic(const sc::Ref<sc::GaussianBasisSet> &,
00072 const sc::Ref<FockBlocks> &,
00073 const sc::Ref<sc::PetiteList> &pl,
00074 const sc::Ref<sc::MessageGrp> &,
00075 int nthread, int mythread);
00076 ~FockDistStatic();
00077 void init();
00078 bool fixed_integral_map();
00079 };
00080
00081 class FockDistStatic4: public FockDistStatic {
00082 private:
00083 bool next_block();
00084 bool next_block(int n);
00085 public:
00086 FockDistStatic4(const sc::Ref<sc::GaussianBasisSet> &,
00087 const sc::Ref<FockBlocks> &,
00088 const sc::Ref<sc::PetiteList> &pl,
00089 const sc::Ref<sc::MessageGrp> &,
00090 int nthread, int mythread);
00091 ~FockDistStatic4();
00092 bool get_blocks(int&,int&,int&,int&);
00093 };
00094
00095 class FockDistStatic2: public FockDistStatic {
00096 private:
00097 bool next_block();
00098 public:
00099 FockDistStatic2(const sc::Ref<sc::GaussianBasisSet> &,
00100 const sc::Ref<FockBlocks> &,
00101 const sc::Ref<sc::PetiteList> &pl,
00102 const sc::Ref<sc::MessageGrp> &,
00103 int nthread, int mythread);
00104 ~FockDistStatic2();
00105 bool get_blocks(int&,int&,int&,int&);
00106 };
00107
00108 class FockDistDynamic: public FockDist {
00109 protected:
00110 typedef std::multimap<std::pair<int,int>, std::pair<int,int>, std::greater<std::pair<int,int> > > pairmap_t;
00111
00112 pairmap_t ijmap_, klmap_;
00113 pairmap_t::const_iterator ij_iter_, kl_iter_;
00114
00115
00116
00117
00118 FockDist *static_;
00119 bool static_distribution() { return static_ != 0; }
00120 public:
00121 FockDistDynamic(const sc::Ref<sc::GaussianBasisSet> &,
00122 const sc::Ref<FockBlocks> &,
00123 const sc::Ref<sc::PetiteList> &pl,
00124 const sc::Ref<sc::MessageGrp> &,
00125 int nthread, int mythread,
00126 const signed char *pmax,
00127 sc::Ref<sc::TwoBodyInt> eri,
00128 int l2tol);
00129 ~FockDistDynamic();
00130 bool fixed_integral_map();
00131 };
00132
00133 class FockDistDynamic2: public FockDistDynamic {
00134 protected:
00135 int i_, j_;
00136
00137 bool next_block();
00138 void run_server();
00139 bool server_get_blocks(int&,int&);
00140 public:
00141 FockDistDynamic2(const sc::Ref<sc::GaussianBasisSet> &,
00142 const sc::Ref<FockBlocks> &,
00143 const sc::Ref<sc::PetiteList> &pl,
00144 const sc::Ref<sc::MessageGrp> &,
00145 int nthread, int mythread,
00146 const signed char *pmax,
00147 sc::Ref<sc::TwoBodyInt> eri,
00148 int l2tol);
00149 ~FockDistDynamic2();
00150 bool get_blocks(int&,int&,int&,int&);
00151 void init();
00152 };
00153
00154 class FockDistDynamic4: public FockDistDynamic {
00155 protected:
00156 typedef std::vector<std::pair<int,int> > pairvec_t;
00157 pairvec_t ijvec_, klvec_;
00158 int a_, b_;
00159 int a_end_, b_end_;
00160 int nij_, nkl_;
00161
00162 sc::MessageGrp::MessageHandle recv_handle_;
00163 sc::MessageGrp::MessageHandle send_handle_;
00164 bool requested_work_;
00165 int work_[4];
00166
00167 bool next_block();
00168 void run_server();
00169 bool server_get_blocks(int&,int&,int&,int&);
00170 bool ijkl(int &i, int &j, int &k, int &l);
00171 public:
00172 FockDistDynamic4(const sc::Ref<sc::GaussianBasisSet> &,
00173 const sc::Ref<FockBlocks> &,
00174 const sc::Ref<sc::PetiteList> &pl,
00175 const sc::Ref<sc::MessageGrp> &,
00176 int nthread, int mythread,
00177 const signed char *pmax,
00178 sc::Ref<sc::TwoBodyInt> eri,
00179 int l2tol);
00180 ~FockDistDynamic4();
00181 bool get_blocks(int&,int&,int&,int&);
00182 void init();
00183 };
00184
00187 class FockDistribution: virtual public sc::SavableState {
00189 int dynamic_;
00191 int nindex_;
00193 int shell_;
00195 int cache_integrals_;
00196 public:
00197 FockDistribution(bool dynamic = 0, bool shell = 1, int nindex = 4,
00198 bool cache_integrals = 1);
00199 FockDistribution(sc::StateIn&);
00200 FockDistribution(const sc::Ref<sc::KeyVal> &);
00201 ~FockDistribution();
00202 void save_data_state(sc::StateOut&);
00203 sc::Ref<FockBlocks> fockblocks(const sc::Ref<sc::GaussianBasisSet> &);
00204 sc::Ref<FockDist> fockdist(const sc::Ref<sc::GaussianBasisSet> &,
00205 const sc::Ref<FockBlocks> &,
00206 const sc::Ref<sc::PetiteList> &pl,
00207 const sc::Ref<sc::MessageGrp> &,
00208 int nthread, int mythread,
00209 const signed char *pmax,
00210 sc::Ref<sc::TwoBodyInt> eri,
00211 int l2tol);
00212 void print(std::ostream&o=sc::ExEnv::out0()) const;
00213 bool cache_integrals() const { return cache_integrals_; }
00214 };
00215
00216 }
00217
00218 #endif