Commit 1407f05c by Francois Gygi

redesign of the Bisection class. Load balancing permutations for

acceleration of exchange calcs moved to ExchangeOperator.
ExchangeOperator does not modify wf argument when computing dwf.


git-svn-id: http://qboxcode.org/svn/qb/trunk@1198 cba15fb0-1239-40c8-b417-11db7ca47a34
parent e962ec1a
......@@ -16,34 +16,31 @@
//
////////////////////////////////////////////////////////////////////////////////
#ifndef BISECTION_H
#define BISECTION_H
#include <iostream>
#include <fstream>
#include <iomanip>
#include <complex>
#include <vector>
#include "Context.h"
#include "Sample.h"
#include "Basis.h"
#include "FourierTransform.h"
#include "SlaterDet.h"
#include "Matrix.h"
#include "Timer.h"
#include "isodate.h"
#include "jade.h"
using namespace std;
class FourierTransform;
class Bisection
{
private:
Sample& s_;
Context gcontext_;
// bisection levels in each directions
int nlevels_[3]; // bisection level
int ndiv_[3]; // number of subdivisions
int nlevelsmax_; // max level of bisection
int nst_; // number of states in SlaterDet
int nstloc_;
// real space grid
int np_[3]; // grid size
......@@ -52,35 +49,43 @@ class Bisection
int np012loc_; // local size
FourierTransform *ft_;
vector<vector<long int> > localization_;
std::vector<long int> localization_; // localization indices
// xy_proj[ir]: projector in xy plane associated with grid point ir
vector<int> xy_proj_;
std::vector<int> xy_proj_;
// matrices of real space wave functions in subdomains
vector<DoubleMatrix*> rmat_;
std::vector<DoubleMatrix*> rmat_;
// a matrices
int nmat_;
vector<DoubleMatrix*> amat_;
std::vector<DoubleMatrix*> amat_;
std::vector<std::vector<double> > adiag_;
DoubleMatrix *u_;
// test function
bool check_amat(ComplexMatrix &c);
void trim_amat(const vector<double>& occ);
void distribute(int ispin);
bool check_amat(const ComplexMatrix &c);
void trim_amat(const std::vector<double>& occ);
public:
Bisection(Sample& s, int nlevels[3]);
Bisection(const SlaterDet& sd, int nlevels[3]);
void compute_transform(const SlaterDet& sd, int maxsweep, double tol);
void compute_localization(double epsilon);
void forward(SlaterDet& sd);
void forward(DoubleMatrix& u, SlaterDet& sd);
void backward(SlaterDet& sd);
void backward(DoubleMatrix& u, SlaterDet& sd);
int nmat(void) const { return nmat_; }
void localize(Wavefunction &wf, double epsilon);
long int localization(int ispin, int i) const
{ return localization_[ispin][i]; }
vector<vector<long int> > localization(void) const { return localization_; }
bool overlap(int ispin, int i, int j);
double pair_fraction(int ispin);
double size(int ispin, int i);
double total_size(int ispin);
long int localization(int i) const { return localization_[i]; }
std::vector<long int> localization(void) const { return localization_; }
bool overlap(int i, int j);
bool overlap(std::vector<long int> loc, int i, int j);
const DoubleMatrix& u(void) const { return *u_; }
double pair_fraction(void);
double size(int i);
double total_size(void);
~Bisection();
};
#endif
......@@ -62,22 +62,47 @@ class BisectionCmd : public Cmd
nLevels[1]=atoi(argv[2]);
nLevels[2]=atoi(argv[3]);
Bisection bisection(*s,nLevels);
bisection.localize(wf, epsilon);
vector<vector<long int> > localization = bisection.localization();
if ( ui->onpe0() )
for ( int ispin = 0; ispin < wf.nspin(); ispin++ )
{
cout << " BisectionCmd: lx=" << nLevels[0]
<< " ly=" << nLevels[1]
<< " lz=" << nLevels[2]
<< " threshold=" << epsilon << endl;
for ( int ispin = 0; ispin < wf.nspin(); ispin++ )
SlaterDet& sd = *wf.sd(0,0);
Bisection bisection(sd,nLevels);
const int maxsweep = 20;
const double tol = 1.e-8;
bisection.compute_transform(sd,maxsweep,tol);
bisection.compute_localization(epsilon);
bisection.forward(sd);
vector<long int> localization = bisection.localization();
if ( ui->onpe0() )
{
cout << " BisectionCmd: lx=" << nLevels[0]
<< " ly=" << nLevels[1]
<< " lz=" << nLevels[2]
<< " threshold=" << epsilon << endl;
cout << " Bisection::localize: total size: ispin=" << ispin
<< ": " << bisection.total_size(ispin) << endl;
<< ": " << bisection.total_size() << endl;
cout << " Bisection::localize: pair fraction: ispin=" << ispin
<< ": " << bisection.pair_fraction(ispin) << endl;
<< ": " << bisection.pair_fraction() << endl;
// print localization vectors and overlaps
int sum = 0;
const int nst = localization.size();
for ( int i = 0; i < nst; i++ )
{
int count = 0;
for ( int j = 0; j < nst; j++ )
{
if ( bisection.overlap(i,j) )
count++;
}
cout << "localization[" << i << "]: "
<< localization[i] << " "
<< bitset<30>(localization[i]) << " overlaps: "
<< count << endl;
sum += count;
}
cout << "total overlaps: " << sum << " / " << nst*nst
<< " = " << ((double) sum)/(nst*nst) << endl;
}
}
return 0;
......
......@@ -20,11 +20,11 @@
#include "SlaterDet.h"
#include "FourierTransform.h"
#include "KPGridConnectivity.h"
#include "Bisection.h"
#ifndef EXCHANGEOPERATOR_H
#define EXCHANGEOPERATOR_H
class Bisection;
class ExchangeOperator
{
private:
......@@ -40,9 +40,11 @@ class ExchangeOperator
// reference wf and dwf for non scf iteration
Wavefunction wf0_;
Wavefunction dwf0_;
// copy of wf
Wavefunction wfc_;
double compute_exchange_for_general_case_(Sample* s, Wavefunction* dwf);
double compute_exchange_at_gamma_(Wavefunction &wf, Wavefunction* dwf);
double compute_exchange_at_gamma_(const Wavefunction &wf, Wavefunction* dwf);
void apply_VXC_(double mix, Wavefunction& wf_ref,
Wavefunction& dwf_ref, Wavefunction& dwf);
......@@ -166,7 +168,10 @@ class ExchangeOperator
void CompleteSendingOccupations(int iRotationStep);
// bisection
Bisection* bisection_;
bool use_bisection_;
vector<Bisection*> bisection_;
vector<DoubleMatrix*> uc_;
vector<long int> localization_;
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment