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

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/armci/examples/benchmarks/RandomAccess/smp_bucket/smp_bucket.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
 
#include <mpi.h>
6
 
 
7
 
#if HAVE_STDIO_H
8
 
#   include <stdio.h>
9
 
#endif
10
 
#if HAVE_MATH_H
11
 
#   include <math.h>
12
 
#endif
13
 
#if HAVE_STDLIB_H
14
 
#   include <stdlib.h>
15
 
#endif
16
 
#if HAVE_SYS_TYPES_H
17
 
#   include <sys/types.h>
18
 
#endif
19
 
#if HAVE_SYS_STAT_H
20
 
#   include <sys/stat.h>
21
 
#endif
22
 
#if HAVE_FCNTL_H
23
 
#   include <fcntl.h>
24
 
#endif
25
 
 
26
 
#include "armci.h"
27
 
#include "message.h"
28
 
#include "../ra_common.h"
29
 
 
30
 
#define DEBUG 0
31
 
 
32
 
static int me, nproc,nsmp;
33
 
static u64Int procnumupdates,myglobalstart,globaltablelen,mytablelen,mintablesize,*procglobalstart; 
34
 
static int bigtables,Remainder;
35
 
static int *armcismpid;
36
 
static int my_free_handle;
37
 
FILE *fd;
38
 
u64Int **HPCC_Table;
39
 
 
40
 
struct vector_dscr_t{
41
 
  int active;
42
 
  int dstproc;
43
 
  int dstsmp;
44
 
  u64Int **xmitbuffer;
45
 
  struct vector_dscr_t *next;
46
 
  armci_giov_t a_v;
47
 
};
48
 
struct vector_dscr_t *vec_dscr;
49
 
static struct vector_dscr_t curdscr_val;
50
 
struct vector_dscr_t *curdscr_ptr = &curdscr_val;
51
 
 
52
 
static armci_hdl_t* _get_next_handle()
53
 
{
54
 
    my_free_handle++;
55
 
    my_free_handle %= MAX_OUTSTANDING_HANDLES;
56
 
}
57
 
/* from hpcc RandomAccess/utility.c */
58
 
static u64Int HPCC_starts(s64Int n)
59
 
{
60
 
int i,j;
61
 
u64Int temp,ran,m2[64];
62
 
 
63
 
    while (n < 0) n += PERIOD;
64
 
    while (n > PERIOD) n -= PERIOD;
65
 
    if (n == 0) return 0x1;
66
 
 
67
 
    temp = 0x1;
68
 
    for (i=0; i<64; i++) {
69
 
      m2[i] = temp;
70
 
      temp = (temp << 1) ^ ((s64Int) temp < 0 ? POLY : 0);
71
 
      temp = (temp << 1) ^ ((s64Int) temp < 0 ? POLY : 0);
72
 
    }
73
 
 
74
 
    for (i=62; i>=0; i--)
75
 
      if ((n >> i) & 1)
76
 
        break;
77
 
 
78
 
    ran = 0x2;
79
 
    while (i > 0) {
80
 
      temp = 0;
81
 
      for (j=0; j<64; j++)
82
 
        if ((ran >> j) & 1)
83
 
          temp ^= m2[j];
84
 
      ran = temp;
85
 
      i -= 1;
86
 
      if ((n >> i) & 1)
87
 
      ran = (ran << 1) ^ ((s64Int) ran < 0 ? POLY : 0);
88
 
    }
89
 
    return ran;
90
 
 
91
 
}
92
 
 
93
 
