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

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/global/testing/ntestc.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
 
 
12
 
#include "macdecls.h"
13
 
#include "ga.h"
14
 
#include "mp3.h"
15
 
 
16
 
/* utilities for GA test programs */
17
 
#include "testutil.h"
18
 
 
19
 
#define N 10            /* first dimension  */
20
 
#define NDIM 4          /* number of dimensions */
21
 
#define BASE 0
22
 
#define PERMUTE_ 
23
 
 
24
 
/*#define NEW_API*/
25
 
 
26
 
 
27
 
/*\ fill n-dimensional array section with value
28
 
\*/
29
 
void fill_patch(double *ptr, int dim[], int ld[], int ndim, double val)
30
 
{
31
 
     int i, j, stride=1;
32
 
 
33
 
     switch (ndim){
34
 
     case 0: GA_Error("fill_patch: error",ndim);
35
 
     case 1: for(i=0;i <dim[0];i++)ptr[i]=val;
36
 
             break;
37
 
     case 2: for(i=0; i< dim[0]; i++){
38
 
               double *arr = ptr + i*ld[0];
39
 
               for(j=0; j< dim[1]; j++)arr[j]=val; 
40
 
             }
41
 
             break;
42
 
     default: 
43
 
             for(i=0; i<ndim-1; i++)stride *=ld[i];
44
 
             for(i=0; i<dim[0]; i++){
45
 
                 double *arr = ptr + stride*i;
46
 
                 fill_patch(arr, dim+1, ld+1, ndim-1, val);
47
 
             } 
48
 
     }
49
 
}
50
 
        
51
 
 
52
 
 
53
 
void do_work()
54
 
