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

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/global/src/ga_profile.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
/* $Id: ga_profile.c,v 1.5 2005-07-21 08:13:26 manoj Exp $ */
 
6
/**
 
7
 * Note #1: Right now, only process 0's profile is printed.
 
8
 * Each and every process saves its profile in the correspoding data struture.
 
9
 * However profiler prints process 0's profile when ga_profile_terminate()
 
10
 * is called. Do the corresponding changes in ga_profile_terminate() to
 
11
 * print the profile of other processes.
 
12
 *
 
13
 * Note #2: By default profiles prints message ranges #s 21. Example: range 10
 
14
 * corresponds to message ranges from 1024 bytes to 2047 bytes.
 
15
 * Message ranges are in the power of 2. for ex:
 
16
 * ------------------------------------
 
17
 *  MSG_RANGE (r)        BYTES (2^r to 2^(r+1)-1)
 
18
 * ------------------------------------
 
19
 *      0                    0-1
 
20
 *      1                    2-3
 
21
 *      2                    4-7
 
22
 *     ...                   ...
 
23
 *      10                1024-2047 bytes
 
24
 *     ...                   ...
 
25
 *      20                1MB - (2MB-1)
 
26
 *      21                  >= 2MB
 
27
 * -------------------------------------
 
28
 *
 
29
 * Note#3: If Stride information needs to be printed, set GA_PRINT_STRIDE.
 
30
 * Stride information is printed in ga_profile_terminate() for a various
 
31
 * selective message ranges and event types. Modify according to your needs.
 
32
 */
 
33
 
 
34
 
 
35
#ifdef ENABLE_PROFILE
 
36
 
 
37
#if HAVE_STDIO_H
 
38
#   include <stdio.h>
 
39
#endif
 
40
#if HAVE_STDLIB_H
 
41
#   include <stdlib.h>
 
42
#endif
 
43
#if HAVE_STRING_H
 
44
#   include <string.h>
 
45
#endif
 
46
#if HAVE_MATH_H
 
47
#   include <math.h>
 
48
#endif
 
49
#include "globalp.h"
 
50
#include "base.h" 
 
51
#include "ga_profile.h" 
 
52
#include "ga-papi.h"
 
53
#include "ga-wapi.h"
 
54
 
 
55
#ifndef MPI
 
56
#  include "tcgmsg.h"
 
57
#   define MP_TIMER tcg_time
 
58
#else
 
59
#  include "mpi.h"
 
60
#   define MP_TIMER MPI_Wtime
 
61
#endif
 
62
 
 
63
 
 
64
#define GA_PRINT_STRIDE 1
 
65
#define GA_MAX_MSG_RANGE 21
 
66
 
 
67
#if GA_PRINT_STRIDE
 
68
#define STRIDE_COUNT 1000
 
69
  typedef struct ga_stride {
 
70
    int ndim;
 
71
    int lo[GA_MAX_DIM];
 
72
    int hi[GA_MAX_DIM];
 
73
    char name[FNAM+1];
 
74
    double time;
 
75
  }ga_stride_t;
 
76
#endif
 
77
 
 
78
#define GA_EVENTS 6 /*  get, put, acc, Non-Contiguous get, put, acc*/
 
79
enum events {GET,    /* Contiguous get */
 
80
             PUT, 
 
81
             ACC, 
 
82
             NC_GET, /* Non contiguous Get */
 
83
             NC_PUT,
 
84
             NC_ACC
 
85
};
 
86
 
 
87
char *event_name[GA_EVENTS] = {"GET", "PUT", "ACC", "NON CONTIGUOUS GET",
 
88
                               "NON CONTIGUOUS PUT", "NON CONTIGUOUS ACC"};
 
89
 
 
90
typedef struct ga_profile {
 
91
  int count;          /* number of times called */
 
92
  double exectime;  /* total execution time for "count" calls */
 
93
#if GA_PRINT_STRIDE
 
94
  ga_stride_t stride[STRIDE_COUNT];
 
95
#endif
 
96
}ga_profile_t;
 
97
 
 
98
/* profile get/put/acc for various message ranges (i.e GA_MAX_MSG_RANGE) */
 
