Skip to content

Commit 93f48ba

Browse files
authored
Merge pull request GeoscienceAustralia#278 from GeoscienceAustralia/dr-refactor-boost
Refactoring boost usage
2 parents baebbbb + da39d78 commit 93f48ba

File tree

103 files changed

+5868
-2050
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+5868
-2050
lines changed

dynadjust/dynadjust/dnaadjust/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ add_library (${PROJECT_NAME} SHARED
1616
${CMAKE_SOURCE_DIR}/include/io/map_file.cpp
1717
${CMAKE_SOURCE_DIR}/include/io/seg_file.cpp
1818
${CMAKE_SOURCE_DIR}/include/io/dnaiotbu.cpp
19-
${CMAKE_SOURCE_DIR}/include/io/dnaiosnxwrite.cpp
19+
${CMAKE_SOURCE_DIR}/include/io/snx_file_writer.cpp
2020
${CMAKE_SOURCE_DIR}/include/parameters/dnadatum.cpp
2121
${CMAKE_SOURCE_DIR}/include/parameters/dnaellipsoid.cpp
2222
${CMAKE_SOURCE_DIR}/include/parameters/dnaprojection.cpp

dynadjust/dynadjust/dnaadjust/dnaadjust-multi.cpp

Lines changed: 69 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ concurrent_block_adjustment<UINT32> concurrentAdjustments;
2727

2828
extern concurrent_queue<UINT32> combineAdjustmentQueue;
2929
extern concurrent_queue<UINT32> prepareAdjustmentQueue;
30-
extern boost::mutex dbg_file_mutex;
31-
extern boost::exception_ptr fwd_error;
32-
extern boost::exception_ptr rev_error;
33-
extern boost::exception_ptr cmb_error;
34-
extern boost::exception_ptr prep_error;
30+
extern std::mutex dbg_file_mutex;
31+
extern std::exception_ptr fwd_error;
32+
extern std::exception_ptr rev_error;
33+
extern std::exception_ptr cmb_error;
34+
extern std::exception_ptr prep_error;
3535

36-
bool combineAdjustmentExceptionThrown(const std::vector<boost::exception_ptr>& cmb_errors_)
36+
bool combineAdjustmentExceptionThrown(const std::vector<std::exception_ptr>& cmb_errors_)
3737
{
3838
// got a forward or reverse exception, or
3939
// have any of the other combination adjustments failed?
@@ -57,7 +57,7 @@ bool combineAdjustmentExceptionThrown(const std::vector<boost::exception_ptr>& c
5757
return false;
5858
}
5959

60-
bool prepareAdjustmentExceptionThrown(const std::vector<boost::exception_ptr>& prep_errors_)
60+
bool prepareAdjustmentExceptionThrown(const std::vector<std::exception_ptr>& prep_errors_)
6161
{
6262
// have any of the other combination adjustments failed?
6363
UINT32 err_size(static_cast<UINT32>(prep_errors_.size()));
@@ -98,14 +98,14 @@ void dna_adjust::AdjustPhasedMultiThread()
9898
UINT32 i;
9999
bool iterate(true);
100100

101-
boost::posix_time::milliseconds iteration_time(boost::posix_time::milliseconds(0));
102-
boost::timer::cpu_timer it_time, tot_time;
101+
std::chrono::milliseconds iteration_time(std::chrono::milliseconds(0));
102+
cpu_timer it_time, tot_time;
103103

104104
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
105-
boost::shared_ptr<thread> f, r, c;
106-
std::vector< boost::shared_ptr<thread> > mt_adjust_threads_sp;
105+
std::shared_ptr<std::thread> f, r, c;
106+
std::vector< std::shared_ptr<std::thread> > mt_adjust_threads_sp;
107107
#else
108-
std::vector<boost::thread> mt_adjust_threads;
108+
std::vector<std::thread> mt_adjust_threads;
109109
#endif
110110

111111
concurrentAdjustments.resize_runs(blockCount_);
@@ -136,26 +136,26 @@ void dna_adjust::AdjustPhasedMultiThread()
136136
// Forward and reverse threads sequentially adjust all blocks in
137137
// forward and reverse directions.
138138
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
139-
f.reset(new thread(adjust_forward_thread(this, boost::ref(fwd_error))));
139+
f.reset(new thread(adjust_forward_thread(this, std::ref(fwd_error))));
140140
mt_adjust_threads_sp.push_back(f);
141-
r.reset(new thread(adjust_reverse_thread(this, boost::ref(rev_error))));
141+
r.reset(new thread(adjust_reverse_thread(this, std::ref(rev_error))));
142142
mt_adjust_threads_sp.push_back(r);
143143
#else
144-
mt_adjust_threads.push_back(boost::thread(adjust_forward_thread(this, boost::ref(fwd_error))));
145-
mt_adjust_threads.push_back(boost::thread(adjust_reverse_thread(this, boost::ref(rev_error))));
144+
mt_adjust_threads.push_back(std::thread(adjust_forward_thread(this, std::ref(fwd_error))));
145+
mt_adjust_threads.push_back(std::thread(adjust_reverse_thread(this, std::ref(rev_error))));
146146
#endif
147147

148148
// Combination thread fires up as many threads as there are cores
149149
// on the current PC to concurrently combine blocks
150150
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
151151
if (CombinationThreadRequired())
152152
{
153-
c.reset(new thread(adjust_combine_thread(this, boost::ref(cmb_error))));
153+
c.reset(new thread(adjust_combine_thread(this, std::ref(cmb_error))));
154154
mt_adjust_threads_sp.push_back(c);
155155
}
156156
#else
157157
if (CombinationThreadRequired())
158-
mt_adjust_threads.push_back(boost::thread(adjust_combine_thread(this, boost::ref(cmb_error))));
158+
mt_adjust_threads.push_back(std::thread(adjust_combine_thread(this, std::ref(cmb_error))));
159159
#endif
160160

161161
// Start the clock
@@ -164,12 +164,12 @@ void dna_adjust::AdjustPhasedMultiThread()
164164
// Start the forward, reverse and combine threads, which commences the
165165
// network adjustment
166166
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
167-
for_each(mt_adjust_threads_sp.begin(), mt_adjust_threads_sp.end(), boost::mem_fn(&thread::join));
167+
for_each(mt_adjust_threads_sp.begin(), mt_adjust_threads_sp.end(), std::mem_fn(&thread::join));
168168
#else
169-
for_each(mt_adjust_threads.begin(), mt_adjust_threads.end(), boost::mem_fn(&boost::thread::join));
169+
for_each(mt_adjust_threads.begin(), mt_adjust_threads.end(), std::mem_fn(&std::thread::join));
170170
#endif
171171
// This point is reached when the threads have finished
172-
iteration_time = boost::posix_time::milliseconds(it_time.elapsed().wall/MILLI_TO_NANO);
172+
iteration_time = std::chrono::duration_cast<std::chrono::milliseconds>(it_time.elapsed().wall);
173173

174174
//delete mt_adjust_threads;
175175
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
@@ -184,22 +184,24 @@ void dna_adjust::AdjustPhasedMultiThread()
184184
// test stub handle the exception
185185
if (fwd_error)
186186
// exception thrown in the forward pass
187-
boost::rethrow_exception(fwd_error);
187+
std::rethrow_exception(fwd_error);
188188
else if (rev_error)
189189
// exception thrown in the reverse pass
190-
boost::rethrow_exception(rev_error);
190+
std::rethrow_exception(rev_error);
191191
else if (cmb_error)
192192
// exception thrown in one of the combination adjustments
193-
boost::rethrow_exception(cmb_error);
193+
std::rethrow_exception(cmb_error);
194194

195195
if (IsCancelled())
196196
break;
197197

198198
ss.str("");
199-
if (iteration_time > boost::posix_time::seconds(1))
200-
ss << boost::posix_time::seconds(static_cast<long>(iteration_time.total_seconds()));
201-
else
202-
ss << iteration_time;
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+
}
203205

204206
///////////////////////////////////
205207
// protected write to adj file (not needed here since write to
@@ -374,7 +376,7 @@ void adjust_forward_thread::operator()()
374376

375377
try {
376378
// Set exception
377-
error_ = boost::exception_ptr();
379+
error_ = std::exception_ptr();
378380

379381
for (currentBlock=0; currentBlock<main_adj_->blockCount_; ++currentBlock)
380382
{
@@ -454,11 +456,11 @@ void adjust_forward_thread::operator()()
454456
combineAdjustmentQueue.notify_all();
455457

456458
// Reset exception
457-
error_ = boost::exception_ptr();
459+
error_ = std::exception_ptr();
458460

459461
}
460462
catch (...) {
461-
error_ = boost::current_exception();
463+
error_ = std::current_exception();
462464
if (combineAdjustmentQueue.is_empty())
463465
combineAdjustmentQueue.push_and_notify(99999999);
464466
//combineAdjustmentQueue.notify_all();
@@ -468,7 +470,7 @@ void adjust_forward_thread::operator()()
468470
// notify all threads waiting on combineAdjustmentQueue
469471
//combineAdjustmentQueue.notify_all();
470472

471-
//this_thread::sleep(boost::posix_time::milliseconds(10));
473+
//std::this_thread::sleep_for(std::chrono::milliseconds(10));
472474

473475
// notify all threads waiting on combineAdjustmentQueue
474476
//combineAdjustmentQueue.notify_all();
@@ -484,7 +486,7 @@ void adjust_reverse_thread::operator()()
484486

485487
try {
486488
// Set exception
487-
error_ = boost::exception_ptr();
489+
error_ = std::exception_ptr();
488490

489491
for (block=0; block<main_adj_->blockCount_; ++block, --currentBlock)
490492
{
@@ -581,11 +583,11 @@ void adjust_reverse_thread::operator()()
581583
combineAdjustmentQueue.queue_exhausted();
582584

583585
// Reset exception
584-
error_ = boost::exception_ptr();
586+
error_ = std::exception_ptr();
585587

586588
}
587589
catch (...) {
588-
error_ = boost::current_exception();
590+
error_ = std::current_exception();
589591
if (combineAdjustmentQueue.is_empty())
590592
combineAdjustmentQueue.push_and_notify(99999999);
591593
return;
@@ -615,7 +617,7 @@ void adjust_process_combine_thread::operator()()
615617
// Wait here until blocks have been placed on the queue
616618
if (!combineAdjustmentQueue.front_and_pop(currentBlock))
617619
{
618-
boost::this_thread::sleep(boost::posix_time::milliseconds(2));
620+
std::this_thread::sleep_for(std::chrono::milliseconds(2));
619621
continue;
620622
}
621623

@@ -635,10 +637,10 @@ void adjust_process_combine_thread::operator()()
635637
}
636638
}
637639

638-
error_ = boost::exception_ptr();
640+
error_ = std::exception_ptr();
639641
}
640642
catch (...) {
641-
error_ = boost::current_exception();
643+
error_ = std::current_exception();
642644
return;
643645
}
644646
}
@@ -658,18 +660,18 @@ void adjust_combine_thread::operator()()
658660
// OK, at this point, there is a block # in the queue - let's combine!
659661

660662
// Get number of cores available
661-
UINT32 thread_id, cores(boost::thread::hardware_concurrency());
663+
UINT32 thread_id, cores(std::thread::hardware_concurrency());
662664

663665
// Set up exception pointers
664-
std::vector<boost::exception_ptr> cmb_errors;
666+
std::vector<std::exception_ptr> cmb_errors;
665667
cmb_errors.resize(cores);
666668

667669
// Create the thread pool
668670
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
669-
boost::shared_ptr<thread> c;
670-
std::vector< boost::shared_ptr<thread> > mt_combine_threads_sp;
671+
std::shared_ptr<std::thread> c;
672+
std::vector< std::shared_ptr<std::thread> > mt_combine_threads_sp;
671673
#else
672-
std::vector<boost::thread> mt_combine_threads;
674+
std::vector<std::thread> mt_combine_threads;
673675
#endif
674676

675677
for (thread_id=0; thread_id<cores; ++thread_id)
@@ -680,25 +682,25 @@ void adjust_combine_thread::operator()()
680682
adjust_process_combine_thread(
681683
main_adj_, // pointer to main adjustment object
682684
thread_id, // this new thread's ID (1..n, where n = # cores)
683-
boost::ref(cmb_errors.at(thread_id)), // reference to this thread's exception_ptr
684-
boost::ref(cmb_errors)))); // reference to all other threads' exception_ptrs
685+
std::ref(cmb_errors.at(thread_id)), // reference to this thread's exception_ptr
686+
std::ref(cmb_errors)))); // reference to all other threads' exception_ptrs
685687

