~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« back to all changes in this revision

Viewing changes to src/tools/ga-4-3/global/testing/testmult.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2012-02-09 20:02:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209200241-jgk03qfsphal4ug2
Tags: 6.1-1
* New upstream release.

[ Michael Banck ]
* debian/patches/02_makefile_flags.patch: Updated.
* debian/patches/02_makefile_flags.patch: Use internal blas and lapack code.
* debian/patches/02_makefile_flags.patch: Define GCC4 for LINUX and LINUX64
  (Closes: #632611 and LP: #791308).
* debian/control (Build-Depends): Added openssh-client.
* debian/rules (USE_SCALAPACK, SCALAPACK): Removed variables (Closes:
  #654658).
* debian/rules (LIBDIR, USE_MPIF4, ARMCI_NETWORK): New variables.
* debian/TODO: New file.
* debian/control (Build-Depends): Removed libblas-dev, liblapack-dev and
  libscalapack-mpi-dev.
* debian/patches/04_show_testsuite_diff_output.patch: New patch, shows the
  diff output for failed tests.
* debian/patches/series: Adjusted.
* debian/testsuite: Optionally run all tests if "all" is passed as option.
* debian/rules: Run debian/testsuite with "all" if DEB_BUILD_OPTIONS
  contains "checkall".

[ Daniel Leidert ]
* debian/control: Used wrap-and-sort. Added Vcs-Svn and Vcs-Browser fields.
  (Priority): Moved to extra according to policy section 2.5.
  (Standards-Version): Bumped to 3.9.2.
  (Description): Fixed a typo.
* debian/watch: Added.
* debian/patches/03_hurd-i386_define_path_max.patch: Added.
  - Define MAX_PATH if not defines to fix FTBFS on hurd.
* debian/patches/series: Adjusted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include "macdecls.h"
 
4
#include "ga.h"
 
5
#ifdef MPI
 
6
#include <mpi.h>
 
7
#else
 
8
#include "sndrcv.h"
 
9
#endif
 
10
 
 
11
/* utilities for GA test programs */
 
12
#include "testutil.h"
 
13
#include "math.h"
 
14
 
 
15
#define N 400          /* first dimension  */
 
16
#define BASE 0
 
17
#define PERMUTE_ 
 
18
 
 
19
#define GA_DATA_TYPE MT_C_FLOAT
 
20
#define GA_ABS(a) (((a) >= 0) ? (a) : (-(a)))
 
21
#define TOLERANCE 0.000001
 
22
 
 
23
#ifdef MPI
 
24
#define CLOCK_ MPI_Wtime
 
25
#else
 
26
#define CLOCK_ TCGTIME_
 
27
#endif
 
28
 
 
29
DoublePrecision gTime=0.0, gStart;
 
30
 
 
31
void
 
32
test(int data_type, int ndim) {
 
33
  int me=GA_Nodeid(), nproc=GA_Nnodes();
 
34
  int g_a, g_b, g_c, g_A, g_B, g_C;
 
35
  int i;
 
36
  int dims[GA_MAX_DIM]={N,N,2,2,2,1,1};
 
37
  int lo[GA_MAX_DIM]={1,1,1,1,1,0,0};
 
38
  int hi[GA_MAX_DIM]={N-2,N-2,1,1,1,0,0};
 
39
  int clo[2], chi[2], m, n, k;
 
40
  int ld[GA_MAX_DIM]={N-2,1,1,1,0,0};
 
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, *value2, *alpha, *beta;
 
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",0);
 
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 = CLOCK_();
 
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 += CLOCK_()-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(value1_flt != 0.0)
 
154
      GA_Error("GA_Sgemm, NGA_Matmul_patch Failed", 0);
 
155
    break;
 
156
  case C_DBL:
 
157
    value1_dbl = GA_Ddot(g_C, g_C);
 
158
    if(value1_dbl != 0.0)
 
159
      GA_Error("GA_Dgemm, NGA_Matmul_patch Failed", 0);
 
160
    break;
 
161
  case C_DCPL:
 
162
    value1_dcpl = GA_Zdot(g_C, g_C);
 
163
    if(value1_dcpl.real != 0.0 || value1_dcpl.imag != 0.0)
 
164
      GA_Error("GA_Zgemm, NGA_Matmul_patch Failed", 0);
 
165
    break;
 
166
  case C_SCPL:
 
167
    value1_scpl = GA_Cdot(g_C, g_C);
 
168
    if(value1_scpl.real != 0.0 || value1_scpl.imag != 0.0)
 
169
      GA_Error("GA_Sgemm, NGA_Matmul_patch Failed", 0);
 
170
    break;
 
171
  default:
 
172
    GA_Error("wrong data type", data_type);
 
173
  }  
 
174
  
 
175
  if(me==0) printf("....OK\n");
 
176
 
 
177
  GA_Destroy(g_A);
 
178
  GA_Destroy(g_c);
 
179
  GA_Destroy(g_C);
 
180
}
 
181
 
 
182
void
 
183
do_work() {
 
184
  int i;
 
185
  int me = GA_Nodeid();
 
186
 
 
187
  for(i=2; i<=GA_MAX_DIM; i++) {
 
188
     test(C_FLOAT, i);
 
189
     test(C_DBL,   i);
 
190
     test(C_DCPL,  i);
 
191
     test(C_SCPL,  i);
 
192
     if(me == 0) printf("\n\n");
 
193
    GA_Sync();
 
194
  }
 
195
}
 
196
     
 
197
 
 
198
int 
 
199
main(int argc, char **argv) {
 
200
 
 
201
Integer heap=9000000, stack=9000000;
 
202
int me, nproc;
 
203
DoublePrecision time;
 
204
 
 
205
#ifdef MPI
 
206
#ifdef DCMF
 
207
    int desired = MPI_THREAD_MULTIPLE;
 
208
    int provided;
 
209
    MPI_Init_thread(&argc, &argv, desired, &provided);
 
210
    if ( provided != MPI_THREAD_MULTIPLE ) printf("provided != MPI_THREAD_MULTIPLE\n");
 
211
#else
 
212
  MPI_Init (&argc, &argv);      /* initialize MPI */
 
213
#endif
 
214
#else
 
215
    PBEGIN_(argc, argv);                        /* initialize TCGMSG */
 
216
#endif
 
217
 
 
218
    GA_Initialize();                           /* initialize GA */
 
219
 
 
220
    nproc = GA_Nnodes();
 
221
    me = GA_Nodeid();
 
222
 
 
223
    if(me==0) printf("Using %d processes\n\n",nproc);
 
224
 
 
225
    if(!MA_init((Integer)MT_F_DBL, stack/nproc, heap/nproc))
 
226
       GA_Error("MA_init failed bytes= %d",stack+heap);   
 
227
 
 
228
#ifdef PERMUTE
 
229
      {
 
230
        int i, *list = (int*)malloc(nproc*sizeof(int));
 
231
        if(!list)GA_Error("malloc failed",nproc);
 
232
 
 
233
        for(i=0; i<nproc;i++)list[i]=nproc-1-i;
 
234
 
 
235
        GA_Register_proclist(list, nproc);
 
236
        free(list);
 
237
      }
 
238
#endif
 
239
 
 
240
    if(GA_Uses_fapi())GA_Error("Program runs with C API only",0);
 
241
 
 
242
    time = CLOCK_();
 
243
    do_work();
 
244
    /*    printf("%d: Total Time = %lf\n", me, CLOCK_()-time);
 
245
          printf("%d: GEMM Total Time = %lf\n", me, gTime);
 
246
    */
 
247
 
 
248
    if(me==0)printf("\nSuccess\n\n");
 
249
    GA_Terminate();
 
250
 
 
251
#ifdef MPI
 
252
    MPI_Finalize();
 
253
#else
 
254
    PEND_();
 
255
#endif
 
256
 
 
257
    return 0;
 
258
}
 
259