~ubuntu-branches/ubuntu/vivid/psicode/vivid

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2008-06-07 16:49:57 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080607164957-8pifvb133yjlkagn
Tags: 3.3.0-3
* debian/rules (DEB_MAKE_CHECK_TARGET): Do not abort test suite on
  failures.
* debian/rules (DEB_CONFIGURE_EXTRA_FLAGS): Set ${bindir} to /usr/lib/psi.
* debian/rules (install/psi3): Move psi3 file to /usr/bin.
* debian/patches/07_464867_move_executables.dpatch: New patch, add
  /usr/lib/psi to the $PATH, so that the moved executables are found.
  (closes: #464867)
* debian/patches/00list: Adjusted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <stdio.h>
2
2
#include <string.h>
 
3
#include <math.h>
3
4
#include "dpd.h"
4
5
 
5
6
/* dpd_buf4_copy(): Copies an existing four-index dpdbuf4 into another file.
20
21
{
21
22
  int h, row, col, my_irrep;
22
23
  long int rowtot, coltot;
 
24
  int nbuckets, incore, n;
 
25
  long int memoryd, rows_per_bucket, rows_left, size;
23
26
  dpdbuf4 OutBuf;
24
27
 
25
28
  my_irrep = InBuf->file.my_irrep;
30
33
 
31
34
  for(h=0; h < InBuf->params->nirreps; h++) {
32
35
 
33
 
      dpd_buf4_mat_irrep_init(InBuf, h);
34
 
      dpd_buf4_mat_irrep_rd(InBuf, h);
35
 
 
36
 
      dpd_buf4_mat_irrep_init(&OutBuf, h);
37
 
 
38
 
/*
39
 
      for(row=0; row < InBuf->params->rowtot[h]; row++) {
40
 
          for(col=0; col < InBuf->params->coltot[h^my_irrep]; col++) {
41
 
              OutBuf.matrix[h][row][col] = InBuf->matrix[h][row][col];
42
 
            }
43
 
        }
44
 
*/
45
 
 
46
 
      /* Use memcpy() instead of element by element copy */
47
 
      rowtot = InBuf->params->rowtot[h];
48
 
      coltot = InBuf->params->coltot[h^my_irrep];
49
 
 
50
 
      if(rowtot && coltot) 
51
 
          memcpy((void *) &(OutBuf.matrix[h][0][0]),
52
 
                 (const void *) &(InBuf->matrix[h][0][0]),
53
 
                 sizeof(double)*rowtot*coltot);
54
 
 
55
 
      dpd_buf4_mat_irrep_wrt(&OutBuf, h);
56
 
 
57
 
      dpd_buf4_mat_irrep_close(&OutBuf, h);
58
 
      dpd_buf4_mat_irrep_close(InBuf, h);
 
36
    memoryd = dpd_memfree()/2; /* use half the memory for each buf4 */
 
37
 
 
38
    rowtot = InBuf->params->rowtot[h];
 
39
    coltot = InBuf->params->coltot[h^my_irrep];
 
40
 
 
41
    if(rowtot && coltot) {
 
42
 
 
43
      rows_per_bucket = memoryd/coltot;
 
44
      /* enough memory for the whole matrix? */
 
45
      if(rows_per_bucket > rowtot)
 
46
        rows_per_bucket = rowtot;
 
47
 
 
48
      if(!rows_per_bucket) dpd_error("buf4_scmcopy: Not enough memory for one row!", stderr);
 
49
 
 
50
      nbuckets = (int) ceil(((double) rowtot)/((double) rows_per_bucket));
 
51
 
 
52
      rows_left = rowtot % rows_per_bucket;
 
53
 
 
54
      incore = 1;
 
55
      if(nbuckets > 1) {
 
56
        incore = 0;
 
57
#if DPD_DEBUG
 
58
        fprintf(stderr, "buf4_copy: memory information.\n");
 
59
        fprintf(stderr, "buf4_copy: rowtot[%d] = %d.\n", h, InBuf->params->rowtot[h]);
 
60
        fprintf(stderr, "buf4_copy: nbuckets = %d\n", nbuckets);
 
61
        fprintf(stderr, "buf4_copy: rows_per_bucket = %d\n", rows_per_bucket);
 
62
        fprintf(stderr, "buf4_copy: rows_left = %d\n", rows_left);
 
63
        fprintf(stderr, "buf4_copy: out-of-core algorithm used\n");
 
64
#endif
 
65
      }
 
66
 
 
67
      if(incore) {
 
68
 
 
69
 
 
70
        dpd_buf4_mat_irrep_init(InBuf, h);
 
71
        dpd_buf4_mat_irrep_rd(InBuf, h);
 
72
 
 
73
        dpd_buf4_mat_irrep_init(&OutBuf, h);
 
74
 
 
75
        if(rowtot && coltot) 
 
76
          memcpy((void *) &(OutBuf.matrix[h][0][0]),
 
77
                 (const void *) &(InBuf->matrix[h][0][0]),
 
78
                 sizeof(double)*rowtot*coltot);
 
79
 
 
80
        dpd_buf4_mat_irrep_wrt(&OutBuf, h);
 
81
 
 
82
        dpd_buf4_mat_irrep_close(&OutBuf, h);
 
83
        dpd_buf4_mat_irrep_close(InBuf, h);
 
84
      }
 
85
      else {
 
86
 
 
87
        dpd_buf4_mat_irrep_init_block(InBuf, h, rows_per_bucket);
 
88
        dpd_buf4_mat_irrep_init_block(&OutBuf, h, rows_per_bucket);
 
89
 
 
90
        coltot = InBuf->params->coltot[h^my_irrep];
 
91
        size = ((long) rows_per_bucket)*((long) coltot);
 
92
 
 
93
        for(n=0; n < (rows_left ? nbuckets-1 : nbuckets); n++) {
 
94
 
 
95
          dpd_buf4_mat_irrep_rd_block(InBuf, h, n*rows_per_bucket, rows_per_bucket);
 
96
 
 
97
          memcpy((void *) &(OutBuf.matrix[h][0][0]), (const void *) &(InBuf->matrix[h][0][0]), 
 
98
                 ((long) sizeof(double))*size);
 
99
 
 
100
          dpd_buf4_mat_irrep_wrt_block(&OutBuf, h, n*rows_per_bucket, rows_per_bucket);
 
101
        }
 
102
        if(rows_left) {
 
103
 
 
104
          size = ((long) rows_left) * ((long) coltot);
 
105
 
 
106
          dpd_buf4_mat_irrep_rd_block(InBuf, h, n*rows_per_bucket, rows_left);
 
107
 
 
108
          memcpy((void *) &(OutBuf.matrix[h][0][0]), (const void *) &(InBuf->matrix[h][0][0]), 
 
109
                 ((long) sizeof(double))*size);
 
110
 
 
111
          dpd_buf4_mat_irrep_wrt_block(&OutBuf, h, n*rows_per_bucket, rows_left);
 
112
        }
 
113
 
 
114
        dpd_buf4_mat_irrep_close_block(InBuf, h, rows_per_bucket);
 
115
        dpd_buf4_mat_irrep_close_block(&OutBuf, h, rows_per_bucket);
 
116
 
 
117
      }
59
118
    }
60
119
 
 
120
  }
 
121
 
61
122
  dpd_buf4_close(&OutBuf);
62
123
 
63
124
  return 0;