1 /* This software was developed by Bruce Hendrickson and Robert Leland   *
2  * at Sandia National Laboratories under US Department of Energy        *
3  * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
4 
5 #include   <stdio.h>
6 
7 /* Timing parameters. */
8 
9 double    start_time = -1;
10 double    total_time = 0;
11 double    input_time = 0;
12 double    partition_time = 0;
13 double 	  sequence_time = 0;
14 double    kernel_time = 0;
15 double    reformat_time = 0;
16 double    check_input_time = 0;
17 double    count_time = 0;
18 double    print_assign_time = 0;
19 
20 double    coarsen_time = 0;
21 double    match_time = 0;
22 double    make_cgraph_time = 0;
23 
24 double    lanczos_time = 0;
25 double    splarax_time = 0;
26 double    orthog_time = 0;
27 double    ql_time = 0;
28 double    tevec_time = 0;
29 double    ritz_time = 0;
30 double    evec_time = 0;
31 double    blas_time = 0;
32 double    init_time = 0;
33 double    scan_time = 0;
34 double    debug_time = 0;
35 double    pause_time = 0;
36 
37 double    rqi_symmlq_time = 0;
38 double    refine_time = 0;
39 
40 double    kl_total_time = 0;
41 double    kl_init_time = 0;
42 double    nway_kl_time = 0;
43 double    kl_bucket_time = 0;
44 
45 double    inertial_time = 0;
46 double    inertial_axis_time = 0;
47 double    median_time = 0;
48 
49 double    sim_time = 0;
50 
51 
time_out(outfile)52 void      time_out(outfile)
53 FILE     *outfile;		/* file to print output to */
54 {
55     FILE     *tempfile;		/* file name for two passes */
56     extern int ECHO;		/* parameter for different output styles */
57     extern int OUTPUT_TIME;	/* how much timing output should I print? */
58     double    time_tol;		/* tolerance for ignoring time */
59     double    other_time;	/* time not accounted for */
60     int       i;		/* loop counter */
61 
62     time_tol = 0.005;
63 
64     for (i = 0; i < 2; i++) {
65 	if (i == 1) {		/* Print to file? */
66 	    if (ECHO < 0)
67 		tempfile = outfile;
68 	    else
69 		break;
70 	}
71 	else {			/* Print to stdout. */
72 	    tempfile = stdout;
73 	}
74 
75 
76 	if (OUTPUT_TIME > 0) {
77 	    if (total_time != 0) {
78 		fprintf(tempfile, "\nTotal time: %g sec.\n", total_time);
79 		if (input_time != 0)
80 		    fprintf(tempfile, "  input %g\n", input_time);
81 		if (reformat_time != 0)
82 		    fprintf(tempfile, "  reformatting %g\n", reformat_time);
83 		if (check_input_time != 0)
84 		    fprintf(tempfile, "  checking input %g\n", check_input_time);
85 		if (partition_time != 0)
86 		    fprintf(tempfile, "  partitioning %g\n", partition_time);
87 		if (sequence_time != 0)
88 		    fprintf(tempfile, "  sequencing %g\n", sequence_time);
89 		if (kernel_time != 0)
90 		    fprintf(tempfile, "  kernel benchmarking %g\n", kernel_time);
91 		if (count_time != 0)
92 		    fprintf(tempfile, "  evaluation %g\n", count_time);
93 		if (print_assign_time != 0)
94 		    fprintf(tempfile, "  printing assignment file %g\n", print_assign_time);
95 
96 		if (sim_time != 0)
97 		    fprintf(tempfile, "  simulating %g\n", sim_time);
98 		other_time = total_time - input_time - reformat_time -
99 		   check_input_time - partition_time - count_time -
100 		   print_assign_time - sim_time - sequence_time - kernel_time;
101 		if (other_time > time_tol)
102 		    fprintf(tempfile, "  other %g\n", other_time);
103 	    }
104 	}
105 
106 	if (OUTPUT_TIME > 1) {
107 	    if (inertial_time != 0) {
108 		if (inertial_time != 0)
109 		    fprintf(tempfile, "\nInertial time: %g sec.\n", inertial_time);
110 		if (inertial_axis_time != 0)
111 		    fprintf(tempfile, "  inertial axis %g\n", inertial_axis_time);
112 		if (median_time != 0)
113 		    fprintf(tempfile, "  median finding %g\n", median_time);
114 		other_time = inertial_time - inertial_axis_time - median_time;
115 		if (other_time > time_tol)
116 		    fprintf(tempfile, "  other %g\n", other_time);
117 	    }
118 
119 	    if (kl_total_time != 0) {
120 		if (kl_total_time != 0)
121 		    fprintf(tempfile, "\nKL time: %g sec.\n", kl_total_time);
122 		if (kl_init_time != 0)
123 		    fprintf(tempfile, "  initialization %g\n", kl_init_time);
124 		if (nway_kl_time != 0)
125 		    fprintf(tempfile, "  nway refinement %g\n", nway_kl_time);
126 		if (kl_bucket_time != 0)
127 		    fprintf(tempfile, "    bucket sorting %g\n", kl_bucket_time);
128 		other_time = kl_total_time - kl_init_time - nway_kl_time;
129 		if (other_time > time_tol)
130 		    fprintf(tempfile, "  other %g\n", other_time);
131 	    }
132 
133 	    if (coarsen_time != 0 && rqi_symmlq_time == 0) {
134 		fprintf(tempfile, "\nCoarsening %g sec.\n", coarsen_time);
135 		if (match_time != 0)
136 		    fprintf(tempfile, "  maxmatch %g\n", match_time);
137 		if (make_cgraph_time != 0)
138 		    fprintf(tempfile, "  makecgraph %g\n", make_cgraph_time);
139 	    }
140 
141 	    if (lanczos_time != 0) {
142 		fprintf(tempfile, "\nLanczos time: %g sec.\n", lanczos_time);
143 		if (splarax_time != 0)
144 		    fprintf(tempfile, "  matvec/solve %g\n", splarax_time);
145 		if (blas_time != 0)
146 		    fprintf(tempfile, "  vector ops %g\n", blas_time);
147 		if (evec_time != 0)
148 		    fprintf(tempfile, "  assemble evec %g\n", evec_time);
149 		if (init_time != 0)
150 		    fprintf(tempfile, "  malloc/init/free %g\n", init_time);
151 		if (orthog_time != 0)
152 		    fprintf(tempfile, "  maintain orthog %g\n", orthog_time);
153 		if (scan_time != 0)
154 		    fprintf(tempfile, "  scan %g\n", scan_time);
155 		if (debug_time != 0)
156 		    fprintf(tempfile, "  debug/warning/check %g\n", debug_time);
157 		if (ql_time != 0)
158 		    fprintf(tempfile, "  ql/bisection %g\n", ql_time);
159 		if (tevec_time != 0)
160 		    fprintf(tempfile, "  tevec %g\n", tevec_time);
161 		if (ritz_time != 0)
162 		    fprintf(tempfile, "  compute ritz %g\n", ritz_time);
163 		if (pause_time != 0)
164 		    fprintf(tempfile, "  pause %g\n", pause_time);
165 		other_time = lanczos_time - splarax_time - orthog_time
166 		   - ql_time - tevec_time - ritz_time - evec_time
167 		   - blas_time - init_time - scan_time - debug_time - pause_time;
168 		if (other_time > time_tol && other_time != lanczos_time) {
169 		    fprintf(tempfile, "  other %g\n", other_time);
170 		}
171 	    }
172 
173 	    if (rqi_symmlq_time != 0) {
174 		fprintf(tempfile, "\nRQI/Symmlq time: %g sec.\n", rqi_symmlq_time);
175 		if (coarsen_time != 0)
176 		    fprintf(tempfile, "  coarsening %g\n", coarsen_time);
177 		if (match_time != 0)
178 		    fprintf(tempfile, "    maxmatch %g\n", match_time);
179 		if (make_cgraph_time != 0)
180 		    fprintf(tempfile, "    makecgraph %g\n", make_cgraph_time);
181 		if (refine_time != 0)
182 		    fprintf(tempfile, "  refinement %g\n", refine_time);
183 		if (lanczos_time != 0)
184 		    fprintf(tempfile, "  lanczos %g\n", lanczos_time);
185 		other_time = rqi_symmlq_time - coarsen_time - refine_time - lanczos_time;
186 		if (other_time > time_tol)
187 		    fprintf(tempfile, "  other %g\n", other_time);
188 	    }
189 	}
190     }
191 }
192 
193 
clear_timing()194 void      clear_timing()
195 {
196     start_time = -1;
197     total_time = 0;
198     input_time = 0;
199     partition_time = 0;
200     sequence_time = 0;
201     kernel_time = 0;
202     reformat_time = 0;
203     check_input_time = 0;
204     count_time = 0;
205     print_assign_time = 0;
206 
207     coarsen_time = 0;
208     match_time = 0;
209     make_cgraph_time = 0;
210 
211     lanczos_time = 0;
212     splarax_time = 0;
213     orthog_time = 0;
214     ql_time = 0;
215     tevec_time = 0;
216     ritz_time = 0;
217     evec_time = 0;
218     blas_time = 0;
219     init_time = 0;
220     scan_time = 0;
221     debug_time = 0;
222     pause_time = 0;
223 
224     rqi_symmlq_time = 0;
225     refine_time = 0;
226 
227     kl_total_time = 0;
228     kl_init_time = 0;
229     nway_kl_time = 0;
230     kl_bucket_time = 0;
231 
232     inertial_time = 0;
233     inertial_axis_time = 0;
234     median_time = 0;
235 
236     sim_time = 0;
237 }
238