@@ -95,89 +95,121 @@ int comparestrings_dyson(struct occstr str0, struct occstr str1, int ninto)
95
95
}
96
96
97
97
/*
98
- * compute_dyson_orbital : compute the dyson orbital between electronic
99
- * states of N+1 and N electron wavefuntions by comparing alpha/ beta strings.
98
+ * compute_dyson_orbital_b : compute the dyson orbital between electronic
99
+ * states of N+1 and N electron wavefuntions by comparing beta strings.
100
100
* Input:
101
101
*
102
102
*/
103
- void compute_dyson_orbital (int v0_hndl , int v1_hndl , int w0_hndl , int w1_hndl ,
104
- struct occstr * pstr0 , struct eospace * peosp0 , int npe0 ,
105
- struct occstr * qstr0 , struct eospace * qeosp0 , int nqe0 ,
106
- struct occstr * pstr1 , struct eospace * peosp1 , int npe1 ,
107
- struct occstr * qstr1 , struct eospace * qeosp1 , int nqe1 ,
108
- int norbs , int ndocc , int nactv , int ndyst0 ,
109
- int * dysnst0 , int ndyst1 , int * dysnst1 , int ndets0 ,
110
- int ndets1 , int sp1 , int sp2 )
103
+ void compute_dyson_orbital_b (int v0_hndl , int v1_hndl , int w0_hndl , int w1_hndl ,
104
+ struct occstr * pstr0 , struct eospace * peosp0 , int npe0 ,
105
+ struct occstr * qstr0 , struct eospace * qeosp0 , int nqe0 ,
106
+ struct occstr * pstr1 , struct eospace * peosp1 , int npe1 ,
107
+ struct occstr * qstr1 , struct eospace * qeosp1 , int nqe1 ,
108
+ int * * pq1 , int npq1 ,
109
+ int norbs , int ndocc , int nactv , int ndyst0 ,
110
+ int * dysnst0 , int ndyst1 , int * dysnst1 , int ndets0 ,
111
+ int ndets1 , int * * strcont , int nbelec0 ,
112
+ double * * dyorb )
111
113
{
112
114
#define MAXBUFFER 10000
113
- /* Local V and W buffers */
114
- double * * v0 = NULL , * v0data = NULL ;
115
- int v0cols = 0 , v0rows = 0 ;
116
- double * * v1 = NULL , * v1data = NULL ;
117
- int v1cols = 0 , v1rows = 0 ;
118
- int * * w0 = NULL , * w0data = NULL ;
119
- int * * w1 = NULL , * w1data = NULL ;
120
- /* GA dimensions for buffers */
121
- int v0_lo [2 ] = {0 , 0 }, v0_hi [2 ] = {0 , 0 }, v0_ld [1 ] = {0 };
122
- int v1_lo [2 ] = {0 , 0 }, v1_hi [2 ] = {0 , 0 }, v1_ld [1 ] = {0 };
123
- int w0_lo [2 ] = {0 , 0 }, w0_hi [2 ] = {0 , 0 }, w0_ld [1 ] = {0 };
124
- int w1_lo [2 ] = {0 , 0 }, w1_hi [2 ] = {0 , 0 }, w1_ld [1 ] = {0 };
125
-
126
- int buflen ;
127
- int i , imax , j , jmax ;
128
- int nvirt ;
129
-
130
- nvirt = norbs - ndocc - nactv ;
115
+ /* (N+1) and (N) Vector arrays */
116
+ double * * v0 = NULL , * v01d = NULL ;
117
+ double * * v1 = NULL , * v11d = NULL ;
118
+ int v0_lo [2 ], v0_hi [2 ], v0_ld [1 ];
119
+ int v1_lo [2 ], v1_hi [2 ], v1_ld [1 ];
120
+ int v0_rows , v0_cols ;
121
+ int v1_rows , v1_cols ;
122
+ /* (N+1) and (N) wavefunction arrays */
123
+ int * * w0 = NULL , * w01d = NULL ;
124
+ int * * w1 = NULL , * w11d = NULL ;
125
+ int w0_lo [2 ], w0_hi [2 ], w0_ld [1 ];
126
+ int w1_lo [2 ], w1_hi [2 ], w1_ld [1 ];
127
+ /* Local variables */
128
+ int p0 , q0 ; /* w0 values */
129
+ int p1 , q1 ; /* w1 values */
130
+ int * j0indx = NULL ; /* Determinant index of |p0,q0> */
131
+ int * j1indx = NULL ; /* Determinant index of |p1,q1> */
132
+ int * o1indx = NULL ; /* Orbital difference of <p0,q0|p1,q1> */
133
+ int nj1 = 0 ;
134
+ int * * vindx = NULL , * vindx1d = NULL ;
135
+ int i , j , k ;
136
+ int cnt ;
131
137
132
- /* Compute dimensions of V0. Allocate array. Get buffer . */
138
+ /* Get local distribution of V0. Allocate array and read in values . */
133
139
NGA_Distribution (v0_hndl , mpi_proc_rank , v0_lo , v0_hi );
134
- v0rows = v0_hi [1 ] - v0_lo [1 ] + 1 ;
135
- v0cols = v0_hi [0 ] - v0_lo [0 ] + 1 ;
136
- v0_ld [0 ]= v0rows ;
137
- v0data = allocate_mem_double_cont (& v0 , v0rows , v0cols );
138
- NGA_Get (v0_hndl , v0_lo , v0_hi , v0data , v0_ld );
139
- /* Get W0 wavefunction information */
140
+ v0_rows = v0_hi [1 ] - v0_lo [1 ] + 1 ;
141
+ v0_cols = v0_hi [0 ] - v0_lo [0 ] + 1 ;
142
+ v0_ld [0 ]= v0_rows ;
143
+ v01d = allocate_mem_double_cont (& v0 , v0_rows , v0_cols );
144
+ NGA_Get (v0_hndl , v0_lo , v0_hi , v01d , v0_ld );
145
+ /* Get corresponding wavefunction information */
146
+ w01d = allocate_mem_int_cont (& w0 , 3 , v0_rows );
140
147
w0_lo [0 ] = v0_lo [1 ];
141
148
w0_lo [1 ] = 0 ;
142
149
w0_hi [0 ] = v0_hi [1 ];
143
150
w0_hi [1 ] = 2 ;
144
- w0data = allocate_mem_int_cont ( & w0 , 3 , v0rows ) ;
145
- NGA_Get (w0_hndl , w0_lo , w0_hi , w0data , w0_ld );
151
+ w0_ld [ 0 ] = 3 ;
152
+ NGA_Get (w0_hndl , w0_lo , w0_hi , w01d , w0_ld );
146
153
147
- buflen = MAXBUFFER ; /* Set buffer length */
154
+ /* Allocate J index array and j-index array to grab V1 values from
155
+ * global array. */
156
+ nj1 = v0_rows * nbelec0 ;
157
+ j0indx = malloc (sizeof (int ) * nj1 );
158
+ j1indx = malloc (sizeof (int ) * nj1 );
159
+ o1indx = malloc (sizeof (int ) * nj1 );
160
+ vindx1d = allocate_mem_int_cont (& vindx , 2 , (ndyst1 * nj1 ));
148
161
149
- /* Get state number for v1 by getting number of columns
150
- * on this process. (Array is distributed by row.) */
151
- NGA_Distribution (v1_hndl , mpi_proc_rank , v1_lo , v1_hi );
152
- v1cols = v1_hi [0 ] - v1_lo [0 ] + 1 ;
153
- v1rows = buflen ;
154
- v1_ld [0 ] = v1rows ;
155
- v1_lo [0 ] = 0 ;
156
- v1_hi [0 ] = 0 ;
157
- v1data = allocate_mem_double_cont (& v1 , v1rows , v1cols );
158
- w1_lo [1 ] = 0 ;
159
- w1_hi [1 ] = 2 ;
160
- w1data = allocate_mem_int_cont (& w1 , 3 , v1rows );
161
-
162
- GA_Sync ();
162
+ /* Allocate local buffer of V1 */
163
+ v11d = allocate_mem_double_cont (& v1 , nj1 , ndyst1 );
163
164
164
- for (i = 0 ; i < ndets1 ; i += buflen ) {
165
- imax = int_min ((i + buflen - 1 ), (ndets1 - 1 ));
166
- v1_lo [1 ] = i ;
167
- v1_hi [1 ] = imax ;
168
- v1rows = v1_hi [1 ] - v1_lo [1 ] + 1 ;
169
- NGA_Get (v1_hndl , v1_lo , v1_hi , v1data , v1_ld );
170
- w1_lo [0 ] = i ;
171
- w1_hi [0 ] = imax ;
172
- NGA_Get (w1_hndl , w1_lo , w1_hi , w1data , w1_ld );
173
-
165
+ /* Loop over w0 = (p,q), finding q'/p' in w1 */
166
+ cnt = 0 ;
167
+ for (i = 0 ; i < v0_rows ; i ++ ) {
168
+ p0 = w0 [i ][0 ];
169
+ q0 = w0 [i ][1 ];
170
+ /* Loop over q' */
171
+ for (j = 0 ; j < nbelec0 ; j ++ ) {
172
+ p1 = p0 ;
173
+ q1 = strcont [q0 ][j ]; /* New string */
174
+ j1indx [cnt ] = string_info_to_determinant (p1 , q1 , peosp1 , npe1 ,
175
+ qeosp1 , nqe1 , pq1 , npq1 );
176
+ o1indx [cnt ] = qstr0 [q0 ].istr [j ] - 1 ;
177
+ j0indx [cnt ] = i ;
178
+ cnt ++ ;
179
+ #ifdef DEBUGGING
180
+ //print_occstring(&(qstr0[q0]), nbelec0, ndocc, nactv);
181
+ //print_occstring(&(qstr1[q1]), (nbelec0 - 1), ndocc, nactv);
182
+ //printf(" | %d >, orbital = %d\n", j1indx[cnt - 1], o1indx[cnt - 1]);
183
+ #endif
184
+ }
174
185
}
175
186
176
- GA_Sync ();
177
- deallocate_mem_cont_int (& w0 , w0data );
178
- deallocate_mem_cont_int (& w1 , w1data );
179
- deallocate_mem_cont (& v0 , v0data );
180
- deallocate_mem_cont (& v1 , v1data );
187
+ /* Get indexes for all columns of J that we need */
188
+ set_ga_det_indexes_spec (j1indx , cnt , ndyst1 , dysnst1 , vindx );
189
+
190
+ /* Get V1 elements */
191
+ NGA_Gather (v1_hndl , v11d , vindx , (cnt * ndyst1 ));
192
+
193
+ /* Loop over contributions */
194
+ for (i = 0 ; i < cnt ; i ++ ) {
195
+
196
+ for (j = 0 ; j < ndyst0 ; j ++ ) {
197
+ for (k = 0 ; k < ndyst1 ; k ++ ) {
198
+ dyorb [j * ndyst1 + k ][o1indx [i ]] += v0 [j ][j0indx [i ]] *
199
+ v1 [k ][j1indx [i ]];
200
+ }
201
+ }
202
+ }
203
+
204
+
205
+ /* Deallocate arrays */
206
+ deallocate_mem_cont (& v0 , v01d );
207
+ deallocate_mem_cont (& v1 , v11d );
208
+ deallocate_mem_cont_int (& w0 , w01d );
209
+ deallocate_mem_cont_int (& vindx , vindx1d );
210
+ free (j0indx );
211
+ free (j1indx );
212
+ free (o1indx );
181
213
return ;
182
214
}
183
215
@@ -299,10 +331,10 @@ void generate_strcontlist(struct occstr *str, int nstr, struct eospace *eosp0,
299
331
newstr .virtx [1 ] = str [i ].virtx [1 ];
300
332
301
333
#ifdef DEBUGGING
302
- printf (" ORIG: " );
303
- print_occstring (str [i ], nelec0 , ndocc , nactv );
304
- printf (" NEW: " );
305
- print_occstring (newstr , nelec1 , ndocc , nactv );
334
+ // printf(" ORIG: ");
335
+ // print_occstring(&( str[i]) , nelec0, ndocc, nactv);
336
+ // printf(" NEW: ");
337
+ // print_occstring(&( newstr) , nelec1, ndocc, nactv);
306
338
#endif
307
339
neospx = get_string_eospace (& newstr , ndocc , nactv , eosp1 , ne1 );
308
340
strcont [i ][cnt ] = occstr2address (& newstr , eosp1 [neospx ], ndocc ,
@@ -311,8 +343,111 @@ void generate_strcontlist(struct occstr *str, int nstr, struct eospace *eosp0,
311
343
}
312
344
/* Loop over external orbital electrons, removing them */
313
345
for (j = 0 ; j < str [i ].nvrtx ; j ++ ) {
314
-
346
+ newstr .byte1 = str [i ].byte1 ;
347
+ newstr .nvrtx = str [i ].nvrtx - 1 ;
348
+ newstr .virtx [0 ] = str [i ].virtx [0 ];
349
+ newstr .virtx [1 ] = str [i ].virtx [1 ];
350
+ newstr .virtx [j ] = 0 ;
351
+ if (j == 0 && str [i ].nvrtx == 2 ) {
352
+ newstr .virtx [0 ] = newstr .virtx [1 ];
353
+ newstr .virtx [1 ] = 0 ;
354
+ }
355
+ #ifdef DEBUGGING
356
+ //printf(" ORIG: ");
357
+ //print_occstring(&(str[i]), nelec0, ndocc, nactv);
358
+ //printf(" NEW: ");
359
+ //print_occstring(&(newstr), nelec1, ndocc, nactv);
360
+ #endif
361
+ neospx = get_string_eospace (& newstr , ndocc , nactv , eosp1 , ne1 );
362
+ strcont [i ][cnt ] = occstr2address (& newstr , eosp1 [neospx ], ndocc ,
363
+ nactv , nvirt , nelec1 , elecx );
364
+ cnt ++ ;
365
+
315
366
}
367
+ //printf("Count: %d\n", cnt);
368
+ }
369
+ return ;
370
+ }
371
+
372
+ /*
373
+ * string_info_to_determinant: compute the determinant index given
374
+ * the p and q string information.
375
+ * Input:
376
+ * pval = p string
377
+ * qval = q string
378
+ * peosp = alpha electron orbital spaces
379
+ * pegrps = number of alpha electron orbital spaces
380
+ * qeosp = beta electron orbital spaces
381
+ * qegrps = number of beta electron orbital spaces
382
+ * pq = (p,q)-space pairings
383
+ * npq = number of (p,q)-space pairings
384
+ * Output:
385
+ * detindx = determinant index in expansion.
386
+ */
387
+ int string_info_to_determinant (int pval , int qval , struct eospace * peosp ,
388
+ int pegrps , struct eospace * qeosp , int qegrps ,
389
+ int * * pq , int npq )
390
+ {
391
+ int i , j , k ;
392
+ int jstart , jmax , kstart , kmax ;
393
+ int iloc , jloc ;
394
+ int cntr = 0 ; /* Counter */
395
+ /* Find space combo for p,q */
396
+ for (i = 0 ; i < pegrps - 1 ; i ++ ) {
397
+ if (pval >= peosp [i ].start && pval < peosp [i + 1 ].start ) break ;
398
+ }
399
+ iloc = i ;
400
+ for (j = 0 ; j < qegrps - 1 ; j ++ ) {
401
+ if (qval >= qeosp [j ].start && qval < qeosp [j + 1 ].start ) break ;
402
+ }
403
+ jloc = j ;
404
+ for (i = 0 ; i < npq ; i ++ ) {
405
+ if (pq [i ][0 ] == iloc && pq [i ][1 ] == jloc ) break ;
406
+ }
407
+ iloc = i ;
408
+ /* p,q pairing is found: i */
409
+ for (i = 0 ; i < iloc ; i ++ ) {
410
+ cntr = cntr + peosp [(pq [i ][0 ])].nstr * qeosp [(pq [i ][1 ])].nstr ;
411
+ }
412
+ /* Search for index */
413
+ jstart = peosp [(pq [iloc ][0 ])].start ;
414
+ kstart = qeosp [(pq [iloc ][1 ])].start ;
415
+ jmax = jstart + peosp [(pq [iloc ][0 ])].nstr ;
416
+ kmax = kstart + qeosp [(pq [iloc ][1 ])].nstr ;
417
+ for (j = jstart ; j < jmax ; j ++ ) {
418
+ for (k = kstart ; k < kmax ; k ++ ) {
419
+ if (j == pval && k == qval ) {
420
+ k = kmax ;
421
+ j = jmax ;
422
+ break ;
423
+ }
424
+ cntr ++ ;
425
+ }
426
+ }
427
+ return cntr ;
428
+ }
429
+
430
+ /*
431
+ * set_ga_det_indexes_spec: set the array of indices to gather from global array.
432
+ * Input:
433
+ * jindx = list of row numbers in vector V
434
+ * num = number of row numbers
435
+ * cols = number of columns of V
436
+ * colindx = column indices
437
+ * Output:
438
+ * vindx = indices of global array V to gather
439
+ */
440
+ void set_ga_det_indexes_spec (int * jindx , int num , int cols , int * colindx ,
441
+ int * * vindx )
442
+ {
443
+ int cntr = 0 ; /* Index counter */
444
+ /* Arrays in global arrays are stored like: [column][row] */
445
+ for (int i = 0 ; i < cols ; i ++ ) {
446
+ for (int j = 0 ; j < num ; j ++ ) {
447
+ vindx [cntr ][0 ] = colindx [i ];
448
+ vindx [cntr ][1 ] = jindx [j ];
449
+ cntr ++ ;
450
+ }
316
451
}
317
452
return ;
318
453
}
0 commit comments