31#include <sys/utsname.h>
37#include <sys/resource.h>
40static FILE *fp = NULL;
45double tcpu, twall, tbytes, f_bytes;
46double tot_wall, final_wall, start_wall;
47double cpu_comm, wall_comm;
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;
200 if (lng <= 0) {
return(0);}
201 for (i=1, j=--lng; j>0; ++i) {
219 if (gettimeofday (&st, NULL) == -1) {
221 "elapse: gettimeofday: %s.\n",
225 *timer = ((double) st.tv_sec) + 1.e-6 * ((double) st.tv_usec);
239 typedef struct {
int tms_utime;
242 int tms_cstime; } tms;
244 struct tms Time_buffer;
247 ret = times (&Time_buffer);
249 real = ((double) ret) * 0.01;
251 *usr = ((double) Time_buffer.tms_utime) * 0.01;
252 *sys = ((double) Time_buffer.tms_stime) * 0.01;
261struct time_data *time;
268 time->s_cpu = user + sys;
280struct time_data *time;
287 time->f_cpu = user + sys;
289 time->c_cpu += time->f_cpu - time->s_cpu;
290 time->c_wall += time->f_wall - time->s_wall;
314 ret = getrusage (0, &RU);
317 printf (
"getrusage FAILED!!!\n");
318 printf (
"ret = %d\n", ret);
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));
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);
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);
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);
354 printf(
"*****************END OF RESOURCE STATISTICS*************************\n\n");
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;
383struct time_data *time;
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);
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);
398 twall += time->c_wall;
400 tbytes += time->c_bytes * 0.000001;
403 if (time->c_calls > 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]);
415 time->c_buckets[3] = time->c_buckets[1] + time->c_buckets[2] + time->c_buckets[3];
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]);
440 char trace_file[255], processor[8];
446 tot_wall = final_wall - start_wall;
void print_timing(char *string, struct time_data *time)
void elapse(double *timer)
void summary_(int *returnVal)
void cputim(double *usr, double *sys)
void start_timer(struct time_data *time)
void end_timer(struct time_data *time)