15 dpair(
double a_,
double b_){ a=a_, b=b_;}
22 fprintf(fp,
"(a=%lf b=%lf)",((
dpair*)p)->
a, ((
dpair*)p)->
b);
39 T[
"abij"] = T[
"abij"]*D[
"abij"];
47 [](
double d,
dpair & p){
50 badd(Ei[
"i"],TD[
"abij"]);
51 badd(Ei[
"j"],TD[
"abij"]);
53 [](
double d,
dpair & p){
56 bsub(Ea[
"a"],TD[
"abij"]);
57 bsub(Ea[
"b"],TD[
"abij"]);
78 T[
"abij"] = Vabij[
"abij"];
83 Z[
"abij"] = Vijab[
"ijab"];
84 Z[
"abij"] += Fab[
"af"]*T[
"fbij"];
85 Z[
"abij"] -= Fij[
"ni"]*T[
"abnj"];
86 Z[
"abij"] += 0.5*Vabcd[
"abef"]*T[
"efij"];
87 Z[
"abij"] += 0.5*Vijkl[
"mnij"]*T[
"abmn"];
88 Z[
"abij"] += Vaibj[
"amei"]*T[
"ebmj"];
92 double MP3_energy = Z[
"abij"]*Vabij[
"abij"];
96 int sparse_mp3(
int nv,
int no,
World & dw,
double sp=.8,
bool test=1,
int niter=0,
bool bnd=1,
bool bns=1,
bool sparse_T=1){
97 int vvvv[] = {nv,nv,nv,nv};
98 int vovo[] = {nv,no,nv,no};
99 int vvoo[] = {nv,nv,no,no};
100 int oovv[] = {no,no,nv,nv};
101 int oooo[] = {no,no,no,no};
129 Transform<> fltr([=](
double & d){
if (fabs(d)<sp) d=0.0; });
136 double dense_energy, sparse_energy;
139 dense_energy =
mp3(Ea, Ei, Fab, Fij, Vabij, Vijab, Vabcd, Vijkl, Vaibj, 0);
142 printf(
"Calculated MP3 energy %lf with dense integral tensors.\n",dense_energy);
148 double min_time = DBL_MAX;
149 double max_time = 0.0;
150 double tot_time = 0.0;
154 printf(
"Starting %d benchmarking iterations of dense MP3...\n", niter);
158 for (
int i=0; i<niter; i++){
159 double start_time = MPI_Wtime();
160 mp3(Ea, Ei, Fab, Fij, Vabij, Vijab, Vabcd, Vijkl, Vaibj, 0);
161 double end_time = MPI_Wtime();
162 double iter_time = end_time-start_time;
163 times[i] = iter_time;
164 tot_time += iter_time;
165 if (iter_time < min_time) min_time = iter_time;
166 if (iter_time > max_time) max_time = iter_time;
171 printf(
"Completed %d benchmarking iterations of dense MP3 (no=%d nv=%d sp=%lf).\n", niter, no, nv, sp);
172 printf(
"All iterations times: ");
173 for (
int i=0; i<niter; i++){
174 printf(
"%lf ", times[i]);
177 std::sort(times,times+niter);
178 printf(
"Dense MP3 (no=%d nv=%d sp=%lf p=%d) Min time = %lf, Avg time = %lf, Med time = %lf, Max time = %lf\n",no,nv,sp,dw.
np,min_time,tot_time/niter, times[niter/2], max_time);
190 sparse_energy =
mp3(Ea, Ei, Fab, Fij, Vabij, Vijab, Vabcd, Vijkl, Vaibj, sparse_T);
196 pass = fabs((dense_energy-sparse_energy)/dense_energy)<1.E-6;
201 printf(
"{ third-order Moller-Plesset petrubation theory (MP3) using sparse*dense } passed \n");
203 printf(
"{ third-order Moller-Plesset petrubation theory (MP3) using sparse*dense } failed \n");
206 printf(
"{ third-order Moller-Plesset petrubation theory (MP3) using sparse*sparse } passed \n");
208 printf(
"{ third-order Moller-Plesset petrubation theory (MP3) using sparse*sparse } failed \n");
213 printf(
"Calcluated MP3 energy %lf with sparse integral tensors.\n",sparse_energy);
220 printf(
"Starting %d benchmarking iterations of sparse MP3...\n", niter);
227 for (
int i=0; i<niter; i++){
228 double start_time = MPI_Wtime();
229 mp3(Ea, Ei, Fab, Fij, Vabij, Vijab, Vabcd, Vijkl, Vaibj, sparse_T);
230 double end_time = MPI_Wtime();
231 double iter_time = end_time-start_time;
235 times[i] = iter_time;
236 tot_time += iter_time;
237 if (iter_time < min_time) min_time = iter_time;
238 if (iter_time > max_time) max_time = iter_time;
243 printf(
"Completed %d benchmarking iterations of sparse MP3 (no=%d nv=%d).\n", niter, no, nv);
244 printf(
"All iterations times: ");
245 for (
int i=0; i<niter; i++){
246 printf(
"%lf ", times[i]);
249 std::sort(times,times+niter);
250 printf(
"Sparse MP3 (no=%d nv=%d sp=%lf p=%d spT=%d) Min time = %lf, Avg time = %lf, Med time = %lf, Max time = %lf\n",no,nv,sp,dw.
np,sparse_T,min_time,tot_time/niter, times[niter/2], max_time);
262 char ** itr = std::find(begin, end, option);
263 if (itr != end && ++itr != end){
270 int main(
int argc,
char ** argv){
271 int rank,
np, nv, no, pass, niter, bnd, bns, test;
274 int const in_num = argc;
275 char ** input_str = argv;
277 MPI_Init(&argc, &argv);
278 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
279 MPI_Comm_size(MPI_COMM_WORLD, &np);
282 nv = atoi(
getCmdOption(input_str, input_str+in_num,
"-nv"));
287 no = atoi(
getCmdOption(input_str, input_str+in_num,
"-no"));
292 sp = atof(
getCmdOption(input_str, input_str+in_num,
"-sp"));
293 if (sp < 0.0 || sp > 1.0) sp = .8;
296 if (
getCmdOption(input_str, input_str+in_num,
"-niter")){
297 niter = atof(
getCmdOption(input_str, input_str+in_num,
"-niter"));
298 if (niter < 0) niter = 10;
300 if (
getCmdOption(input_str, input_str+in_num,
"-sparse_T")){
301 sparse_T = (bool)atoi(
getCmdOption(input_str, input_str+in_num,
"-sparse_T"));
305 bnd = atoi(
getCmdOption(input_str, input_str+in_num,
"-bnd"));
306 if (bnd != 0 && bnd != 1) bnd = 0;
310 bns = atoi(
getCmdOption(input_str, input_str+in_num,
"-bns"));
311 if (bns != 0 && bns != 1) bns = 0;
314 if (
getCmdOption(input_str, input_str+in_num,
"-test")){
315 test = atoi(
getCmdOption(input_str, input_str+in_num,
"-test"));
316 if (test != 0 && test != 1) test = 1;
320 printf(
"Running sparse (%lf zeros) third-order Moller-Plesset petrubation theory (MP3) method on %d virtual and %d occupied orbitals and T sparsity turned ot %d\n",sp,nv,no,sparse_T);
325 pass =
sparse_mp3(nv, no, dw, sp, test, niter, bnd, bns, sparse_T);
void update_all_models(MPI_Comm comm)
CTF_int::CommData cdt
communicator data for MPI comm defining this world
Matrix class which encapsulates a 2D tensor.
int sparse_mp3(int nv, int no, World &dw, double sp=.8, bool test=1, int niter=0, bool bnd=1, bool bns=1, bool sparse_T=1)
Vector class which encapsulates a 1D tensor.
dpair operator+(dpair const &p) const
an instance of the CTF library (world) on a MPI communicator
int main(int argc, char **argv)
void divide_EaEi(Tensor<> &Ea, Tensor<> &Ei, Tensor<> &T, bool sparse_T)
CTF::World * wrld
distributed processor context on which tensor is defined
void fill_random(dtype rmin, dtype rmax)
fills local unique tensor elements to random values in the range [min,max] works only for dtype in {f...
int rank
rank of local processor
int * lens
unpadded tensor edge lengths
void print(char const *a, FILE *fp=stdout) const
prints the value
void sparsify()
reduce tensor to sparse format, storing only nonzero data, or data above a specified threshold...
epoch during which to measure timers
dpair(double a_, double b_)
char * getCmdOption(char **begin, char **end, const std::string &option)
A Monoid is a Set equipped with a binary addition operator '+' or a custom function addition must hav...
an instance of a tensor within a CTF world
double mp3(Tensor<> &Ea, Tensor<> &Ei, Tensor<> &Fab, Tensor<> &Fij, Tensor<> &Vabij, Tensor<> &Vijab, Tensor<> &Vabcd, Tensor<> &Vijkl, Tensor<> &Vaibj, bool sparse_T)
int np
number of processors