686688
mt_combine_threads_sp.push_back(c);
687689
#else
688-
mt_combine_threads.push_back(boost::thread(
690+
mt_combine_threads.push_back(std::thread(
689691
adjust_process_combine_thread(
690692
main_adj_, // pointer to main adjustment object
691693
thread_id, // this new thread's ID (1..n, where n = # cores)
692-
boost::ref(cmb_errors.at(thread_id)), // reference to this thread's exception_ptr
693-
boost::ref(cmb_errors)))); // reference to all other threads' exception_ptrs
694+
std::ref(cmb_errors.at(thread_id)), // reference to this thread's exception_ptr
695+
std::ref(cmb_errors)))); // reference to all other threads' exception_ptrs
694696
#endif
695697

696698
}
697699

698700
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
699-
for_each(mt_combine_threads_sp.begin(), mt_combine_threads_sp.end(), boost::mem_fn(&thread::join));
701+
for_each(mt_combine_threads_sp.begin(), mt_combine_threads_sp.end(), std::mem_fn(&thread::join));
700702
#else
701-
for_each(mt_combine_threads.begin(), mt_combine_threads.end(), boost::mem_fn(&boost::thread::join));
703+
for_each(mt_combine_threads.begin(), mt_combine_threads.end(), std::mem_fn(&std::thread::join));
702704
#endif
703705