{
55
 
int g_a, g_b;
56
 
int me=GA_Nodeid(), nproc=GA_Nnodes(), proc, loop;
57
 
int dims[NDIM], lo[NDIM], hi[NDIM], block[NDIM], ld[NDIM-1];
58
 
int64_t lo64[NDIM], hi64[NDIM];
59
 
int i,d,*proclist, offset;
60
 
int adims[NDIM], ndim,type;
61
 
typedef struct {
62
 
       int lo[NDIM];
63
 
       int hi[NDIM];
64
 
} patch_t;
65
 
patch_t *regions;
66
 
int *map;
67
 
double *buf;
68
 
 
69
 
     /***** create array A with default distribution  *****/
70
 
     if(me==0){printf("Creating array A\n"); fflush(stdout);}
71
 
     for(i = 0; i<NDIM; i++)dims[i] = N*(i+1);
72
 
#ifdef NEW_API
73
 
     g_a = GA_Create_handle();
74
 
     GA_Set_data(g_a,NDIM,dims,MT_F_DBL);
75
 
     GA_Set_array_name(g_a,"array A");
76
 
     (void)GA_Allocate(g_a);
77
 
#else
78
 
     g_a = NGA_Create(MT_F_DBL, NDIM, dims, "array A", NULL);
79
 
#endif
80
 
     if(!g_a) GA_Error("create failed: A",1); 
81
 
     if(me==0)printf("OK\n\n");
82
 
 
83
 
     /* print info about array we got */
84
 
     NGA_Inquire(g_a, &type, &ndim, adims);
85
 
     GA_Print_distribution(g_a);
86
 
 
87
 
     GA_Sync();
88
 
     /* duplicate array A with ga_create irreg rather than ga_duplicate
89
 
      * -- want to show distribution control 
90
 
      * -- with ga_duplicate it would be g_b=GA_Duplicate(g_a,name) 
91
 
      */
92
 
     if(me==0)printf("\nReconstructing distribution description for A\n");
93
 
 
94
 
     /* get memory for arrays describing distribution */
95
 
     proclist = (int*)malloc(nproc*sizeof(int));
96
 
     if(!proclist)GA_Error("malloc failed for proclist",1);
97
 
     regions = (patch_t*)malloc(nproc*sizeof(patch_t));
98
 
     if(!regions)GA_Error("malloc failed for regions",1);
99
 
     map = (int*)malloc((nproc+ndim)*sizeof(int)); /* ubound= nproc+mdim */
100
 
     if(!map)GA_Error("malloc failed for map",1);
101
 
 
102
 
     /* first find out how array g_a is distributed */
103
 
     for(i=0;i<ndim;i++)lo[i]=BASE;
104
 
     for(i=0;i<ndim;i++)hi[i]=adims[i] -1 + BASE;
105
 
     for(i=0;i<ndim;i++)lo64[i]=BASE;
106
 
     for(i=0;i<ndim;i++)hi64[i]=adims[i] -1 + BASE;
107
 
     proc = NGA_Locate_nnodes(g_a, lo, hi);
108
 
     if(proc<1) GA_Error("error in NGA_Locate_nnodes",proc);
109
 
     proc = NGA_Locate_nnodes64(g_a, lo64, hi64);
110
 
     if(proc<1) GA_Error("error in NGA_Locate_nnodes",proc);
111
 
     proc = NGA_Locate_region(g_a, lo, hi, (int*)regions, proclist);
112
 
     if(proc<1) GA_Error("error in NGA_Locate_region",proc);
113
 
 
114
 
     /* determine blocking for each dimension */
115
 
     for(i=0;i<ndim;i++)block[i]=0;
116
 
     for(i=0;i<ndim;i++)adims[i]=0;
117
 
     
118
 
     offset =0;
119
 
     for(d=0; d<ndim; d++)
120
 
         for(i=0;i<proc;i++)
121
 
             if( regions[i].hi[d]>adims[d] ){
122
 
                map[offset] = regions[i].lo[d];
123
 
                offset++;
124
 
                block[d]++;
125
 
                adims[d]= regions[i].hi[d];
126
 
             }
127
 
            
128
 
     if(me==0){
129
 
        printf("Distribution map contains %d elements\n",offset); 
130
 
        print_subscript("number of blocks for each dimension",ndim,block,"\n");
131
 
        print_subscript("distribution map",offset,map,"\n\n");
132
 
        fflush(stdout);
133
 
     }
134
 
     
135
 
     if(me==0)printf("Creating array B applying distribution of A\n");
136
 
 
137
 
#    ifdef USE_DUPLICATE
138
 
       g_b = GA_Duplicate(g_a,"array B");
139
 
#    else
140
 
       g_b = NGA_Create_irreg(MT_F_DBL, NDIM, dims, "array B", block,map);
141
 
#    endif
142
 
     if(!g_b) GA_Error("create failed: B",1); 
143
 
     if(me==0)printf("OK\n\n");
144
 
     free(proclist); free(regions); free(map);
145
 
     
146
 
     GA_Print_distribution(g_b);
147
 
 
148
 
     GA_Sync();
149
 
 
150
 
     if(me==0){
151
 
       printf("\nCompare distributions of A and B\n");
152
 
       if(GA_Compare_distr(g_a,g_b))
153
 
          printf("Failure: distributions NOT identical\n");
154
 
       else 
155
 
          printf("Success: distributions identical\n");
156
 
       fflush(stdout);
157
 
     }
158
 
       
159
 
 
160
 
     if(me==0){
161
 
        printf("\nAccessing local elements of A: set them to the owner process id\n");
162
 
        fflush(stdout);
163
 
     }
164
 
     GA_Sync();
165
 
 
166
 
     NGA_Distribution(g_a,me,lo,hi);
167
 
 
168
 
     if(hi[0]>=0){/* -1 means no elements stored on this processor */
169
 
         double *ptr;
170
 
         int locdim[NDIM];
171
 
         NGA_Access(g_a, lo,hi, &ptr, ld);
172
 
         for(i=0;i<ndim;i++)locdim[i]=hi[i]-lo[i]+1;
173
 
         fill_patch(ptr, locdim, ld, ndim,(double)me);
174
 
     }
175
 
 
176
 
     for(i=0;i<nproc; i++){
177
 
       if(me==i && hi[0]>=0){
178
 
         char msg[100];
179
 
         sprintf(msg,"%d: leading dimensions",me);
180
 
         print_subscript(msg,ndim-1,ld,"\n");
181
 
         fflush(stdout);
182
 
       }
183
 
       GA_Sync();
184
 
     }
185
 
     
186
 
     GA_Sync();
187
 
     if(me==0)printf("\nRandomly checking the update using ga_get on array sections\n");
188
 
     GA_Sync();
189
 
 
190
 
     /* show ga_get working and verify array updates 
191
 
      * every process does N random gets
192
 
      * for simplicity get only a single row at a time
193
 
      */
194
 
     srand(me); /* different seed for every process */
195
 
     hi[ndim-1]=adims[ndim-1] -1 + BASE;
196
 
     for(i=1;i<ndim-1; i++)ld[i]=1; ld[ndim-2]=adims[ndim-1] -1 + BASE;
197
 
 
198
 
     /* get buffer memory */
199
 
     buf = (double*)malloc(adims[ndim-1]*sizeof(double));
200
 
     if(!buf)GA_Error("malloc failed for buf",1);
201
 
 
202
 
     /* half of the processes check the result */
203
 
     if(me<=nproc/2) 
204
 
     for(loop = 0; loop< N; loop++){ /* task parallel loop */
205
 
         lo[ndim-1]=BASE;
206
 
         for (i= 0; i < ndim -1; i ++){
207
 
              lo[i] = hi[i] = rand()%adims[i]+BASE; 
208
 
         }
209
 
 
210
 
         /* print_subscript("getting",ndim,lo,"\n");*/
211
 
         NGA_Get(g_a,lo,hi,buf,ld); 
212
 
         
213
 
         /* check values */
214
 
         for(i=0;i<adims[ndim-1]; i++){
215
 
             int p = NGA_Locate(g_a, lo);
216
 
             if((double)p != buf[i]) {
217
 
                char msg[100];
218
 
                sprintf(msg,"%d: wrong value: %d != %f a",me, p, buf[i]);
219
 
                print_subscript(msg,ndim,lo,"\n");
220
 
                GA_Error("Error - bye",i);  
221
 
             }
222
 
             lo[ndim-1]++;
223
 
          }
224
 
     }
225
 
             
226
 
     free(buf);
227
 
     GA_Sync();
228
 
           
229
 
     if(me==0)printf("OK\n");
230
 
     
231
 
     GA_Destroy(g_a);
232
 
     GA_Destroy(g_b);
233
 
}
234
 
     
235
 
 
236
 
