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

« back to all changes in this revision

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