static void xmitsmpvector(){
94
 
struct vector_dscr_t *tmp=curdscr_val.next, *tmp1;
95
 
int mysmpid = armcismpid[me];
96
 
u64Int myscale=0;
97
 
    curdscr_ptr = &curdscr_val;
98
 
#if DEBUG
99
 
    printf("\n%d:in xmitsmpvector dstproc=%d dstsmp=%d mysmp=%d\n",me,tmp->dstproc,tmp->dstsmp,mysmpid);fflush(stdout);
100
 
#endif
101
 
    while(tmp!=NULL){
102
 
      if(tmp->dstsmp!=mysmpid)
103
 
        ARMCI_NbAccV(ARMCI_ACC_RA,&myscale,&tmp->a_v,1,tmp->dstproc,NULL);
104
 
      tmp=tmp->next;
105
 
    }
106
 
    tmp=curdscr_val.next;
107
 
#if DEBUG
108
 
    printf("\n%d:in xmitsmpvector1 dstproc=%d\n",me,tmp->dstproc);fflush(stdout);
109
 
#endif
110
 
    while(tmp!=NULL){
111
 
      if(tmp->dstsmp==mysmpid)
112
 
        ARMCI_AccV(ARMCI_ACC_RA,&myscale,&tmp->a_v,1,tmp->dstproc);
113
 
      tmp=tmp->next;
114
 
    }
115
 
    tmp=curdscr_val.next;
116
 
#if DEBUG
117
 
    printf("\n%d:in xmitsmpvector2 dstproc=%d\n",me,tmp->dstproc);fflush(stdout);
118
 
#endif
119
 
    while(tmp!=NULL){
120
 
      tmp->active=0;
121
 
      tmp->a_v.ptr_array_len=0;
122
 
      tmp1=tmp->next;
123
 
      tmp->next=NULL;
124
 
      tmp = tmp1;
125
 
    }
126
 
#if DEBUG
127
 
    printf("\n%d:in xmitsmpvector done\n",me);fflush(stdout);
128
 
#endif
129
 
     
130
 
}
131
 
 
132
 
static void addtosmpvector(u64Int ran){
133
 
u64Int offset;
134
 
int proc,smpid;
135
 
struct vector_dscr_t *tmp;
136
 
    offset = ran & (globaltablelen-1);
137
 
    if(offset < bigtables)
138
 
      proc=offset/(mintablesize+1);
139
 
    else
140
 
      proc=(offset-Remainder)/mintablesize;
141
 
    /*if(vec_dscr[]);*/
142
 
    smpid = armcismpid[proc];
143
 
#if DEBUG
144
 
    printf("\n%d:adding ran=%d offset=%d proc=%d smpid=%d\n",me,ran,offset,proc,smpid);fflush(stdout);
145
 
#endif
146
 
    tmp =&vec_dscr[smpid]; 
147
 
    if(!tmp->active){
148
 
      tmp->active = 1;
149
 
      tmp->next = NULL;
150
 
      curdscr_ptr->next = tmp;
151
 
      curdscr_ptr = tmp;
152
 
    }
153
 
    *(u64Int *)tmp->a_v.src_ptr_array[tmp->a_v.ptr_array_len]=ran;
154
 
    tmp->a_v.dst_ptr_array[tmp->a_v.ptr_array_len]=(void *)(HPCC_Table[proc]+(offset-procglobalstart[proc]));
155
 
    tmp->a_v.ptr_array_len+=1;
156
 
#if DEBUG
157
 
    printf("\n%d:added ran=%d smpid=%d ptrarrlen=%d\n",me,ran,smpid,tmp->a_v.ptr_array_len);fflush(stdout);
158
 
#endif
159
 
}
160
 
 
161
 
void HPCCRandom_Access()
162
 
{
163
 
int i;
164
 
u64Int ran;
165
 
    ran = HPCC_starts (4 * myglobalstart);
166
 
    for(i=0;i<procnumupdates;i++){
167
 
      ran = (ran << 1) ^ ((s64Int)ran < ZERO64B ? POLY : ZERO64B);
168
 
      addtosmpvector(ran);
169
 
      if(i && i%MAX_TOTAL_PENDING_UPDATES==0)xmitsmpvector();
170
 
    }
171
 
    if(i%MAX_TOTAL_PENDING_UPDATES)xmitsmpvector();
172
 
}
173
 
 
174
 
