NCEPLIBS-w3emc  2.11.0
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 
40 static FILE *fp = NULL;
41 int numtask, mypid;
42 int procid_0;
43 int profile, msglen;
44 int trace_flag;
45 double tcpu, twall, tbytes, f_bytes;
46 double tot_wall, final_wall, start_wall;
47 double cpu_comm, wall_comm;
48 #ifdef _AIX
49 extern double rtc ();
50 #endif
51 struct 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 
66 struct time_data MPI_Allgather_data;
67 struct time_data MPI_Allgatherv_data;
68 struct time_data MPI_Allreduce_data;
69 struct time_data MPI_Alltoall_data;
70 struct time_data MPI_Alltoallv_data;
71 struct time_data MPI_Barrier_data;
72 struct time_data MPI_Bcast_data;
73 struct time_data MPI_Gather_data;
74 struct time_data MPI_Gatherv_data;
75 struct time_data MPI_Op_create_data;
76 struct time_data MPI_Op_free_data;
77 struct time_data MPI_Reduce_scatter_data;
78 struct time_data MPI_Reduce_data;
79 struct time_data MPI_Scan_data;
80 struct time_data MPI_Scatter_data;
81 struct time_data MPI_Scatterv_data;
82 struct time_data MPI_Attr_delete_data;
83 struct time_data MPI_Attr_get_data;
84 struct time_data MPI_Attr_put_data;
85 struct time_data MPI_Comm_compare_data;
86 struct time_data MPI_Comm_create_data;
87 struct time_data MPI_Comm_dup_data;
88 struct time_data MPI_Comm_free_data;
89 struct time_data MPI_Comm_group_data;
90 struct time_data MPI_Comm_rank_data;
91 struct time_data MPI_Comm_remote_group_data;
92 struct time_data MPI_Comm_remote_size_data;
93 struct time_data MPI_Comm_size_data;
94 struct time_data MPI_Comm_split_data;
95 struct time_data MPI_Comm_test_inter_data;
96 struct time_data MPI_Group_compare_data;
97 struct time_data MPI_Group_difference_data;
98 struct time_data MPI_Group_excl_data;
99 struct time_data MPI_Group_free_data;
100 struct time_data MPI_Group_incl_data;
101 struct time_data MPI_Group_intersection_data;
102 struct time_data MPI_Group_rank_data;
103 struct time_data MPI_Group_range_excl_data;
104 struct time_data MPI_Group_range_incl_data;
105 struct time_data MPI_Group_size_data;
106 struct time_data MPI_Group_translate_ranks_data;
107 struct time_data MPI_Group_union_data;
108 struct time_data MPI_Intercomm_create_data;
109 struct time_data MPI_Intercomm_merge_data;
110 struct time_data MPI_Keyval_create_data;
111 struct time_data MPI_Keyval_free_data;
112 struct time_data MPI_Abort_data;
113 struct time_data MPI_Error_class_data;
114 struct time_data MPI_Errhandler_create_data;
115 struct time_data MPI_Errhandler_free_data;
116 struct time_data MPI_Errhandler_get_data;
117 struct time_data MPI_Error_string_data;
118 struct time_data MPI_Errhandler_set_data;
119 struct time_data MPI_Get_processor_name_data;
120 struct time_data MPI_Initialized_data;
121 struct time_data MPI_Wtick_data;
122 struct time_data MPI_Wtime_data;
123 struct time_data MPI_Address_data;
124 struct time_data MPI_Bsend_data;
125 struct time_data MPI_Bsend_init_data;
126 struct time_data MPI_Buffer_attach_data;
127 struct time_data MPI_Buffer_detach_data;
128 struct time_data MPI_Cancel_data;
129 struct time_data MPI_Request_free_data;
130 struct time_data MPI_Recv_init_data;
131 struct time_data MPI_Send_init_data;
132 struct time_data MPI_Get_elements_data;
133 struct time_data MPI_Get_count_data;
134 struct time_data MPI_Ibsend_data;
135 struct time_data MPI_Iprobe_data;
136 struct time_data MPI_Irecv_data;
137 struct time_data MPI_Irsend_data;
138 struct time_data MPI_Isend_data;
139 struct time_data MPI_Issend_data;
140 struct time_data MPI_Pack_data;
141 struct time_data MPI_Pack_size_data;
142 struct time_data MPI_Probe_data;
143 struct time_data MPI_Recv_data;
144 struct time_data MPI_Rsend_data;
145 struct time_data MPI_Rsend_init_data;
146 struct time_data MPI_Send_data;
147 struct time_data MPI_Sendrecv_data;
148 struct time_data MPI_Sendrecv_replace_data;
149 struct time_data MPI_Ssend_data;
150 struct time_data MPI_Ssend_init_data;
151 struct time_data MPI_Start_data;
152 struct time_data MPI_Startall_data;
153 struct time_data MPI_Test_data;
154 struct time_data MPI_Testall_data;
155 struct time_data MPI_Testany_data;
156 struct time_data MPI_Test_cancelled_data;
157 struct time_data MPI_Testsome_data;
158 struct time_data MPI_Type_commit_data;
159 struct time_data MPI_Type_contiguous_data;
160 struct time_data MPI_Type_extent_data;
161 struct time_data MPI_Type_free_data;
162 struct time_data MPI_Type_hindexed_data;
163 struct time_data MPI_Type_hvector_data;
164 struct time_data MPI_Type_indexed_data;
165 struct time_data MPI_Type_lb_data;
166 struct time_data MPI_Type_size_data;
167 struct time_data MPI_Type_struct_data;
168 struct time_data MPI_Type_ub_data;
169 struct time_data MPI_Type_vector_data;
170 struct time_data MPI_Unpack_data;
171 struct time_data MPI_Wait_data;
172 struct time_data MPI_Waitall_data;
173 struct time_data MPI_Waitany_data;
174 struct time_data MPI_Waitsome_data;
175 struct time_data MPI_Cart_coords_data;
176 struct time_data MPI_Cart_create_data;
177 struct time_data MPI_Cart_get_data;
178 struct time_data MPI_Cart_map_data;
179 struct time_data MPI_Cart_rank_data;
180 struct time_data MPI_Cart_shift_data;
181 struct time_data MPI_Cart_sub_data;
182 struct time_data MPI_Cartdim_get_data;
183 struct time_data MPI_Dims_create_data;
184 struct time_data MPI_Graph_create_data;
185 struct time_data MPI_Graph_get_data;
186 struct time_data MPI_Graph_map_data;
187 struct time_data MPI_Graph_neighbors_data;
188 struct time_data MPI_Graph_neighbors_count_data;
189 struct time_data MPI_Graphdims_get_data;
190 struct time_data MPI_Topo_test_data;
191 
196 int bucket (lng)
197 int 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 
211 void elapse (timer)
212 double *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 
234 void cputim (usr, sys)
235 double *usr;
236 double *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 
260 void start_timer (time)
261 struct 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 
279 void end_timer (time)
280 struct 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 
299 void 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 
381 void print_timing (string, time)
382 char *string;
383 struct 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 
437 void 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 
458 void 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