704706
// cmb_error is set during combineThreadProcessor
@@ -734,7 +736,7 @@ void adjust_process_prepare_thread::operator()()
734736
// Wait here until blocks have been placed on the queue
735737
if (!prepareAdjustmentQueue.front_and_pop(currentBlock))
736738
{
737-
boost::this_thread::sleep(boost::posix_time::milliseconds(2));
739+
std::this_thread::sleep_for(std::chrono::milliseconds(2));
738740
continue;
739741
}
740742

@@ -750,10 +752,10 @@ void adjust_process_prepare_thread::operator()()
750752
prepareAdjustmentQueue.queue_exhausted();
751753
}
752754

753-
error_ = boost::exception_ptr();
755+
error_ = std::exception_ptr();
754756
}
755757
catch (...) {
756-
error_ = boost::current_exception();
758+
error_ = std::current_exception();
757759
}
758760
}
759761

@@ -765,18 +767,18 @@ void adjust_prepare_thread::operator()()
765767

766768
// OK, at this point, there is a block # in the queue - let's combine!
767769
// Get number of cores available
768-
UINT32 thread_id, cores(boost::thread::hardware_concurrency());
770+
UINT32 thread_id, cores(std::thread::hardware_concurrency());
769771

770772
// Set up exception pointers
771-
std::vector<boost::exception_ptr> prep_errors;
773+
std::vector<std::exception_ptr> prep_errors;
772774
prep_errors.resize(cores);
773775

