~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/lib/libdpd/buf4_copy.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*! \file
 
2
    \ingroup DPD
 
3
    \brief Enter brief description of file here 
 
4
*/
 
5
#include <cstdio>
 
6
#include <cstring>
 
7
#include <cmath>
 
8
#include "dpd.h"
 
9
 
 
10
extern "C" {
 
11
        
 
12
/* dpd_buf4_copy(): Copies an existing four-index dpdbuf4 into another file.
 
13
**
 
14
** Arguments:
 
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.
 
18
**
 
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.
 
21
**
 
22
** Converted to use buf4 only rather than assumptions about file4.
 
23
** TDC, September 1999
 
24
*/
 
25
 
 
26
int dpd_buf4_copy(dpdbuf4 *InBuf, int outfilenum, const char *label)
 
27
{
 
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;
 
32
  dpdbuf4 OutBuf;
 
33
 
 
34
  my_irrep = InBuf->file.my_irrep;
 
35
 
 
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);
 
39
 
 
40
  for(h=0; h < InBuf->params->nirreps; h++) {
 
41
 
 
42
    memoryd = dpd_memfree()/2; /* use half the memory for each buf4 */
 
43
 
 
44
    rowtot = InBuf->params->rowtot[h];
 
45
    coltot = InBuf->params->coltot[h^my_irrep];
 
46
 
 
47
    if(rowtot && coltot) {
 
48
 
 
49
      rows_per_bucket = memoryd/coltot;
 
50
      /* enough memory for the whole matrix? */
 
51
      if(rows_per_bucket > rowtot)
 
52
        rows_per_bucket = rowtot;
 
53
 
 
54
      if(!rows_per_bucket) dpd_error("buf4_scmcopy: Not enough memory for one row!", stderr);
 
55
 
 
56
      nbuckets = (int) ceil(((double) rowtot)/((double) rows_per_bucket));
 
57
 
 
58
      rows_left = rowtot % rows_per_bucket;
 
59
 
 
60
      incore = 1;
 
61
      if(nbuckets > 1) {
 
62
        incore = 0;
 
63
#if DPD_DEBUG
 
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");
 
70
#endif
 
71
      }
 
72
 
 
73
      if(incore) {
 
74
 
 
75
 
 
76
        dpd_buf4_mat_irrep_init(InBuf, h);
 
77
        dpd_buf4_mat_irrep_rd(InBuf, h);
 
78
 
 
79
        dpd_buf4_mat_irrep_init(&OutBuf, h);
 
80
 
 
81
        if(rowtot && coltot) 
 
82
          memcpy((void *) &(OutBuf.matrix[h][0][0]),
 
83
                 (const void *) &(InBuf->matrix[h][0][0]),
 
84
                 sizeof(double)*rowtot*coltot);
 
85
 
 
86
        dpd_buf4_mat_irrep_wrt(&OutBuf, h);
 
87
 
 
88
        dpd_buf4_mat_irrep_close(&OutBuf, h);
 
89
        dpd_buf4_mat_irrep_close(InBuf, h);
 
90
      }
 
91
      else {
 
92
 
 
93
        dpd_buf4_mat_irrep_init_block(InBuf, h, rows_per_bucket);
 
94
        dpd_buf4_mat_irrep_init_block(&OutBuf, h, rows_per_bucket);
 
95
 
 
96
        coltot = InBuf->params->coltot[h^my_irrep];
 
97
        size = ((long) rows_per_bucket)*((long) coltot);
 
98
 
 
99
        for(n=0; n < (rows_left ? nbuckets-1 : nbuckets); n++) {
 
100
 
 
101
          dpd_buf4_mat_irrep_rd_block(InBuf, h, n*rows_per_bucket, rows_per_bucket);
 
102
 
 
103
          memcpy((void *) &(OutBuf.matrix[h][0][0]), (const void *) &(InBuf->matrix[h][0][0]), 
 
104
                 ((long) sizeof(double))*size);
 
105
 
 
106
          dpd_buf4_mat_irrep_wrt_block(&OutBuf, h, n*rows_per_bucket, rows_per_bucket);
 
107
        }
 
108
        if(rows_left) {
 
109
 
 
110
          size = ((long) rows_left) * ((long) coltot);
 
111
 
 
112
          dpd_buf4_mat_irrep_rd_block(InBuf, h, n*rows_per_bucket, rows_left);
 
113
 
 
114
          memcpy((void *) &(OutBuf.matrix[h][0][0]), (const void *) &(InBuf->matrix[h][0][0]), 
 
115
                 ((long) sizeof(double))*size);
 
116
 
 
117
          dpd_buf4_mat_irrep_wrt_block(&OutBuf, h, n*rows_per_bucket, rows_left);
 
118
        }
 
119
 
 
120
        dpd_buf4_mat_irrep_close_block(InBuf, h, rows_per_bucket);
 
121
        dpd_buf4_mat_irrep_close_block(&OutBuf, h, rows_per_bucket);
 
122
 
 
123
      }
 
124
    }
 
125
 
 
126
  }
 
127
 
 
128
  dpd_buf4_close(&OutBuf);
 
129
 
 
130
  return 0;
 
131
}
 
132
 
 
133
} /* extern "C" */