int main(argc, argv)
237
 
int argc;
238
 
char **argv;
239
 
{
240
 
Integer heap=300000, stack=300000;
241
 
int me, nproc;
242
 
 
243
 
    MP_INIT(argc,argv);
244
 
 
245
 
    GA_INIT(argc,argv);                           /* initialize GA */
246
 
 
247
 
    nproc = GA_Nnodes();
248
 
    me = GA_Nodeid();
249
 
 
250
 
    if(me==0) printf("Using %d processes\n\n",nproc);
251
 
 
252
 
    if(!MA_init((Integer)MT_F_DBL, stack/nproc, heap/nproc))
253
 
       GA_Error("MA_init failed bytes= %d",stack+heap);   
254
 
 
255
 
#ifdef PERMUTE
256
 
      {
257
 
        int i, *list = (int*)malloc(nproc*sizeof(int));
258
 
        if(!list)GA_Error("malloc failed",nproc);
259
 
 
260
 
        for(i=0; i<nproc;i++)list[i]=nproc-1-i;
261
 
 
262
 
        GA_Register_proclist(list, nproc);
263
 
        free(list);
264
 
      }
265
 
#endif
266
 
 
267
 
    if(GA_Uses_fapi())GA_Error("Program runs with C API only",1);
268
 
    
269
 
    do_work();
270
 
 
271
 
    if(me==0)printf("\nAll tests successful\n\n");
272
 
    GA_Terminate();
273
 
 
274
 
    MP_FINALIZE();
275
 
 
276
 
    return 0;
277
 
}
278