Prev | Next | harmonic_takedown |
ok = harmonic_takedown(sum)
double& sum
The input value of the argument does not matter.
Upon return it is the value of the summation; i.e. @(@
s
@)@.
namespace { bool harmonic_takedown(double& sum) { // sum = 1/num_sum + 1/(num_sum-1) + ... + 1 bool ok = true; ok &= thread_alloc::thread_num() == 0; size_t num_threads = std::max(num_threads_, size_t(1)); sum = 0.; // // 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; // // add this threads contribution to the sum sum += work_all_[thread_num]->sum; // // delete problem specific information void* v_ptr = static_cast<void*>( work_all_[thread_num] ); thread_alloc::return_memory( v_ptr ); // // check that there is no longer any memory inuse by this thread // (for general applications, the master might still be using memory) ok &= thread_alloc::inuse(thread_num) == 0; // // return all memory being held for future use by this thread thread_alloc::free_available(thread_num); } return ok; } }