~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/global/testing/testmult.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#if HAVE_CONFIG_H
2
 
#   include "config.h"
3
 
#endif
4
 
 
5
 
#if HAVE_STDIO_H
6
 
#   include <stdio.h>
7
 
#endif
8
 
#if HAVE_STDLIB_H
9
 
#   include <stdlib.h>
10
 
#endif
11
 
#if HAVE_MATH_H
12
 
#   include <math.h>
13
 
#endif
14
 
 
15
 
#include "macdecls.h"
16
 
#include "ga.h"
17
 
#include "mp3.h"
18
 
 
19
 
/* utilities for GA test programs */
20
 
#include "testutil.h"
21
 
 
22
 
#define N 400          /* first dimension  */
23
 
#define BASE 0
24
 
#define PERMUTE_ 
25
 
 
26
 
#define GA_DATA_TYPE MT_C_FLOAT
27
 
#define GA_ABS(a) (((a) >= 0) ? (a) : (-(a)))
28
 
#define TOLERANCE 0.000001
29
 
 
30
 
 
31
 
DoublePrecision gTime=0.0, gStart;
32
 
 
33
 
void
34
 
test(int data_type, int ndim) {
35
 
  int me=GA_Nodeid();
36
 
  int g_a, g_b, g_c, g_A, g_B, g_C;
37
 
  int dims[GA_MAX_DIM]={N,N,2,2,2,1,1};
38
 
  int lo[GA_MAX_DIM]={1,1,1,1,1,0,0};
39
 
  int hi[GA_MAX_DIM]={N-2,N-2,1,1,1,0,0};
40
 
  int clo[2], chi[2], m, n, k;
41
 
  double value1_dbl = 2.0, value2_dbl = 2.0;
42
 
  double alpha_dbl = 1.0, beta_dbl = 0.0;
43
 
  float value1_flt = 2.0, value2_flt = 2.0;
44
 
  float alpha_flt = 1.0, beta_flt = 0.0;
45
 
  DoubleComplex value1_dcpl = {2.0, 2.0}, value2_dcpl = {2.0, 2.0};
46
 
  DoubleComplex alpha_dcpl = {1.0, 0.0} , beta_dcpl = {0.0, 0.0}; 
47
 
  SingleComplex value1_scpl = {2.0, 2.0}, value2_scpl = {2.0, 2.0};
48
 
  SingleComplex alpha_scpl = {1.0, 0.0} , beta_scpl = {0.0, 0.0}; 
49
 
  void *value1=NULL, *value2=NULL, *alpha=NULL, *beta=NULL;
50
 
 
51
 
  switch (data_type) {
52
 
  case C_FLOAT:
53
 
    alpha  = (void *)&alpha_flt;
54
 
    beta   = (void *)&beta_flt;
55
 
    value1 = (void *)&value1_flt;
56
 
    value2 = (void *)&value2_flt;
57
 
    if(me==0) printf("Single Precision: Testing GA_Sgemm,NGA_Matmul_patch for %d-Dimension", ndim);
58
 
    break;      
59
 
  case C_DBL:
60
 
    alpha  = (void *)&alpha_dbl;
61
 
    beta   = (void *)&beta_dbl;
62
 
    value1 = (void *)&value1_dbl;
63
 
    value2 = (void *)&value2_dbl;
64
 
    if(me==0) printf("Double Precision: Testing GA_Dgemm,NGA_Matmul_patch for %d-Dimension", ndim); 
65
 
    break;    
66
 
  case C_DCPL:
67
 
    alpha  = (void *)&alpha_dcpl;
68
 
    beta   = (void *)&beta_dcpl;
69
 
    value1 = (void *)&value1_dcpl;
70
 
    value2 = (void *)&value2_dcpl;
71
 
    if(me==0) printf("Double Complex:   Testing GA_Zgemm,NGA_Matmul_patch for %d-Dimension", ndim);
72
 
    break;
73
 
  case C_SCPL:
74
 
    alpha  = (void *)&alpha_scpl;
75
 
    beta   = (void *)&beta_scpl;
76
 
    value1 = (void *)&value1_scpl;
77
 
    value2 = (void *)&value2_scpl;
78
 
    if(me==0) printf("Single Complex:   Testing GA_Cgemm,NGA_Matmul_patch for %d-Dimension", ndim);
79
 
    break;
80
 
  default:
81
 
    GA_Error("wrong data type", data_type);
82
 
  }
83
 
 
84
 
  g_a = NGA_Create(data_type, ndim, dims, "array A", NULL);
85
 
  g_b = GA_Duplicate(g_a, "array B");  
86
 
  g_c = GA_Duplicate(g_a, "array C");
87
 
  if(!g_a || !g_b || !g_c) GA_Error("Create failed: a, b or c",1);
88
 
 
89
 
  GA_Fill(g_a, value1);
90
 
  GA_Fill(g_b, value2);
91
 
  GA_Zero(g_c);
92
 
 
93
 
  NGA_Matmul_patch('N', 'N', alpha, beta,
94
 
           g_a, lo, hi,
95
 
           g_b, lo, hi,
96
 
           g_c, lo, hi);  
97
 
  GA_Destroy(g_a);
98
 
  GA_Destroy(g_b);
99
 
 
100
 
  /** 
101
 
   * Verifying g_c:
102
 
   * 1. Create g_A(=g_a) and g_B(=g_b)
103
 
   * 2. g_C = g_A*g_B; (Using Gemm routines)
104
 
   * 3. g_A = g_c; (copy the 2-d patch og g_c into g_A)
105
 
   * 4. g_C = g_A - g_C; (Using add() routine by making beta=-1.0)
106
 
   * 5. If all the elements in g_C is zero, implies SUCCESS.
107
 
   */
108
 
  dims[0] = dims[1] = m = n = k = N-2; 
109
 
  g_A = NGA_Create(data_type, 2, dims, "array A_", NULL);
110
 
  g_B = GA_Duplicate(g_A, "array B_");
111
 
  g_C = GA_Duplicate(g_A, "array C_");
112
 
  if(!g_A || !g_B || !g_C) GA_Error("Create failed: A, B or C",n);
113
 
  GA_Fill(g_A, value1);
114
 
  GA_Fill(g_B, value2);
115
 
  GA_Zero(g_C);
116
 
 
117
 
  gStart = MP_TIMER();
118
 
  switch (data_type) {
119
 
  case C_FLOAT:
120
 
    GA_Sgemm('N', 'N', m, n, k, alpha_flt,  g_A, g_B, beta_flt, g_C);
121
 
    beta_flt = -1.0;
122
 
    break;      
123
 
  case C_DBL:
124
 
    GA_Dgemm('N', 'N', m, n, k, alpha_dbl,  g_A, g_B, beta_dbl, g_C);
125
 
    beta_dbl = -1.0;
126
 
    break;    
127
 
  case C_DCPL:
128
 
    GA_Zgemm('N', 'N', m, n, k, alpha_dcpl, g_A, g_B, beta_dcpl, g_C);
129
 
    beta_dcpl.real = -1.0; 
130
 
    break;
131
 
  case C_SCPL:
132
 
    GA_Cgemm('N', 'N', m, n, k, alpha_scpl, g_A, g_B, beta_scpl, g_C);
133
 
    beta_scpl.real = -1.0; 
134
 
    break;
135
 
  default:
136
 
    GA_Error("wrong data type", data_type);
137
 
  }
138
 
  gTime += MP_TIMER()-gStart;
139
 
 
140
 
  GA_Destroy(g_B);
141
 
  
142
 
  clo[0] = clo[1] = 0;
143
 
  chi[0] = chi[1] = N-3;
144
 
 
145
 
  NGA_Copy_patch('N', g_c, lo, hi, g_A, clo, chi) ;
146
 
  
147
 
  GA_Add(alpha, g_A, beta, g_C, g_C);
148
 
  /*  NGA_Add_patch (alpha, g_c, lo, hi, beta, g_C, clo, chi, g_C, clo, chi);*/
149
 
 
150
 
  switch (data_type) {
151
 
  case C_FLOAT:
152
 
    value1_flt = GA_Fdot(g_C, g_C);
153
 
    if(fabsf(value1_flt) > TOLERANCE) {
154
 
      printf("\nabs(result) = %f > %f\n", fabsf(value1_flt), TOLERANCE);
155
 
      GA_Error("GA_Sgemm, NGA_Matmul_patch Failed", 1);
156
 
    }
157
 
    break;
158
 
  case C_DBL:
159
 
    value1_dbl = GA_Ddot(g_C, g_C);
160
 
    if(fabs(value1_dbl) > TOLERANCE) {
161
 
      printf("\nabs(result) = %f > %f\n", fabs(value1_dbl), TOLERANCE);
162
 
      GA_Error("GA_Dgemm, NGA_Matmul_patch Failed", 1);
163
 
    }
164
 
    break;
165
 
  case C_DCPL:
166
 
    value1_dcpl = GA_Zdot(g_C, g_C);
167
 
    if(fabs(value1_dcpl.real) > TOLERANCE
168
 
            || fabs(value1_dcpl.imag) > TOLERANCE) {
169
 
      printf("\nabs(result) = %f+%fi > %f\n",
170
 
              fabs(value1_dcpl.real), fabs(value1_dcpl.imag), TOLERANCE);
171
 
      GA_Error("GA_Zgemm, NGA_Matmul_patch Failed", 1);
172
 
    }
173
 
    break;
174
 
  case C_SCPL:
175
 
    value1_scpl = GA_Cdot(g_C, g_C);
176
 
    if(fabsf(value1_scpl.real) > TOLERANCE
177
 
            || fabsf(value1_scpl.imag) > TOLERANCE) {
178
 
      printf("\nabs(result) = %f+%fi > %f\n",
179
 
              fabsf(value1_scpl.real), fabsf(value1_scpl.imag), TOLERANCE);
180
 
      GA_Error("GA_Sgemm, NGA_Matmul_patch Failed", 1);
181
 
    }
182
 
    break;
183
 
  default:
184
 
    GA_Error("wrong data type", data_type);
185
 
  }  
186
 
  
187
 
  if(me==0) printf("....OK\n");
188
 
 
189
 
  GA_Destroy(g_A);
190
 
  GA_Destroy(g_c);
191
 
  GA_Destroy(g_C);
192
 
}
193
 
 
194
 
