3
\brief Enter brief description of file here
8
#include <libciomr/libciomr.h>
9
#include <libpsio/psio.h>
11
#include <libiwl/iwl.h>
12
#include <libchkpt/chkpt.h>
13
#include <libdpd/dpd.h>
20
void transtwo_rhf(void)
22
int nirreps, nso, nmo;
23
double ***C, **scratch, **TMP;
24
int h, p, q, r, s, pq, rs, Gs, Gr, PQ, RS;
25
int nrows, ncols, nlinks;
26
unsigned long int memfree, rows_per_bucket, rows_left, this_bucket_rows;
33
nirreps = moinfo.nirreps;
37
C_offset = moinfo.C_offset;
39
TMP = block_matrix(nso,nso);
41
if(params.print_lvl) {
42
fprintf(outfile, "\tStarting first half-transformation.\n");
46
psio_open(PSIF_SO_PRESORT, PSIO_OPEN_OLD);
47
psio_open(PSIF_HALFT0, PSIO_OPEN_NEW);
49
timer_on("RHF:1sthalf");
50
dpd_buf4_init(&J, PSIF_SO_PRESORT, 0, 3, 0, 3, 3, 0, "SO Ints (pq,rs)");
51
dpd_buf4_init(&K, PSIF_HALFT0, 0, 3, 5, 3, 8, 0, "Half-Transformed Ints (pq,ij)");
52
for(h=0; h < nirreps; h++) {
54
memfree = (unsigned long int) (dpd_memfree() - J.params->coltot[h] - K.params->coltot[h]);
55
if(J.params->coltot[h]) {
56
rows_per_bucket = memfree/(2 * J.params->coltot[h]);
57
if(rows_per_bucket > J.params->rowtot[h]) rows_per_bucket = (unsigned long int) J.params->rowtot[h];
58
nbuckets = (int) ceil(((double) J.params->rowtot[h])/((double) rows_per_bucket));
59
rows_left = (unsigned long int) (J.params->rowtot[h] % rows_per_bucket);
67
if(params.print_lvl > 1) {
68
fprintf(outfile, "\th = %d; memfree = %lu\n", h, memfree);
69
fprintf(outfile, "\th = %d; rows_per_bucket = %lu\n", h, rows_per_bucket);
70
fprintf(outfile, "\th = %d; rows_left = %lu\n", h, rows_left);
71
fprintf(outfile, "\th = %d; nbuckets = %d\n", h, nbuckets);
75
dpd_buf4_mat_irrep_init_block(&J, h, rows_per_bucket);
76
dpd_buf4_mat_irrep_init_block(&K, h, rows_per_bucket);
78
for(n=0; n < nbuckets; n++) {
79
if(nbuckets == 1) this_bucket_rows = rows_per_bucket;
80
else this_bucket_rows = (n < nbuckets-1) ? rows_per_bucket : rows_left;
81
dpd_buf4_mat_irrep_rd_block(&J, h, n*rows_per_bucket, this_bucket_rows);
82
for(pq=0; pq < this_bucket_rows; pq++) {
83
for(Gr=0; Gr < nirreps; Gr++) {
85
nrows = moinfo.sopi[Gr];
86
ncols = moinfo.actpi[Gs];
87
nlinks = moinfo.sopi[Gs];
88
rs = J.col_offset[h][Gr];
89
if(nrows && ncols && nlinks)
90
C_DGEMM('n','n',nrows,ncols,nlinks,1.0,&J.matrix[h][pq][rs],nlinks,
91
&(C[Gs][0][C_offset[Gs]]),moinfo.mopi[Gs],0.0,TMP[0],nso);
93
nrows = moinfo.actpi[Gr];
94
ncols = moinfo.actpi[Gs];
95
nlinks = moinfo.sopi[Gr];
96
rs = K.col_offset[h][Gr];
97
if(nrows && ncols && nlinks)
98
C_DGEMM('t','n',nrows,ncols,nlinks,1.0,&(C[Gr][0][C_offset[Gr]]),moinfo.mopi[Gr],TMP[0],nso,
99
0.0,&K.matrix[h][pq][rs],ncols);
102
dpd_buf4_mat_irrep_wrt_block(&K, h, n*rows_per_bucket, this_bucket_rows);
105
dpd_buf4_mat_irrep_close_block(&J, h, rows_per_bucket);
106
dpd_buf4_mat_irrep_close_block(&K, h, rows_per_bucket);
111
psio_close(PSIF_SO_PRESORT, 0);
113
timer_off("RHF:1sthalf");
114
timer_on("RHF:midsort");
115
if(params.print_lvl) {
116
fprintf(outfile, "\tSorting half-transformed integrals.\n");
120
psio_open(PSIF_HALFT1, PSIO_OPEN_NEW);
122
dpd_buf4_init(&K, PSIF_HALFT0, 0, 3, 8, 3, 8, 0, "Half-Transformed Ints (pq,ij)");
123
dpd_buf4_sort(&K, PSIF_HALFT1, rspq, 8, 3, "Half-Transformed Ints (ij,pq)");
126
psio_close(PSIF_HALFT0, 0);
127
timer_off("RHF:midsort");
128
timer_on("RHF:2ndhalf");
130
if(params.print_lvl) {
131
fprintf(outfile, "\tStarting second half-transformation.\n");
134
iwl_buf_init(&MBuff, PSIF_MO_TEI, params.tolerance, 0, 0);
136
dpd_buf4_init(&J, PSIF_HALFT1, 0, 8, 0, 8, 3, 0, "Half-Transformed Ints (ij,pq)");
137
dpd_buf4_init(&K, CC_MISC, 0, 8, 5, 8, 8, 0, "MO Ints (ij,kl)");
138
for(h=0; h < nirreps; h++) {
140
memfree = (unsigned long int) (dpd_memfree() - J.params->coltot[h] - K.params->coltot[h]);
141
if(J.params->coltot[h]) {
142
rows_per_bucket = memfree/(2 * J.params->coltot[h]);
143
if(rows_per_bucket > J.params->rowtot[h]) rows_per_bucket = (unsigned long int) J.params->rowtot[h];
144
nbuckets = (int) ceil(((double) J.params->rowtot[h])/((double) rows_per_bucket));
145
rows_left = (unsigned long int) (J.params->rowtot[h] % rows_per_bucket);
153
if(params.print_lvl > 1) {
154
fprintf(outfile, "\th = %d; memfree = %lu\n", h, memfree);
155
fprintf(outfile, "\th = %d; rows_per_bucket = %lu\n", h, rows_per_bucket);
156
fprintf(outfile, "\th = %d; rows_left = %lu\n", h, rows_left);
157
fprintf(outfile, "\th = %d; nbuckets = %d\n", h, nbuckets);
161
dpd_buf4_mat_irrep_init_block(&J, h, rows_per_bucket);
162
dpd_buf4_mat_irrep_init_block(&K, h, rows_per_bucket);
164
for(n=0; n < nbuckets; n++) {
165
if(nbuckets == 1) this_bucket_rows = rows_per_bucket;
166
else this_bucket_rows = (n < nbuckets-1) ? rows_per_bucket : rows_left;
167
dpd_buf4_mat_irrep_rd_block(&J, h, n*rows_per_bucket, this_bucket_rows);
168
for(pq=0; pq < this_bucket_rows; pq++) {
169
for(Gr=0; Gr < nirreps; Gr++) {
171
nrows = moinfo.sopi[Gr];
172
ncols = moinfo.actpi[Gs];
173
nlinks = moinfo.sopi[Gs];
174
rs = J.col_offset[h][Gr];
175
if(nrows && ncols && nlinks)
176
C_DGEMM('n','n',nrows,ncols,nlinks,1.0,&J.matrix[h][pq][rs],nlinks,
177
&(C[Gs][0][C_offset[Gs]]),moinfo.mopi[Gs],0.0,TMP[0],nso);
179
nrows = moinfo.actpi[Gr];
180
ncols = moinfo.actpi[Gs];
181
nlinks = moinfo.sopi[Gr];
182
rs = K.col_offset[h][Gr];
183
if(nrows && ncols && nlinks)
184
C_DGEMM('t','n',nrows,ncols,nlinks,1.0,&(C[Gr][0][C_offset[Gr]]),moinfo.mopi[Gr],TMP[0],nso,
185
0.0,&K.matrix[h][pq][rs],ncols);
188
p = moinfo.pitz2corr_two[K.params->roworb[h][pq+n*rows_per_bucket][0]];
189
q = moinfo.pitz2corr_two[K.params->roworb[h][pq+n*rows_per_bucket][1]];
191
for(rs=0; rs < K.params->coltot[h]; rs++) {
192
r = moinfo.pitz2corr_two[K.params->colorb[h][rs][0]];
193
s = moinfo.pitz2corr_two[K.params->colorb[h][rs][1]];
195
if(r >= s && RS <= PQ)
196
iwl_buf_wrt_val(&MBuff, p, q, r, s, K.matrix[h][pq][rs], params.print_tei, outfile, 0);
200
dpd_buf4_mat_irrep_close_block(&J, h, rows_per_bucket);
201
dpd_buf4_mat_irrep_close_block(&K, h, rows_per_bucket);
206
iwl_buf_flush(&MBuff, 1);
207
iwl_buf_close(&MBuff, 1);
209
timer_off("RHF:2ndhalf");
213
psio_close(PSIF_HALFT1, 0);
215
if(params.print_lvl) {
216
fprintf(outfile, "\tTwo-electron integral transformation complete.\n");
221
} // namespace transqt2