99
static ga_profile_t GA_PROF[GA_EVENTS][GA_MAX_MSG_RANGE]; 
 
100
 
 
101
/* Current event */
 
102
struct event_info {
 
103
  int event_type;
 
104
  int range;
 
105
  int is_set;
 
106
  double start_time;
 
107
} gCURRENT_EVNT; 
 
108
 
 
109
void ga_profile_init() {
 
110
    int i,j;
 
111
    if(pnga_nodeid()==0) {printf("\nProfiling GA - ON\n");fflush(stdout);}
 
112
    for(i=0; i<GA_EVENTS; i++)
 
113
       for(j=0; j<GA_MAX_MSG_RANGE; j++) {
 
114
          GA_PROF[i][j].count = 0;  GA_PROF[i][j].exectime = 0.0; 
 
115
       }
 
116
}
 
117
 
 
118
static void ga_profile_set_event(int event_type, int range) {
 
119
    gCURRENT_EVNT.event_type = event_type;
 
120
    gCURRENT_EVNT.range      = range;
 
121
    gCURRENT_EVNT.is_set     = 1;
 
122
    gCURRENT_EVNT.start_time = MP_TIMER();
 
123
}
 
124
 
 
125
void ga_profile_start(int g_a, long bytes, int ndim, Integer *lo, Integer *hi,
 
126
                      int comm_type) {
 
127
    int i, count=0, non_contig=0, event_type, range;
 
128
 
 
129
    /* find the message range */
 
130
    if(bytes<=0) range=0;
 
131
    else range = (int) (log((double)bytes)/log(2.0));
 
132
    if(range>=GA_MAX_MSG_RANGE) range = GA_MAX_MSG_RANGE;
 
133
 
 
134
    /* check contiguous or non-contiguous */
 
135
    for(i=0; i<ndim; i++) if(hi[0]-lo[0]) count++;
 
136
    if(count>1) non_contig=1; /* i.e. non-contiguous */
 
137
 
 
138
    switch(comm_type) {
 
139
       case ENABLE_PROFILE_PUT:
 
140
          if(non_contig) event_type = NC_PUT;
 
141
          else event_type = PUT;
 
142
          break;
 
143
       case ENABLE_PROFILE_GET: 
 
144
          if(non_contig) event_type = NC_GET;
 
145
          else event_type = GET;
 
146
          break;
 
147
       case ENABLE_PROFILE_ACC: 
 
148
          if(non_contig) event_type = NC_ACC;
 
149
          else event_type = ACC;
 
150
          break;
 
151
       default: pnga_error("ENABLE_PROFILE: Invalid communication type", 0L);
 
152
    }
 
153
 
 
154
    /* set the curent event for timer */
 
155
    ga_profile_set_event(event_type, range);
 
156
    
 
157
    /* profile update: i.e. update event count */
 
158
    GA_PROF[event_type][range].count++;
 
159
 
 
160
#if GA_PRINT_STRIDE 
 
161
    {
 
162
       int idx = GA_PROF[event_type][range].count-1;
 
163
       if(idx<STRIDE_COUNT) {
 
164
          GA_PROF[event_type][range].stride[idx].ndim = ndim;
 
165
          strcpy(GA_PROF[event_type][range].stride[idx].name, GA[g_a].name);
 
166
          for(i=0;i<ndim;i++) {
 
167
             GA_PROF[event_type][range].stride[idx].lo[i] = (int)lo[i];
 
168
             GA_PROF[event_type][range].stride[idx].hi[i] = (int)hi[i];
 
169
          }
 
170
       }
 
171
    }
 
172
#endif
 
173
}
 
