@@ -41,6 +41,14 @@ class HighsTimer {
4141 presolve_clock = clock_def (" Presolve" );
4242 solve_clock = clock_def (" Solve" );
4343 postsolve_clock = clock_def (" Postsolve" );
44+ printf_flag = true ;
45+ }
46+
47+ /* *
48+ * @brief Set the printf flag
49+ */
50+ void setPrintfFlag (const bool output_flag, const bool log_to_console) {
51+ this ->printf_flag = output_flag ? log_to_console : false ;
4452 }
4553
4654 /* *
@@ -73,6 +81,7 @@ class HighsTimer {
7381 this ->presolve_clock = clock_def (" Presolve" );
7482 this ->solve_clock = clock_def (" Solve" );
7583 this ->postsolve_clock = clock_def (" Postsolve" );
84+ this ->printf_flag = true ;
7685 }
7786
7887 /* *
@@ -92,7 +101,7 @@ class HighsTimer {
92101 void writeAllClocks () {
93102 for (HighsInt i = 0 ; i < num_clock; i++)
94103 if (clock_num_call[i])
95- printf (" Time %7.5f for %9d calls of clock %3d: %s\n " , clock_time[i],
104+ if (printf_flag) printf (" Time %7.5f for %9d calls of clock %3d: %s\n " , clock_time[i],
96105 int (clock_num_call[i]), int (i), clock_names[i].c_str ());
97106 }
98107
@@ -113,15 +122,15 @@ class HighsTimer {
113122 // understand this better, for now don't assert that this clock
114123 // has stopped
115124 if (!clock_stopped) {
116- printf (" Clock %d - %s - still running\n " , int (i_clock),
125+ if (printf_flag) printf (" Clock %d - %s - still running\n " , int (i_clock),
117126 clock_names[i_clock].c_str ());
118127 }
119128 assert (clock_stopped);
120129 }
121130 // Set the start to be the negation of the WallTick to check that
122131 // the clock's been started when it's next stopped
123132 if (i_clock == check_clock) {
124- printf (" HighsTimer: starting clock %d: %s\n " , int (check_clock),
133+ if (printf_flag) printf (" HighsTimer: starting clock %d: %s\n " , int (check_clock),
125134 this ->clock_names [check_clock].c_str ());
126135 }
127136 clock_start[i_clock] = -getWallTime ();
@@ -138,7 +147,7 @@ class HighsTimer {
138147 // -getWallTime() <= 0
139148 const bool clock_stopped = clock_start[i_clock] > 0 ;
140149 if (clock_stopped) {
141- printf (" Clock %d - %s - not running\n " , int (i_clock),
150+ if (printf_flag) printf (" Clock %d - %s - not running\n " , int (i_clock),
142151 clock_names[i_clock].c_str ());
143152 }
144153 assert (!clock_stopped);
@@ -149,7 +158,7 @@ class HighsTimer {
149158 // Set the start to be the WallTick to check that the clock's been
150159 // stopped when it's next started
151160 if (i_clock == check_clock) {
152- printf (" HighsTimer: stopping clock %d: %s\n " , int (check_clock),
161+ if (printf_flag) printf (" HighsTimer: stopping clock %d: %s\n " , int (check_clock),
153162 this ->clock_names [check_clock].c_str ());
154163 }
155164 clock_start[i_clock] = wall_time;
@@ -164,7 +173,7 @@ class HighsTimer {
164173 assert (i_clock < num_clock);
165174 if (i_clock == check_clock) {
166175 std::string clock_name = this ->clock_names [check_clock];
167- printf (" HighsTimer: reading clock %d: %s\n " , int (check_clock),
176+ if (printf_flag) printf (" HighsTimer: reading clock %d: %s\n " , int (check_clock),
168177 clock_name.c_str ());
169178 }
170179 double read_time;
@@ -187,7 +196,7 @@ class HighsTimer {
187196 assert (i_clock >= 0 );
188197 assert (i_clock < num_clock);
189198 if (i_clock == check_clock) {
190- printf (" HighsTimer: querying clock %d: %s - with start record %g\n " ,
199+ if (printf_flag) printf (" HighsTimer: querying clock %d: %s - with start record %g\n " ,
191200 int (check_clock), this ->clock_names [check_clock].c_str (),
192201 clock_start[i_clock]);
193202 }
@@ -243,7 +252,7 @@ class HighsTimer {
243252 size_t num_clock_list_entries = clock_list.size ();
244253 double current_run_highs_time = read ();
245254 bool non_null_report = false ;
246-
255+ if (!printf_flag) return non_null_report;
247256 // Check validity of the clock list and check no clocks are still
248257 // running, determine whether there are any times to report and
249258 // determine the total clock times
@@ -365,6 +374,7 @@ class HighsTimer {
365374 HighsInt presolve_clock;
366375 HighsInt solve_clock;
367376 HighsInt postsolve_clock;
377+ bool printf_flag;
368378};
369379
370380#endif /* UTIL_HIGHSTIMER_H_ */
0 commit comments