Prev | Next | multi_chkpoint_one_takedown |
ok = multi_chkpoint_one_takedown(square_root)
vector<double>& square_root
The input value of
square_root
does not matter.
Upon return,
it has the same size and is the element by element square root of
y_squared
.
bool ok
If it is false,
multi_chkpoint_one_takedown
detected an error.
namespace { bool multi_chkpoint_one_takedown(vector<double>& square_root) { bool ok = true; ok &= thread_alloc::thread_num() == 0; size_t num_threads = std::max(num_threads_, size_t(1)); // // extract square roots in original order square_root.resize(0); for(size_t thread_num = 0; thread_num < num_threads; thread_num++) { // results for this thread size_t n = work_all_[thread_num]->square_root->size(); for(size_t i = 0; i < n; i++) square_root.push_back((* work_all_[thread_num]->square_root )[i]); } // // go down so that free memory for other threads before memory for master size_t thread_num = num_threads; while(thread_num--) { // check that this tread was ok with the work it did ok &= work_all_[thread_num]->ok; // // run destructor on vector object for this thread delete work_all_[thread_num]->y_squared; delete work_all_[thread_num]->square_root; // // run destructor on function object for this thread delete work_all_[thread_num]->fun; // // delete problem specific information void* v_ptr = static_cast<void*>( work_all_[thread_num] ); thread_alloc::return_memory( v_ptr ); // // Note that checkpoint object has memory connect to each thread // thread_alloc::inuse(thread_num) cannot be zero until it is deleted if( thread_num > 0 ) { ok &= thread_alloc::inuse(thread_num) > 0; // // return all memory that is not in use and // but being held for future use by this thread thread_alloc::free_available(thread_num); } } return ok; } }