774776
// Create the thread pool
775777
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
776-
boost::shared_ptr<thread> p;
777-
std::vector< boost::shared_ptr<thread> > mt_prepare_threads_sp;
778+
std::shared_ptr<std::thread> p;
779+
std::vector< std::shared_ptr<std::thread> > mt_prepare_threads_sp;
778780
#else
779-
std::vector<boost::thread> mt_prepare_threads;
781+
std::vector<std::thread> mt_prepare_threads;
780782
#endif
781783

782784

@@ -787,24 +789,24 @@ void adjust_prepare_thread::operator()()
787789
adjust_process_prepare_thread(
788790
main_adj_, // pointer to main adjustment object
789791
thread_id, // this new thread's ID (1..n, where n = # cores)
790-
boost::ref(prep_errors.at(thread_id)), // reference to this thread's exception_ptr
791-
boost::ref(prep_errors)))); // reference to all other threads' exception_ptrs
792+
std::ref(prep_errors.at(thread_id)), // reference to this thread's exception_ptr
793+
std::ref(prep_errors)))); // reference to all other threads' exception_ptrs
792794

793795
mt_prepare_threads_sp.push_back(p);
794796
#else
795-
mt_prepare_threads.push_back(boost::thread(
797+
mt_prepare_threads.push_back(std::thread(
796798
adjust_process_prepare_thread(
797799
main_adj_, // pointer to main adjustment object
798800
thread_id, // this new thread's ID (1..n, where n = # cores)
799-
boost::ref(prep_errors.at(thread_id)), // reference to this thread's exception_ptr
800-
boost::ref(prep_errors)))); // reference to all other threads' exception_ptrs
801+
std::ref(prep_errors.at(thread_id)), // reference to this thread's exception_ptr
802+
std::ref(prep_errors)))); // reference to all other threads' exception_ptrs
801803
#endif
802804
}
803805