174
 
 
175
void ga_profile_stop() {
 
176
    int event_type = gCURRENT_EVNT.event_type;
 
177
    int idx, range = gCURRENT_EVNT.range;
 
178
    double time = MP_TIMER() - gCURRENT_EVNT.start_time;
 
179
 
 
180
    if(gCURRENT_EVNT.is_set) { /* Yep, there is an event set */
 
181
       GA_PROF[event_type][range].exectime += time;
 
182
       gCURRENT_EVNT.is_set = 0; /* clear the event */
 
183
    }
 
184
    else
 
185
       pnga_error("ENABLE_PROFILE: No event set. Probably ga_profile_stop() is called before ga_profile_start()", 0L);
 
186
 
 
187
#if GA_PRINT_STRIDE
 
188
    {  /* measure the time of each strided data transfer */
 
189
       idx = GA_PROF[event_type][range].count-1;
 
190
       if(idx<STRIDE_COUNT)  GA_PROF[event_type][range].stride[idx].time = time;
 
191
    }
 
192
#endif
 
193
}
 
194
 
 
195
#define GA_HDR1() printf("\n\n************ CONTIGUOUS DATA TRANSFER ************\n\n");
 
196
#define GA_HDR2() printf("\n\n********** NON-CONTIGUOUS DATA TRANSFER **********\n\n"); 
 
197
#define GA_HDR3() printf("RANK\t #Gets\t #puts\t #accs\t RANGE\n\n");
 
198
#define GA_HDR4() printf("RANK\t get_time\t put_time\t acc_time\t RANGE\n\n");
 
199
#define GA_HDR5() printf("SL#\tndim  time      stride_info (array name)\n\n");
 
200
 
 
201
/* This prints the number of contiguous get/put/acc/ calls for every 
 
202
   message range */
 
203
void ga_print_numcalls1() {
 
204
    int i; 
 
205
    GA_HDR1(); GA_HDR3();
 
206
    for(i=0; i< GA_MAX_MSG_RANGE-1; i++)
 
207
       printf("%d\t %d\t %d\t %d\t (%d-%d)\n", pnga_nodeid(),
 
208
              GA_PROF[GET][i].count, GA_PROF[PUT][i].count,
 
209
              GA_PROF[ACC][i].count, 1<<i, 1<<(i+1));
 
210
    printf("%d\t %d\t %d\t %d\t (>%d)\n", pnga_nodeid(),
 
211
           GA_PROF[GET][i].count, GA_PROF[PUT][i].count,
 
212
           GA_PROF[ACC][i].count, 1<<GA_MAX_MSG_RANGE);
 
213
}
 
214
 
 
215
/* This prints the number of non-contiguous get/put/acc/ calls for every 
 
216
   message range */
 
217
void ga_print_numcalls2() {
 
218
    int i; 
 
219
    GA_HDR2(); GA_HDR3();
 
220
    for(i=0; i< GA_MAX_MSG_RANGE-1; i++)
 
221
       printf("%d\t %d\t %d\t %d\t (%d-%d)\n", pnga_nodeid(),
 
222
              GA_PROF[NC_GET][i].count, GA_PROF[NC_PUT][i].count,
 
223
              GA_PROF[NC_ACC][i].count, 1<<i, 1<<(i+1));
 
224
    printf("%d\t %d\t %d\t %d\t (>%d)\n",pnga_nodeid(),
 
225
           GA_PROF[NC_GET][i].count, GA_PROF[NC_PUT][i].count,
 
226
           GA_PROF[NC_ACC][i].count, 1<<GA_MAX_MSG_RANGE);
 
227
}
 
228
 
 
229
/* This prints timings of all contiguous get/put/acc/ calls for every 
 
230
   message range */
 
231
void ga_print_timings1() {
 
232
    int i; 
 
233
    GA_HDR1(); GA_HDR4();
 
234
    for(i=0; i< GA_MAX_MSG_RANGE-1; i++)
 
235
       printf("%d\t %.2e\t %.2e\t %.2e\t (%d-%d)\n", pnga_nodeid(), 
 
236
              GA_PROF[GET][i].exectime, GA_PROF[PUT][i].exectime, 
 
237
              GA_PROF[ACC][i].exectime, 1<<i, 1<<(i+1));
 
238
    printf("%d\t %.2e\t %.2e\t %.2e\t (>%d)\n", pnga_nodeid(), 
 
239
           GA_PROF[GET][i].exectime, GA_PROF[PUT][i].exectime, 
 
240
           GA_PROF[ACC][i].exectime, 1<<GA_MAX_MSG_RANGE);    
 
241
}
 
