Skip to content

Commit 97072da

Browse files
committed
Add iteration times
1 parent f348b6a commit 97072da

7 files changed

Lines changed: 41 additions & 33 deletions

File tree

dynadjust/dynadjust/dnaadjust/dnaadjust-multi.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ void dna_adjust::AdjustPhasedMultiThread()
9494
initialiseIteration();
9595

9696
std::string corr_msg;
97-
std::ostringstream ss;
9897
UINT32 i;
9998
bool iterate(true);
10099

101-
std::chrono::milliseconds iteration_time(std::chrono::milliseconds(0));
102100
cpu_timer it_time, tot_time;
103101

104102
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
@@ -169,7 +167,6 @@ void dna_adjust::AdjustPhasedMultiThread()
169167
for_each(mt_adjust_threads.begin(), mt_adjust_threads.end(), std::mem_fn(&std::thread::join));
170168
#endif
171169
// This point is reached when the threads have finished
172-
iteration_time = std::chrono::duration_cast<std::chrono::milliseconds>(it_time.elapsed().wall);
173170

174171
//delete mt_adjust_threads;
175172
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
@@ -195,25 +192,20 @@ void dna_adjust::AdjustPhasedMultiThread()
195192
if (IsCancelled())
196193
break;
197194

198-
ss.str("");
199-
if (iteration_time >= std::chrono::seconds(1)) {
200-
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(iteration_time);
201-
ss << seconds.count() << "s";
202-
} else {
203-
ss << iteration_time.count() << "ms";
204-
}
195+
std::string iteration_time_str = format_wall_time(it_time.elapsed().wall);
205196

206197
///////////////////////////////////
207198
// protected write to adj file (not needed here since write to
208199
// adj file at this stage is via single thread
209-
adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Elapsed time" << ss.str() << std::endl;
200+
adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Elapsed time" << iteration_time_str << std::endl;
210201
OutputLargestCorrection(corr_msg);
211202
///////////////////////////////////
212203

213204
if (projectSettings_.g.verbose)
214205
debug_file << concurrentAdjustments.print_adjusted_blocks();
215206

216207
iterationCorrections_.add_message(corr_msg);
208+
iterationTimes_.add_message(iteration_time_str);
217209
iterationQueue_.push_and_notify(CurrentIteration()); // currentIteration begins at 1, so not zero-indexed
218210

219211
// continue iterating?

dynadjust/dynadjust/dnaadjust/dnaadjust.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,7 @@ _ADJUST_STATUS_ dna_adjust::AdjustNetwork()
21122112
isIterationComplete_ = false;
21132113
isAdjustmentQuestionable_ = false;
21142114
iterationCorrections_.clear_messages();
2115+
iterationTimes_.clear_messages();
21152116

21162117
if (projectSettings_.o._database_ids)
21172118
LoadDatabaseId();
@@ -2432,6 +2433,7 @@ void dna_adjust::AdjustSimultaneous()
24322433

24332434
// update data for messages
24342435
iterationCorrections_.add_message(corr_msg);
2436+
iterationTimes_.add_message(format_wall_time(it_time.elapsed().wall));
24352437
iterationQueue_.push_and_notify(CurrentIteration()); // currentIteration begins at 1, so not zero-indexed
24362438
isIterationComplete_ = true;
24372439

@@ -2567,8 +2569,9 @@ void dna_adjust::AdjustPhased()
25672569

25682570
// Calculate and print largest adjustment correction and station ID
25692571
OutputLargestCorrection(corr_msg);
2570-
2572+
25712573
iterationCorrections_.add_message(corr_msg);
2574+
iterationTimes_.add_message(format_wall_time(it_time.elapsed().wall));
25722575
iterationQueue_.push_and_notify(CurrentIteration()); // currentIteration begins at 1, so not zero-indexed
25732576
isIterationComplete_ = true;
25742577

@@ -2645,8 +2648,9 @@ void dna_adjust::AdjustPhasedBlock1()
26452648

26462649
if (fabs(maxCorr_) > projectSettings_.a.iteration_threshold)
26472650
adjustStatus_ = ADJUST_THRESHOLD_EXCEEDED;
2648-
2651+
26492652
iterationCorrections_.add_message(corr_msg);
2653+
iterationTimes_.add_message(format_wall_time(it_time.elapsed().wall));
26502654
iterationQueue_.push_and_notify(CurrentIteration()); // currentIteration begins at 1, so not zero-indexed
26512655

26522656
ValidateandFinaliseAdjustment(tot_time);

