NCEPLIBS-w3emc 2.12.0
Loading...
Searching...
No Matches
summary.c
Go to the documentation of this file.
1
23#include <stdio.h>
24#include <stdlib.h>
25#include <math.h>
26#include <string.h>
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <sys/time.h>
30#include <sys/times.h>
31#include <sys/utsname.h>
32#ifdef _AIX
33#include <sys/proc.h>
34#endif
35#ifdef __linux__
36#include <errno.h>
37#include <sys/resource.h>
38#endif
39
40static FILE *fp = NULL;
41int numtask, mypid;
42int procid_0;
43int profile, msglen;
44int trace_flag;
45double tcpu, twall, tbytes, f_bytes;
46double tot_wall, final_wall, start_wall;
47double cpu_comm, wall_comm;
48#ifdef _AIX
49extern double rtc ();
50#endif
51struct time_data {
52 double s_cpu;
53 double s_wall;
54 double f_cpu;
55 double f_wall;
56 double c_cpu;
57 double c_wall;
58 double c_bytes;
59 int c_calls;
60 int c_buckets[32];
61 float c_sum[32];
62 double b_cpu[32];
63 double b_wall[32];
64};
65
66struct time_data MPI_Allgather_data;
67struct time_data MPI_Allgatherv_data;
68struct time_data MPI_Allreduce_data;
69struct time_data MPI_Alltoall_data;
70struct time_data MPI_Alltoallv_data;
71struct time_data MPI_Barrier_data;
72struct time_data MPI_Bcast_data;
73struct time_data MPI_Gather_data;
74struct time_data MPI_Gatherv_data;
75struct time_data MPI_Op_create_data;
76struct time_data MPI_Op_free_data;
77struct time_data MPI_Reduce_scatter_data;
78struct time_data MPI_Reduce_data;
79struct time_data MPI_Scan_data;
80struct time_data MPI_Scatter_data;
81struct time_data MPI_Scatterv_data;
82struct time_data MPI_Attr_delete_data;
83struct time_data MPI_Attr_get_data;
84struct time_data MPI_Attr_put_data;
85struct time_data MPI_Comm_compare_data;
86struct time_data MPI_Comm_create_data;
87struct time_data MPI_Comm_dup_data;
88struct time_data MPI_Comm_free_data;
89struct time_data MPI_Comm_group_data;
90struct time_data MPI_Comm_rank_data;
91struct time_data MPI_Comm_remote_group_data;
92struct time_data MPI_Comm_remote_size_data;
93struct time_data MPI_Comm_size_data;
94struct time_data MPI_Comm_split_data;
95struct time_data MPI_Comm_test_inter_data;
96struct time_data MPI_Group_compare_data;
97struct time_data MPI_Group_difference_data;
98struct time_data MPI_Group_excl_data;
99struct time_data MPI_Group_free_data;
100struct time_data MPI_Group_incl_data;
101struct time_data MPI_Group_intersection_data;
102struct time_data MPI_Group_rank_data;
103struct time_data MPI_Group_range_excl_data;
104struct time_data MPI_Group_range_incl_data;
105struct time_data MPI_Group_size_data;
106struct time_data MPI_Group_translate_ranks_data;
107struct time_data MPI_Group_union_data;
108struct time_data MPI_Intercomm_create_data;
109struct time_data MPI_Intercomm_merge_data;
110struct time_data MPI_Keyval_create_data;
111struct time_data MPI_Keyval_free_data;
112struct time_data MPI_Abort_data;
113struct time_data MPI_Error_class_data;
114struct time_data MPI_Errhandler_create_data;
115struct time_data MPI_Errhandler_free_data;
116struct time_data MPI_Errhandler_get_data;
117struct time_data MPI_Error_string_data;
118struct time_data MPI_Errhandler_set_data;
119struct time_data MPI_Get_processor_name_data;
120struct time_data MPI_Initialized_data;
121struct time_data MPI_Wtick_data;
122struct time_data MPI_Wtime_data;
123struct time_data MPI_Address_data;
124struct time_data MPI_Bsend_data;
125struct time_data MPI_Bsend_init_data;
126struct time_data MPI_Buffer_attach_data;
127struct time_data MPI_Buffer_detach_data;
128struct time_data MPI_Cancel_data;
129struct time_data MPI_Request_free_data;
130struct time_data MPI_Recv_init_data;
131struct time_data MPI_Send_init_data;
132struct time_data MPI_Get_elements_data;
133struct time_data MPI_Get_count_data;
134struct time_data MPI_Ibsend_data;
135struct time_data MPI_Iprobe_data;
136struct time_data MPI_Irecv_data;
137struct time_data MPI_Irsend_data;
138struct time_data MPI_Isend_data;
139struct time_data MPI_Issend_data;
140struct time_data MPI_Pack_data;
141struct time_data MPI_Pack_size_data;
142struct time_data MPI_Probe_data;
143struct time_data MPI_Recv_data;
144struct time_data MPI_Rsend_data;
145struct time_data MPI_Rsend_init_data;
146struct time_data MPI_Send_data;
147struct time_data MPI_Sendrecv_data;
148struct time_data MPI_Sendrecv_replace_data;
149struct time_data MPI_Ssend_data;
150struct time_data MPI_Ssend_init_data;
151struct time_data MPI_Start_data;
152struct time_data MPI_Startall_data;
153struct time_data MPI_Test_data;
154struct time_data MPI_Testall_data;
155struct time_data MPI_Testany_data;
156struct time_data MPI_Test_cancelled_data;
157struct time_data MPI_Testsome_data;
158struct time_data MPI_Type_commit_data;
159struct time_data MPI_Type_contiguous_data;
160struct time_data MPI_Type_extent_data;
161struct time_data MPI_Type_free_data;
162struct time_data MPI_Type_hindexed_data;
163struct time_data MPI_Type_hvector_data;
164struct time_data MPI_Type_indexed_data;
165struct time_data MPI_Type_lb_data;
166struct time_data MPI_Type_size_data;
167struct time_data MPI_Type_struct_data;
168struct time_data MPI_Type_ub_data;
169struct time_data MPI_Type_vector_data;
170struct time_data MPI_Unpack_data;
171struct time_data MPI_Wait_data;
172struct time_data MPI_Waitall_data;
173struct time_data MPI_Waitany_data;
174struct time_data MPI_Waitsome_data;
175struct time_data MPI_Cart_coords_data;
176struct time_data MPI_Cart_create_data;
177struct time_data MPI_Cart_get_data;
178struct time_data MPI_Cart_map_data;
179struct time_data MPI_Cart_rank_data;
180struct time_data MPI_Cart_shift_data;
181struct time_data MPI_Cart_sub_data;
182struct time_data MPI_Cartdim_get_data;
183struct time_data MPI_Dims_create_data;
184struct time_data MPI_Graph_create_data;
185struct time_data MPI_Graph_get_data;
186struct time_data MPI_Graph_map_data;
187struct time_data MPI_Graph_neighbors_data;
188struct time_data MPI_Graph_neighbors_count_data;
189struct time_data MPI_Graphdims_get_data;
190struct time_data MPI_Topo_test_data;
191
196int bucket (lng)
197int lng;
198{
199 int i, j;
200 if (lng <= 0) {return(0);}
201 for (i=1, j=--lng; j>0; ++i) {
202 j = j>>1;
203 }
204 return (i);
205}
206
211void elapse (timer)
212double *timer;
213{
214#ifdef _AIX
215 *timer = rtc();
216#endif
217#ifdef __linux__
218 struct timeval st;
219 if (gettimeofday (&st, NULL) == -1) {
220 fprintf (stderr,
221 "elapse: gettimeofday: %s.\n",
222 strerror (errno));
223 *timer = 0.;
224 }
225 *timer = ((double) st.tv_sec) + 1.e-6 * ((double) st.tv_usec);
226#endif
227}
228
234void cputim (usr, sys)
235double *usr;
236double *sys;
237{
238 double real;
239 typedef struct { int tms_utime;
240 int tms_stime;
241 int tms_cutime;
242 int tms_cstime; } tms;
243
244 struct tms Time_buffer;
245 int ret;
246
247 ret = times (&Time_buffer);
248
249 real = ((double) ret) * 0.01;
250
251 *usr = ((double) Time_buffer.tms_utime) * 0.01;
252 *sys = ((double) Time_buffer.tms_stime) * 0.01;
253 return;
254}
255
260void start_timer (time)
261struct time_data *time;
262{
263 double user, sys;
264 double wall;
265
266 cputim (&user, &sys);
267 elapse (&wall);
268 time->s_cpu = user + sys;
269 time->s_wall = wall;
270
271 return;
272}
273
279void end_timer (time)
280struct time_data *time;
281{
282 double user, sys;
283 double wall;
284
285 cputim (&user, &sys);
286 elapse (&wall);
287 time->f_cpu = user + sys;
288 time->f_wall = wall;
289 time->c_cpu += time->f_cpu - time->s_cpu;
290 time->c_wall += time->f_wall - time->s_wall;
291
292 return;
293}
294
299void resource ()
300
301{
302 double usr, sys;
303 long data[14];
304#ifdef _AIX
305 typedef struct {
306 int tv_sec; /* seconds */
307 int tv_usec; /* microseconds */
308 } timeval;
309#endif
310 double user, system;
311 int ret;
312
313 struct rusage RU;
314 ret = getrusage (0, &RU);
315
316 if (ret != 0) {
317 printf ("getrusage FAILED!!!\n");
318 printf ("ret = %d\n", ret);
319 return;
320 }
321
322 user = ((double) RU.ru_utime.tv_sec) + (((double) RU.ru_utime.tv_usec) * ((double) 0.000001));
323 system = ((double) RU.ru_stime.tv_sec) + (((double) RU.ru_stime.tv_usec) * ((double) 0.000001));
324
325 printf("*****************RESOURCE STATISTICS*******************************\n");
326 printf("The total amount of wall time = %f\n", tot_wall);
327 printf("The total amount of time in user mode = %f\n", user);
328 printf("The total amount of time in sys mode = %f\n", system);
329#ifdef _AIX
330 printf("The maximum resident set size (KB) = %d\n", RU.ru_maxrss);
331 printf("Average shared memory use in text segment (KB*sec) = %d\n", RU.ru_ixrss);
332 printf("Average unshared memory use in data segment (KB*sec) = %d\n", RU.ru_idrss);
333 printf("Average unshared memory use in stack segment(KB*sec) = %d\n", RU.ru_isrss);
334 printf("Number of page faults without I/O activity = %d\n", RU.ru_minflt);
335 printf("Number of page faults with I/O activity = %d\n", RU.ru_majflt);
336 printf("Number of times process was swapped out = %d\n", RU.ru_nswap);
337 printf("Number of times filesystem performed INPUT = %d\n", RU.ru_inblock);
338 printf("Number of times filesystem performed OUTPUT = %d\n", RU.ru_oublock);
339 printf("Number of IPC messages sent = %d\n", RU.ru_msgsnd);
340 printf("Number of IPC messages received = %d\n", RU.ru_msgrcv);
341 printf("Number of Signals delivered = %d\n", RU.ru_nsignals);
342 printf("Number of Voluntary Context Switches = %d\n", RU.ru_nvcsw);
343 printf("Number of InVoluntary Context Switches = %d\n", RU.ru_nivcsw);
344#endif
345#ifdef __linux__
346 printf ("The maximum resident set size (KB) = %ld\n", RU.ru_maxrss);
347 printf ("Number of page faults without I/O activity = %ld\n", RU.ru_minflt);
348 printf ("Number of page faults with I/O activity = %ld\n", RU.ru_majflt);
349 printf ("Number of times filesystem performed INPUT = %ld\n", RU.ru_inblock);
350 printf ("Number of times filesystem performed OUTPUT = %ld\n", RU.ru_oublock);
351 printf ("Number of Voluntary Context Switches = %ld\n", RU.ru_nvcsw);
352 printf ("Number of InVoluntary Context Switches = %ld\n", RU.ru_nivcsw);
353#endif
354 printf("*****************END OF RESOURCE STATISTICS*************************\n\n");
355
356 usr = user;
357 sys = system;
358 data[0] = RU.ru_maxrss;
359 data[1] = RU.ru_ixrss;
360 data[2] = RU.ru_idrss;
361 data[3] = RU.ru_isrss;
362 data[4] = RU.ru_minflt;
363 data[5] = RU.ru_majflt;
364 data[6] = RU.ru_nswap;
365 data[7] = RU.ru_inblock;
366 data[8] = RU.ru_oublock;
367 data[9] = RU.ru_msgsnd;
368 data[10] = RU.ru_msgrcv;
369 data[11] = RU.ru_nsignals;
370 data[12] = RU.ru_nvcsw;
371 data[13] = RU.ru_nivcsw;
372 return;
373}
374
381void print_timing (string, time)
382char *string;
383struct time_data *time;
384{
385 if (time->c_calls > 0) {
386 fprintf (fp, "Information for %s: AVG. Length = %13.2f, CALLS = %d, WALL = %13.3f, CPU = %13.3f \n",
387 string, (double) (time->c_bytes) / (double) time->c_calls, time->c_calls,
388 time->c_wall, time->c_cpu);
389 }
390
391 if (time->c_wall > 0.001 ) {
392 fprintf (fp, " %s: Total BYTES = %g, BW = %8.3f MBYTES/WALL SEC., BW = %8.3f MBYTES/CPU SEC.\n",
393 string, time->c_bytes,
394 ((double) time->c_bytes * 0.000001)/time->c_wall,
395 ((double) time->c_bytes * 0.000001)/time->c_cpu);
396 }
397
398 twall += time->c_wall;
399 tcpu += time->c_cpu;
400 tbytes += time->c_bytes * 0.000001;
401
402 /* Print the distribution of the message lengths */
403 if (time->c_calls > 0) {
404 int i, j1, j2;
405
406 j1 = 0; j2 = 0;
407 fprintf (fp, " AVG. Length # of Calls MB/WALL Sec. MB/CPU Sec. WALL Secs. CPU Secs. \n");
408 if (time->c_buckets[0] >0) {
409 fprintf (fp, " %13.2f %13d %13.3f %13.3f %13.4f %13.4f \n",
410 time->c_sum[0]/(float)time->c_buckets[0], time->c_buckets[0],
411 ((double) time->c_sum[0] * 0.000001)/time->b_wall[0],
412 ((double) time->c_sum[0] * 0.000001)/time->b_cpu[0],
413 time->b_wall[0], time->b_cpu[0]);
414 }
415 time->c_buckets[3] = time->c_buckets[1] + time->c_buckets[2] + time->c_buckets[3];
416 j1 = 1; j2 = 4;
417 for (i =3; i < 31; ++i) {
418 if (time->c_buckets[i] > 0) {
419 fprintf (fp, " %13.2f %13d %13.3f %13.3f %13.4f %13.4f \n",
420 time->c_sum[i]/(float)time->c_buckets[i], time->c_buckets[i],
421 ((double) time->c_sum[i] * 0.000001)/time->b_wall[i],
422 ((double) time->c_sum[i] * 0.000001)/time->b_cpu[i],
423 time->b_wall[i], time->b_cpu[i]);
424 }
425 j1 = j2 +1;
426 j2 = j2 + j2;
427 }
428
429 fprintf (fp, "\n");
430 }
431}
432
437void summary_ (int *returnVal)
438{
439 double temp, temp1;
440 char trace_file[255], processor[8];
441
442/*
443 MPI_Finalize - prototyping replacement for MPI_Finalize
444*/
445 elapse(&final_wall);
446 tot_wall = final_wall - start_wall;
447
448 resource();
449
450 if (fp) fclose (fp);
451 return;
452}
453
458void start_ ()
459{
460 int stateid;
461 int Argc;
462 char **Argv;
463
464 char *answer;
465
466 trace_flag=1;
467
468 profile = 0;
469 elapse (&start_wall);
470 return;
471}
void print_timing(char *string, struct time_data *time)
Definition summary.c:381
void resource()
Definition summary.c:299
void elapse(double *timer)
Definition summary.c:211
void summary_(int *returnVal)
Definition summary.c:437
void cputim(double *usr, double *sys)
Definition summary.c:234
void start_timer(struct time_data *time)
Definition summary.c:260
void end_timer(struct time_data *time)
Definition summary.c:279
int bucket(int lng)
Definition summary.c:196
void start_()
Definition summary.c:458