804806
#if defined(__ICC) || defined(__INTEL_COMPILER) // Intel compiler
805-
for_each(mt_prepare_threads_sp.begin(), mt_prepare_threads_sp.end(), boost::mem_fn(&thread::join));
807+
for_each(mt_prepare_threads_sp.begin(), mt_prepare_threads_sp.end(), std::mem_fn(&thread::join));
806808
#else
807-
for_each(mt_prepare_threads.begin(), mt_prepare_threads.end(), boost::mem_fn(&boost::thread::join));
809+
for_each(mt_prepare_threads.begin(), mt_prepare_threads.end(), std::mem_fn(&std::thread::join));
808810
#endif
809811

810812
// prep_error is set during prepareThreadProcessor
@@ -823,7 +825,7 @@ void dna_adjust::PrepareAdjustmentMultiThread()
823825
{
824826
prepareAdjustmentQueue.reset_blocks_coming();
825827

826-
boost::thread mt_prepare_thread(adjust_prepare_thread(this, boost::ref(prep_error)));
828+
std::thread mt_prepare_thread(adjust_prepare_thread(this, std::ref(prep_error)));
827829

828830
// Start the forward, reverse and combine threads, which commences the
829831
// network adjustment
@@ -833,7 +835,7 @@ void dna_adjust::PrepareAdjustmentMultiThread()
833835
// test stub handle the exception
834836
if (prep_error)
835837
// exception thrown in one of the combination adjustments
836-
boost::rethrow_exception(prep_error);
838+
std::rethrow_exception(prep_error);
837839
}
838840

839841

dynadjust/dynadjust/dnaadjust/dnaadjust-stage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void dna_adjust::PrepareMappedRegions(const UINT32& block)
5151
ss << " adjustment exist, or re-run the adjustment using the" << std::endl;
5252
ss << " --" << RECREATE_STAGE_FILES << " option." << std::endl;
5353
adj_file << std::endl << "- Error: " << ss.str() << std::endl;
54-
throw boost::enable_current_exception(std::runtime_error(ss.str()));
54+
throw std::runtime_error(ss.str());
5555
}
5656
}
5757

0 commit comments

Comments
 (0)