38 int shapeASAS[] = {
AS,
NS,
AS,NS};
39 int shapeASNS[] = {
AS,
NS,
NS,NS};
40 int shapeNSNS[] = {
NS,
NS,
NS,NS};
41 int shapeNSAS[] = {
NS,
NS,
AS,NS};
42 int vvvv[] = {nv,nv,nv,nv};
43 int vvvo[] = {nv,nv,nv,no};
44 int vovv[] = {nv,no,nv,nv};
45 int vovo[] = {nv,no,nv,no};
46 int vvoo[] = {nv,nv,no,no};
47 int oovv[] = {no,no,nv,nv};
48 int vooo[] = {nv,no,no,no};
49 int oovo[] = {no,no,nv,no};
50 int oooo[] = {no,no,no,no};
62 abcd =
new Tensor<>(4,vvvv,shapeASAS,dw_,
"Vabcd",1);
63 abci =
new Tensor<>(4,vvvo,shapeASNS,dw_,
"Vabci",1);
64 aibc =
new Tensor<>(4,vovv,shapeNSAS,dw_,
"Vaibc",1);
65 aibj =
new Tensor<>(4,vovo,shapeNSNS,dw_,
"Vaibj",1);
66 abij =
new Tensor<>(4,vvoo,shapeASAS,dw_,
"Vabij",1);
67 ijab =
new Tensor<>(4,oovv,shapeASAS,dw_,
"Vijab",1);
68 aijk =
new Tensor<>(4,vooo,shapeNSAS,dw_,
"Vaijk",1);
69 ijak =
new Tensor<>(4,oovo,shapeASNS,dw_,
"Vijak",1);
70 ijkl =
new Tensor<>(4,oooo,shapeASAS,dw_,
"Vijkl",1);
95 int64_t j, sz, * indices;
98 Tensor<> * tarr[] = {aa, ii, ab, ai, ia, ij,
99 abcd, abci, aibc, aibj,
100 abij, ijab, aijk, ijak, ijkl};
102 MPI_Comm_rank(comm, &rank);
106 for (i=0; i<15; i++){
109 for (j=0; j<sz; j++) values[j] = ((indices[j]*16+i)%13077)/13077. -.5;
110 tarr[i]->
write(sz, indices, values);
111 free(indices),
delete [] values;
117 lenm = strlen(idx_map_);
118 char new_idx_map[lenm+1];
119 new_idx_map[lenm]=
'\0';
122 for (i=0; i<lenm; i++){
123 if (idx_map_[i] >=
'a' && idx_map_[i] <=
'h'){
124 new_idx_map[i] =
'a'+nv;
126 }
else if (idx_map_[i] >=
'i' && idx_map_[i] <=
'n'){
127 new_idx_map[i] =
'i'+no;
132 if (0 == strcmp(
"a",new_idx_map))
return (*aa)[idx_map_];
133 if (0 == strcmp(
"i",new_idx_map))
return (*ii)[idx_map_];
134 if (0 == strcmp(
"ab",new_idx_map))
return (*ab)[idx_map_];
135 if (0 == strcmp(
"ai",new_idx_map))
return (*ai)[idx_map_];
136 if (0 == strcmp(
"ia",new_idx_map))
return (*ia)[idx_map_];
137 if (0 == strcmp(
"ij",new_idx_map))
return (*ij)[idx_map_];
138 if (0 == strcmp(
"abcd",new_idx_map))
return (*abcd)[idx_map_];
139 if (0 == strcmp(
"abci",new_idx_map))
return (*abci)[idx_map_];
140 if (0 == strcmp(
"aibc",new_idx_map))
return (*aibc)[idx_map_];
141 if (0 == strcmp(
"aibj",new_idx_map))
return (*aibj)[idx_map_];
142 if (0 == strcmp(
"abij",new_idx_map))
return (*abij)[idx_map_];
143 if (0 == strcmp(
"ijab",new_idx_map))
return (*ijab)[idx_map_];
144 if (0 == strcmp(
"aijk",new_idx_map))
return (*aijk)[idx_map_];
145 if (0 == strcmp(
"ijak",new_idx_map))
return (*ijak)[idx_map_];
146 if (0 == strcmp(
"ijkl",new_idx_map))
return (*ijkl)[idx_map_];
147 printf(
"Invalid integral indices\n");
150 return (*aa)[idx_map_];
162 int shapeASAS[] = {
AS,
NS,
AS,NS};
163 int vvoo[] = {nv,nv,no,no};
166 abij =
new Tensor<>(4,vvoo,shapeASAS,dw_,
"Tabij",1);
175 if (strlen(idx_map_) == 4)
return (*abij)[idx_map_];
176 else return (*ai)[idx_map_];
181 int64_t j, sz, * indices;
186 MPI_Comm_rank(comm, &rank);
193 for (j=0; j<sz; j++) values[j] = ((indices[j]*13+i)%13077)/13077. -.5;
194 tarr[i]->
write(sz, indices, values);
195 free(indices),
delete [] values;
202 int sched_nparts = 0){
203 int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank);
205 double timer = MPI_Wtime();
206 tCTF_Schedule<double> sched(V.
dw);
207 sched.set_max_partitions(sched_nparts);
212 T21[
"abij"] += .5*T[
"ai"]*T[
"bj"];
217 Fme += V[
"mnef"]*T[
"fn"];
223 Fae -=.5*V[
"mnef"]*T[
"afmn"];
224 Fae += V[
"anef"]*T[
"fn"];
230 Fmi += .5*V[
"mnef"]*T[
"efin"];
231 Fmi += V[
"mnfi"]*T[
"fn"];
237 Wmnei += V[
"mnef"]*T[
"fi"];
242 Wmnij -= V[
"mnei"]*T[
"ej"];
243 Wmnij += V[
"mnef"]*T21[
"efij"];
248 Wamei -= Wmnei*T[
"an"];
249 Wamei += V[
"amef"]*T[
"fi"];
250 Wamei += .5*V[
"mnef"]*T[
"afin"];
255 Wamij += V[
"amei"]*T[
"ej"];
256 Wamij += V[
"amef"]*T[
"efij"];
262 Zai += V[
"ae"]*T[
"ei"];
263 Zai += V[
"amei"]*T[
"em"];
264 Zai += V[
"aeim"]*Fme;
265 Zai += .5*V[
"amef"]*T21[
"efim"];
266 Zai -= .5*Wmnei*T21[
"eamn"];
271 Zabij += V[
"abei"]*T[
"ej"];
272 Zabij += Wamei*T[
"ebmj"];
273 Zabij -= Wamij*T[
"bm"];
274 Zabij += Fae*T[
"ebij"];
275 Zabij -= Fmi*T[
"abmj"];
276 Zabij += .5*V[
"abef"]*T21[
"efij"];
277 Zabij += .5*Wmnij*T21[
"abmn"];
281 printf(
"Record: %lf\n",
286 tCTF_ScheduleTimer schedule_time = sched.execute();
291 int sh_sym[4] = {
SH,
NS,
SH, NS};
296 Dabij[
"abij"] += V[
"i"];
297 Dabij[
"abij"] += V[
"j"];
298 Dabij[
"abij"] -= V[
"a"];
299 Dabij[
"abij"] -= V[
"b"];
304 T.ai->contract(1.0, *(Zai.
parent),
"ai", Dai,
"ai", 0.0,
"ai", fctr);
305 T.abij->contract(1.0, *(Zabij.
parent),
"abij", Dabij,
"abij", 0.0,
"abij", fctr);
308 printf(
"Schedule comm down: %lf\n", schedule_time.comm_down_time);
309 printf(
"Schedule execute: %lf\n", schedule_time.exec_time);
310 printf(
"Schedule imbalance, wall: %lf\n", schedule_time.imbalance_wall_time);
311 printf(
"Schedule imbalance, accum: %lf\n", schedule_time.imbalance_acuum_time);
312 printf(
"Schedule comm up: %lf\n", schedule_time.comm_up_time);
313 printf(
"Schedule total: %lf\n", schedule_time.total_time);
314 printf(
"All execute: %lf\n",
325 char ** itr = std::find(begin, end, option);
326 if (itr != end && ++itr != end){
333 int main(
int argc,
char ** argv){
334 int rank,
np, niter, no, nv, sched_nparts, i;
335 int const in_num = argc;
336 char ** input_str = argv;
338 MPI_Init(&argc, &argv);
339 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
340 MPI_Comm_size(MPI_COMM_WORLD, &np);
343 no = atoi(
getCmdOption(input_str, input_str+in_num,
"-no"));
347 nv = atoi(
getCmdOption(input_str, input_str+in_num,
"-nv"));
350 if (
getCmdOption(input_str, input_str+in_num,
"-niter")){
351 niter = atoi(
getCmdOption(input_str, input_str+in_num,
"-niter"));
352 if (niter < 0) niter = 1;
354 if (
getCmdOption(input_str, input_str+in_num,
"-nparts")){
355 sched_nparts = atoi(
getCmdOption(input_str, input_str+in_num,
"-nparts"));
356 if (sched_nparts < 0) sched_nparts = 0;
357 }
else sched_nparts = 0;
360 World dw(argc, argv);
367 for (i=0; i<niter; i++){
369 double d = MPI_Wtime();
370 ccsd(V,T,sched_nparts);
372 printf(
"(%d nodes) Completed %dth CCSD iteration in time = %lf, |T| is %lf\n",
378 T[
"ai"] = (1./T.
ai->
norm2())*T[
"ai"];
379 T[
"abij"] = (1./T.
abij->
norm2())*T[
"abij"];
Idx_Tensor operator[](char const *idx_map_)
int * sym
symmetries among tensor dimensions
Idx_Tensor operator[](char const *idx_map_)
double divide(double a, double b)
an instance of the CTF library (world) on a MPI communicator
int main(int argc, char **argv)
dtype norm2()
computes the frobenius norm of the tensor (needs sqrt()!)
int * lens
unpadded tensor edge lengths
Amplitudes(int no, int nv, World &dw_)
epoch during which to measure timers
Integrals(int no, int nv, World &dw_)
void get_local_data(int64_t *npair, int64_t **global_idx, dtype **data, bool nonzeros_only=false, bool unpack_sym=false) const
Gives the global indices and values associated with the local data.
char * getCmdOption(char **begin, char **end, const std::string &option)
an instance of a tensor within a CTF world
a tensor with an index map associated with it (necessary for overloaded operators) ...
void ccsd(Integrals &V, Amplitudes &T, int sched_nparts=0)
void write(int64_t npair, int64_t const *global_idx, dtype const *data)
writes in values associated with any set of indices The sparse data is defined in coordinate format...
MPI_Comm comm
set of processors making up this world