5
/***********************************************************************\
6
* Tracing and Timing functions for the GA routines: *
7
* trace_init - initialization *
8
* trace_stime - starts timing *
9
* trace_etime - ends timing *
10
* trace_genrec - generates a trace record for the calling routine *
11
* trace_end - ends tracing & writes report to a file 'proc' *
12
* Note: the usc timer from the ALOG package is used *
13
* Jarek Nieplocha, 10.14.93 *
14
\***********************************************************************/
34
static double tt0, tt1;
35
static Integer *tlog, thandle;
36
static Integer *indlog, ihandle, gahandle;
38
static unsigned long current, MAX_EVENTS=0;
43
#define min(a,b) ((a)<(b) ? (a) : (b))
45
#if HAVE_SYS_WEAK_ALIAS_PRAGMA
46
# pragma weak wnga_timer = pnga_timer
57
/* n is the max number of events to be traced */
58
void trace_init_(long *n)
64
printf("trace_init>> invalid max number of events: %ld\n",*n);
71
/* MA_initialize(MT_INT,10000,10000); */
75
if(!MA_push_get(MT_LONGINT, *n*2, "timeLog", &thandle, &index)){
76
printf("trace_init>> failed to allocate memory 1\n");
79
MA_get_pointer(thandle, &tlog);
81
printf("trace_init>> null pointer: 1\n");
85
if(!MA_push_get(MT_LONGINT, *n*6, "indexLog", &ihandle, &index)){
86
printf("trace_init>> failed to allocate memory 2\n");
89
MA_get_pointer(ihandle, &indlog);
91
printf("trace_init>> null pointer: 2\n");
95
if(!MA_push_get(MT_INT, MAX_GAS, "gaLog", &gahandle, &index)){
96
printf("trace_init>> failed to allocate memory 2\n");
99
MA_get_pointer(gahandle, &galog);
101
printf("trace_init>> null pointer: 2\n");
107
if(err) MAX_EVENTS = 0;
120
void trace_genrec_(Integer *ga, Integer *ilo, Integer *ihi, Integer *jlo, Integer *jhi,
123
int i, d, has_record, counter;
132
int ndim, dims[2], tmp_dims[2], lo[2], hi[2], type, block[2];
133
int me=GA_Nodeid(), nproc=GA_Nnodes(), proc;
135
if(current >= MAX_EVENTS) return;
137
/* only node 0 does the bookkeeping */
139
/* test if this ga has been recorded */
141
for(i=0; i<ganum; i++)
142
if(*ga == (long) galog[i]) has_record = 1;
145
galog[ganum++] = (int)*ga;
147
sprintf(fname, "distrib.%d",(int) *ga);
148
fout = fopen(fname,"w");
150
NGA_Inquire((int)*ga, &type, &ndim, dims);
152
/* get memory for arrays describing distribution */
153
proclist = (int*)malloc(nproc*sizeof(int));
154
if(!proclist)GA_Error("malloc failed for proclist",0);
155
regions = (patch_t*)malloc(nproc*sizeof(patch_t));
156
if(!regions)GA_Error("malloc failed for regions",0);
158
for(d=0; d<ndim; d++) { lo[d] = 0; hi[d] = dims[d] -1;}
160
proc = NGA_Locate_region((int)*ga, lo, hi, (int*)regions, proclist);
161
if(proc<1) GA_Error("error in NGA_Locate_region",proc);
163
for(d=0; d<ndim; d++) {
164
tmp_dims[d] = 0; block[d] = 0;
165
for(i=0; i<nproc; i++)
166
if(regions[i].hi[d] > tmp_dims[d]) {
168
tmp_dims[d] = regions[i].hi[d];
172
/* print the number of processed */
173
fprintf(fout, "%d\n", nproc);
174
/* print dimensions */
175
for(d=0; d<ndim; d++) fprintf(fout, "%d ", dims[d]);
178
/* print number of lines to draw for each dimension */
179
for(d=0; d<ndim; d++)
180
if(block[d] == 1) fprintf(fout, "%d ", block[d]);
181
else fprintf(fout, "%d ", block[d]-1);
184
/* print the offset for each line */
185
for(d=0; d<ndim; d++) {
186
if(block[d] == 1) fprintf(fout, "%d\n", dims[d]);
190
for(i=0; i<nproc; i++)
191
if(regions[i].hi[d] > tmp_dims[d]) {
193
if(counter == block[d]) break;
194
fprintf(fout, "%d\n",
196
tmp_dims[d] = regions[i].hi[d];
201
free(regions); free(proclist);
205
tlog[current*2] = (unsigned long)(tt0 * 1000000);
206
tlog[current*2+1] = (unsigned long)(tt1 * 1000000);
207
indlog[current*6] = *ga;
208
indlog[current*6+1] = *ilo;
209
indlog[current*6+2] = *ihi;
210
indlog[current*6+3] = *jlo;
211
indlog[current*6+4] = *jhi;
212
indlog[current*6+5] = *op;
216
void trace_end_(long *proc)
222
sprintf(fname,"%03d",(int)*proc);
223
fout=fopen(fname,"w");
225
for(i=0;i<min(current,MAX_EVENTS);i++){
226
fprintf(fout,"%d ",(int)*proc);
227
for(k=i*6;k<6*(i+1);k++)fprintf(fout,"%d ",(int)indlog[k]);
228
fprintf(fout,"%ld %ld\n",(unsigned long)tlog[i*2],
229
(unsigned long)tlog[i*2+1]);
232
MA_pop_stack(gahandle);
233
MA_pop_stack(ihandle);
234
MA_pop_stack(thandle);