static void initialize_tables()
175
 
{
176
 
int rc,i,j;
177
 
armci_domain_t d;
178
 
    curdscr_val.next=NULL;
179
 
    curdscr_ptr = &curdscr_val;
180
 
    nsmp = armci_domain_count(d);
181
 
    armcismpid = (int *)malloc(sizeof(int)*nproc);
182
 
    procglobalstart = (u64Int *)calloc(nproc,sizeof(u64Int)); 
183
 
    procglobalstart[me]=myglobalstart;
184
 
#if   SIZEOF_LONG == 8
185
 
    armci_msg_lgop(procglobalstart,nproc,"+");
186
 
#elif SIZEOF_LONG_LONG == 8
187
 
    armci_msg_llgop(procglobalstart,nproc,"+");
188
 
#else
189
 
#   error could not determine 64bit integer type
190
 
#endif
191
 
    for(i=0;i<nproc;i++)
192
 
      armcismpid[i] = armci_clus_id(i);
193
 
    HPCC_Table = (u64Int **)malloc(sizeof(u64Int *)*nproc);    
194
 
    if(HPCC_Table == NULL)
195
 
      ARMCI_Error("initialize_tables:Table pointer malloc failed",(mytablelen*sizeof(u64Int)));
196
 
    if(rc=ARMCI_Malloc((void **)HPCC_Table,mytablelen*sizeof(u64Int)))
197
 
      ARMCI_Error("initialize_tables:Global Table malloc failed",(mytablelen*sizeof(u64Int)));
198
 
    for(i=0;i<mytablelen;i++){
199
 
      HPCC_Table[me][i] = i + myglobalstart;
200
 
    }
201
 
    vec_dscr = (struct vector_dscr_t *)malloc(sizeof(struct vector_dscr_t)*nsmp);
202
 
    if(vec_dscr == NULL)
203
 
      ARMCI_Error("initialize_tables:vec_dscr malloc fail",sizeof(struct vector_dscr_t)*nsmp);
204
 
    for(i=0;i<nsmp;i++){
205
 
      vec_dscr[i].next=NULL;
206
 
      vec_dscr[i].active=0;
207
 
      vec_dscr[i].xmitbuffer = (u64Int **)malloc(sizeof(u64Int *)*nproc);
208
 
      if(vec_dscr[i].xmitbuffer == NULL)
209
 
         ARMCI_Error("initialize_tables:xmitbuffer malloc failed",sizeof(u64Int *)*nproc);
210
 
      if(rc=ARMCI_Malloc((void **)vec_dscr[i].xmitbuffer,MAX_TOTAL_PENDING_UPDATES*sizeof(u64Int))) 
211
 
        ARMCI_Error("initialize_tables:xmitbuffer armci_malloc failed",sizeof(u64Int)*MAX_TOTAL_PENDING_UPDATES);
212
 
      vec_dscr[i].dstproc = armci_smp_master(i);
213
 
      vec_dscr[i].dstsmp = i;
214
 
      vec_dscr[i].a_v.src_ptr_array=(void **)malloc(sizeof(void *)*MAX_TOTAL_PENDING_UPDATES);
215
 
      for(j=0;j<MAX_TOTAL_PENDING_UPDATES;j++)
216
 
        vec_dscr[i].a_v.src_ptr_array[j]=(void *)(vec_dscr[i].xmitbuffer[me]+j);
217
 
      
218
 
      vec_dscr[i].a_v.dst_ptr_array=(void **)malloc(sizeof(void *)*MAX_TOTAL_PENDING_UPDATES);
219
 
      if(vec_dscr[i].a_v.src_ptr_array==NULL || vec_dscr[i].a_v.dst_ptr_array==NULL)
220
 
        ARMCI_Error("initialize_tables:.src_ptr_array malloc fail",sizeof(void *)*MAX_TOTAL_PENDING_UPDATES);
221
 
      vec_dscr[i].a_v.ptr_array_len = 0;
222
 
      vec_dscr[i].a_v.bytes = 8;
223
 
    }
224
 
 
225
 
}
226
 
 
227
 