242
 
 
243
/* This prints timings of all non-contiguous get/put/acc/ calls for every 
 
244
   message range */
 
245
void ga_print_timings2() {
 
246
    int i; 
 
247
    GA_HDR2(); GA_HDR4();
 
248
    for(i=0; i< GA_MAX_MSG_RANGE-1; i++)
 
249
       printf("%d\t %.2e\t %.2e\t %.2e\t (%d-%d)\n", pnga_nodeid(), 
 
250
              GA_PROF[NC_GET][i].exectime, GA_PROF[NC_PUT][i].exectime, 
 
251
              GA_PROF[NC_ACC][i].exectime, 1<<i, 1<<(i+1));
 
252
    printf("%d\t %.2e\t %.2e\t %.2e\t (>%d)\n", pnga_nodeid(), 
 
253
           GA_PROF[NC_GET][i].exectime, GA_PROF[NC_PUT][i].exectime, 
 
254
           GA_PROF[NC_ACC][i].exectime, 1<<GA_MAX_MSG_RANGE);    
 
255
}
 
256
 
 
257
void ga_print_stridedinfo(int event, int range) {
 
258
    int i, j, ndim;
 
259
    double time=0.0;
 
260
    printf("\n\nSTRIDE INFORMATION FOR MSG_RANGE %d-%d for EVENT: %s\n", 
 
261
           1<<range, 1<<(range+1), event_name[event]);
 
262
    GA_HDR5();
 
263
    for(i=0; i< GA_PROF[event][range].count; i++) {
 
264
       if(i>=STRIDE_COUNT) break;
 
265
       time += GA_PROF[event][range].stride[i].time;
 
266
       ndim  = GA_PROF[event][range].stride[i].ndim;
 
267
       printf("%d\t%d     %.2e  (",i, ndim,
 
268
              GA_PROF[event][range].stride[i].time);
 
269
       for(j=0;j<ndim;j++) {
 
270
          printf("%d", GA_PROF[event][range].stride[i].hi[j] -
 
271
                       GA_PROF[event][range].stride[i].lo[j] +1);
 
272
          if(j!=ndim-1) printf("x");
 
273
       }
 
274
       printf(") ==> ");
 
275
       for(j=0;j<ndim;j++)
 
276
          printf("[%d-%d]", GA_PROF[event][range].stride[i].lo[j],
 
277
                            GA_PROF[event][range].stride[i].hi[j]);
 
278
       printf(" \"%s\"\n",  GA_PROF[event][range].stride[i].name);
 
279
    }
 
280
    /*This o/p is just for verification*/
 
281
    printf("**** STRIDE_COUNT = %d ; TOTAL TIME = %.2e\n",GA_PROF[event][range].count,
 
282
           time);
 
283
}
 
284
 
 
285
void ga_profile_terminate() {
 
286
    int i; 
 
287
    if(pnga_nodeid() == 0) { /* process 0's profile only */
 
288
 
 
289
       /* contiguous calls */
 
290
       ga_print_numcalls1();
 
291
       ga_print_timings1();
 
292
 
 
293
       /* non-contiguous calls */
 
294
       ga_print_numcalls2();
 
295
       ga_print_timings2();
 
296
       
 
297
#if GA_PRINT_STRIDE
 
298
       {
 
299
          int msg_range, event_type;
 
300
          /**
 
301
           * printing stride info for non-contiguous get (NC_GET) for message 
 
302
           * range #6.  2^6 - 2^(6+1) bytes. (i.e. 64-128 bytes)
 
303
           */
 
304
          msg_range = 6; /* message range 2^6-2^(6+1) */
 
305
          event_type = NC_GET;
 
306
          ga_print_stridedinfo(NC_GET, msg_range);
 
307
          /*ga_print_stridedinfo(GET,19);*/ /* 2^19-2^20 range (524288-1MB)*/
 
308
       }
 
309
#endif
 
310
    }
 
311
}
 
312
 
 
313
#endif /* end of ENABLE_PROFILE */
 
314