dynadjust/dynadjust/dnaadjust/dnaadjust.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ namespace networkadjust {
102102
extern std::mutex maxCorrMutex;
103103

104104
using dynadjust::cpu_timer;
105+
using dynadjust::format_wall_time;
105106

106107
// forward declaration of dna_adjust
107108
class dna_adjust;
@@ -350,6 +351,12 @@ class dna_adjust {
350351
return iterationCorrections_.get_message(iteration); // safe guard
351352
return iterationCorrections_.get_message(iteration - 1);
352353
};
354+
355+
inline std::string GetIterationTime(const UINT32& iteration) const {
356+
if (iteration == 0)
357+
return iterationTimes_.get_message(iteration); // safe guard
358+
return iterationTimes_.get_message(iteration - 1);
359+
};
353360
/////////////////////////////
354361

355362
concurrent_ofstream<std::string> concurrent_adj_ofstream;
@@ -1118,6 +1125,7 @@ class dna_adjust {
11181125
bool allStationsFixed_;
11191126

11201127
message_bank<std::string> iterationCorrections_;
1128+
message_bank<std::string> iterationTimes_;
11211129

11221130
// For each block
11231131
vUINT32 v_ContiguousNetList_; // vector of contiguous network IDs

dynadjust/dynadjust/dnaadjust/dnaadjust_printer.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,13 @@ void DynAdjustPrinter::PrintIteration(const UINT32& iteration) {
8080
}
8181

8282
void DynAdjustPrinter::PrintAdjustmentTime(cpu_timer& time, int timer_type) {
83-
// calculate and print total time
84-
auto elapsed = time.elapsed();
85-
double seconds = elapsed.wall.count() / 1.0e9;
86-
87-
std::stringstream ss;
88-
if (seconds >= 1.0) {
89-
ss << std::fixed << std::setprecision(3) << seconds << "s";
90-
} else {
91-
ss << std::fixed << std::setprecision(3) << (seconds * 1000.0) << "ms";
92-
}
83+
std::string time_str = format_wall_time(time.elapsed().wall);
9384

9485
if (timer_type == 0) // iteration_time equivalent
95-
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Elapsed time" << ss.str() << std::endl;
86+
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Elapsed time" << time_str << std::endl;
9687
else
9788
{
98-
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Total time" << ss.str() << std::endl << std::endl;
89+
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Total time" << time_str << std::endl << std::endl;
9990
}
10091
}
10192

dynadjust/dynadjust/dnaadjustwrapper/dnaadjustprogress.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,14 @@ void dna_adjust_progress_thread::processAdjustment()
323323
ss.str("");
324324
ss << " Iteration " << std::right << std::setw(2) << std::fixed << std::setprecision(0) << currentIteration;
325325
ss << ", max station corr: " << std::right << std::setw(PROGRESS_ADJ_BLOCK_12) <<
326-
_dnaAdj->GetMaxCorrection(currentIteration) << std::endl;
327-
326+
_dnaAdj->GetMaxCorrection(currentIteration);
327+
ss << ", time: " << _dnaAdj->GetIterationTime(currentIteration) << std::endl;
328+
328329
coutMessage(ss.str());
329330
}
330331
std::this_thread::sleep_for(std::chrono::milliseconds(80));
331332
}
332-
333+
333334
break;
334335
case Phased_Block_1Mode:
335336
case PhasedMode:
@@ -350,12 +351,13 @@ void dna_adjust_progress_thread::processAdjustment()
350351

351352
ss.str("");
352353
ss << " Iteration " << std::right << std::setw(2) << std::fixed << std::setprecision(0) << currentIteration;
353-
ss << ", max station corr: " << std::right << std::setw(PROGRESS_ADJ_BLOCK_12) << _dnaAdj->GetMaxCorrection(currentIteration) << std::endl;
354-
354+
ss << ", max station corr: " << std::right << std::setw(PROGRESS_ADJ_BLOCK_12) << _dnaAdj->GetMaxCorrection(currentIteration);
355+
ss << ", time: " << _dnaAdj->GetIterationTime(currentIteration) << std::endl;
356+
355357
sst.str("");
356358
if (first_time)
357359
sst << std::setw(PROGRESS_ADJ_BLOCK_28) << std::left << " ";
358-
sst << PROGRESS_BACKSPACE_28 << std::setw(PROGRESS_ADJ_BLOCK_28) << std::left << ss.str();
360+
sst << PROGRESS_BACKSPACE_28 << std::left << ss.str();
359361
coutMessage(sst.str());
360362
first_time = true;
361363
}

dynadjust/dynadjust/dnaadjustwrapper/dnaadjustwrapper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ void PrintSummaryMessage(dna_adjust* netAdjust, const project_settings* p, boost
8686
break;
8787
std::stringstream ss("");
8888
ss << " Iteration " << std::right << std::setw(2) << std::fixed << std::setprecision(0) << currentIteration;
89-
ss << ", max station corr: " << std::right << std::setw(12) << netAdjust->GetMaxCorrection(currentIteration) << std::endl;
90-
std::cout << PROGRESS_BACKSPACE_28 << std::setw(28) << std::left << ss.str();
89+
ss << ", max station corr: " << std::right << std::setw(12) << netAdjust->GetMaxCorrection(currentIteration);
90+
ss << ", time: " << netAdjust->GetIterationTime(currentIteration) << std::endl;
91+
std::cout << PROGRESS_BACKSPACE_28 << std::left << ss.str();
9192
}
9293

9394
if (p->a.report_mode)

dynadjust/include/functions/dnatimer.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ class cpu_timer {
7272
std::chrono::high_resolution_clock::time_point start_time_;
7373
};
7474

75+
inline std::string format_wall_time(std::chrono::nanoseconds wall) {
76+
double seconds = wall.count() / 1.0e9;
77+
std::ostringstream oss;
78+
if (seconds >= 1.0)
79+
oss << std::fixed << std::setprecision(3) << seconds << "s";
80+
else
81+
oss << std::fixed << std::setprecision(3) << (seconds * 1000.0) << "ms";
82+
return oss.str();
83+
}
84+
7585
} // namespace dynadjust
7686

7787
#endif // DNATIMER_H_

0 commit comments

Comments
 (0)