static void finalize_tables()
228
 
{
229
 
    ARMCI_Free(HPCC_Table[me]);
230
 
    free(HPCC_Table);
231
 
}     
232
 
 
233
 
int main(argc, argv)
234
 
int argc;
235
 
char **argv;
236
 
{
237
 
s64Int i;
238
 
int log2nproc;
239
 
double CPUTime;        /* CPU  time to update table */
240
 
double RealTime;       /* Real time to update table */
241
 
 
242
 
double TotalMem;
243
 
int PowerofTwo;
244
 
 
245
 
u64Int NumUpdates;     /* actual number of updates to table */
246
 
s64Int ProcNumUpdates; /* number of updates per processor */
247
 
 
248
 
FILE *outFile = NULL;
249
 
double *GUPs;
250
 
double max_time,min_time,avg_time,time_start,time_stop,total_time;
251
 
 
252
 
    armci_msg_init(&argc,&argv);
253
 
    nproc = armci_msg_nproc();
254
 
    me = armci_msg_me();
255
 
    ARMCI_Init();      /* initialize ARMCI */
256
 
 
257
 
    if(me==0)printf("\n                          RANDOM ACCESS EXAMPLE\n");
258
 
    if(argc<2){
259
 
       if(me==0){
260
 
         printf(" CORRECT USAGE IS:");
261
 
         printf("\n\n <launch commands> simple.x inpfile\n");
262
 
         fflush(stdout);
263
 
       }
264
 
       ARMCI_Finalize();
265
 
       armci_msg_finalize();
266
 
       return 0;
267
 
    }
268
 
    globaltablelen = atoi(argv[1]);
269
 
 
270
 
    mintablesize = globaltablelen/nproc;
271
 
    Remainder = globaltablelen - mintablesize*nproc;
272
 
    bigtables = (mintablesize+1)*Remainder;
273
 
    if(me<Remainder){
274
 
      mytablelen = mintablesize+1;
275
 
      myglobalstart = mytablelen*me; 
276
 
    }
277
 
    else{
278
 
      mytablelen = mintablesize;
279
 
      myglobalstart = mytablelen*me+Remainder; 
280
 
    }
281
 
    procnumupdates = 4*mytablelen;
282
 
#if DEBUG
283
 
    printf("\n%d:%d is totaltable, mintablesize=%d rem=%d big=%d glosta=%d tablelen=%d numup=%d\n",me, globaltablelen, mintablesize,Remainder,bigtables,myglobalstart,mytablelen,procnumupdates);
284
 
#endif
285
 
    armci_msg_barrier();
286
 
 
287
 
    initialize_tables();
288
 
 
289
 
    if(me==0)printf("\n\nStarting Random Access....");
290
 
    armci_msg_barrier();
291
 
 
292
 
    time_start=armci_timer();
293
 
    HPCCRandom_Access();
294
 
    time_stop=armci_timer();
295
 
    armci_msg_barrier();
296
 
    total_time=(time_stop-time_start);
297
 
    max_time=total_time;
298
 
    min_time=total_time;
299
 
    avg_time=total_time;
300
 
    armci_msg_dgop(&max_time,1,"max");
301
 
    armci_msg_dgop(&min_time,1,"min");
302
 
    armci_msg_dgop(&avg_time,1,"+");
303
 
    avg_time/=nproc;
304
 
    if(me==0)printf("\nGUPs = %.9f %.9f %.9f Billion(10^9) Updates/PE  per second [GUP/s]\n",1e-9*procnumupdates/max_time,1e-9*procnumupdates/min_time,1e-9*procnumupdates/avg_time);
305
 
    finalize_tables();
306
 
 
307
 
    if(me==0)printf("Terminating ..\n");
308
 
    ARMCI_Finalize();
309
 
    armci_msg_finalize();
310
 
    return 0;
311
 
}