void
195
 
do_work() {
196
 
  int i;
197
 
  int me = GA_Nodeid();
198
 
 
199
 
  for(i=2; i<=GA_MAX_DIM; i++) {
200
 
     test(C_FLOAT, i);
201
 
     test(C_DBL,   i);
202
 
     test(C_DCPL,  i);
203
 
     test(C_SCPL,  i);
204
 
     if(me == 0) printf("\n\n");
205
 
    GA_Sync();
206
 
  }
207
 
}
208
 
     
209
 
 
210
 
int 
211
 
main(int argc, char **argv) {
212
 
 
213
 
Integer heap=9000000, stack=9000000;
214
 
int me, nproc;
215
 
DoublePrecision time;
216
 
 
217
 
    MP_INIT(argc,argv);
218
 
 
219
 
    GA_INIT(argc,argv);                           /* initialize GA */
220
 
 
221
 
    nproc = GA_Nnodes();
222
 
    me = GA_Nodeid();
223
 
 
224
 
    if(me==0) printf("Using %d processes\n\n",nproc);
225
 
 
226
 
    if(!MA_init((Integer)MT_F_DBL, stack/nproc, heap/nproc))
227
 
       GA_Error("MA_init failed bytes= %d",stack+heap);   
228
 
 
229
 
#ifdef PERMUTE
230
 
      {
231
 
        int i, *list = (int*)malloc(nproc*sizeof(int));
232
 
        if(!list)GA_Error("malloc failed",nproc);
233
 
 
234
 
        for(i=0; i<nproc;i++)list[i]=nproc-1-i;
235
 
 
236
 
        GA_Register_proclist(list, nproc);
237
 
        free(list);
238
 
      }
239
 
#endif
240
 
 
241
 
    if(GA_Uses_fapi())GA_Error("Program runs with C API only",1);
242
 
 
243
 
    time = MP_TIMER();
244
 
    do_work();
245
 
    /*    printf("%d: Total Time = %lf\n", me, MP_TIMER()-time);
246
 
      printf("%d: GEMM Total Time = %lf\n", me, gTime);
247
 
    */
248
 
 
249
 
    if(me==0)printf("\nSuccess\n\n");
250
 
    GA_Terminate();
251
 
 
252
 
    MP_FINALIZE();
253
 
 
254
 
    return 0;
255
 
}
256