3
\brief Enter brief description of file here
12
/* dpd_buf4_copy(): Copies an existing four-index dpdbuf4 into another file.
15
** dpdbuf4 *InBuf: A pointer to the given dpd buffer.
16
** int outfilenum: The PSI unit number for the new buffer.
17
** char *label: A string labelling for this buffer.
19
** NB: The buffer and file pq/rs parameters are assumed to be
20
** identical for the copy, obviously. Hence, anti flag must be off.
22
** Converted to use buf4 only rather than assumptions about file4.
23
** TDC, September 1999
26
int dpd_buf4_copy(dpdbuf4 *InBuf, int outfilenum, const char *label)
28
int h, row, col, my_irrep;
29
long int rowtot, coltot;
30
int nbuckets, incore, n;
31
long int memoryd, rows_per_bucket, rows_left, size;
34
my_irrep = InBuf->file.my_irrep;
36
dpd_buf4_init(&OutBuf, outfilenum, InBuf->file.my_irrep, InBuf->params->pqnum,
37
InBuf->params->rsnum, InBuf->params->pqnum,
38
InBuf->params->rsnum, 0, label);
40
for(h=0; h < InBuf->params->nirreps; h++) {
42
memoryd = dpd_memfree()/2; /* use half the memory for each buf4 */
44
rowtot = InBuf->params->rowtot[h];
45
coltot = InBuf->params->coltot[h^my_irrep];
47
if(rowtot && coltot) {
49
rows_per_bucket = memoryd/coltot;
50
/* enough memory for the whole matrix? */
51
if(rows_per_bucket > rowtot)
52
rows_per_bucket = rowtot;
54
if(!rows_per_bucket) dpd_error("buf4_scmcopy: Not enough memory for one row!", stderr);
56
nbuckets = (int) ceil(((double) rowtot)/((double) rows_per_bucket));
58
rows_left = rowtot % rows_per_bucket;
64
fprintf(stderr, "buf4_copy: memory information.\n");
65
fprintf(stderr, "buf4_copy: rowtot[%d] = %d.\n", h, InBuf->params->rowtot[h]);
66
fprintf(stderr, "buf4_copy: nbuckets = %d\n", nbuckets);
67
fprintf(stderr, "buf4_copy: rows_per_bucket = %d\n", rows_per_bucket);
68
fprintf(stderr, "buf4_copy: rows_left = %d\n", rows_left);
69
fprintf(stderr, "buf4_copy: out-of-core algorithm used\n");
76
dpd_buf4_mat_irrep_init(InBuf, h);
77
dpd_buf4_mat_irrep_rd(InBuf, h);
79
dpd_buf4_mat_irrep_init(&OutBuf, h);
82
memcpy((void *) &(OutBuf.matrix[h][0][0]),
83
(const void *) &(InBuf->matrix[h][0][0]),
84
sizeof(double)*rowtot*coltot);
86
dpd_buf4_mat_irrep_wrt(&OutBuf, h);
88
dpd_buf4_mat_irrep_close(&OutBuf, h);
89
dpd_buf4_mat_irrep_close(InBuf, h);
93
dpd_buf4_mat_irrep_init_block(InBuf, h, rows_per_bucket);
94
dpd_buf4_mat_irrep_init_block(&OutBuf, h, rows_per_bucket);
96
coltot = InBuf->params->coltot[h^my_irrep];
97
size = ((long) rows_per_bucket)*((long) coltot);
99
for(n=0; n < (rows_left ? nbuckets-1 : nbuckets); n++) {
101
dpd_buf4_mat_irrep_rd_block(InBuf, h, n*rows_per_bucket, rows_per_bucket);
103
memcpy((void *) &(OutBuf.matrix[h][0][0]), (const void *) &(InBuf->matrix[h][0][0]),
104
((long) sizeof(double))*size);
106
dpd_buf4_mat_irrep_wrt_block(&OutBuf, h, n*rows_per_bucket, rows_per_bucket);
110
size = ((long) rows_left) * ((long) coltot);
112
dpd_buf4_mat_irrep_rd_block(InBuf, h, n*rows_per_bucket, rows_left);
114
memcpy((void *) &(OutBuf.matrix[h][0][0]), (const void *) &(InBuf->matrix[h][0][0]),
115
((long) sizeof(double))*size);
117
dpd_buf4_mat_irrep_wrt_block(&OutBuf, h, n*rows_per_bucket, rows_left);
120
dpd_buf4_mat_irrep_close_block(InBuf, h, rows_per_bucket);
121
dpd_buf4_mat_irrep_close_block(&OutBuf, h, rows_per_bucket);
128
dpd_buf4_close(&OutBuf);