Prev | Next | harmonic_worker |
harmonic_worker()
1/start + 1/(start+1) + ... + 1/(end-1)
start = work_all_[thread_num]->start
end = work_all_[thread_num]->end
namespace { void harmonic_worker(void) { // sum = 1/(stop-1) + 1/(stop-2) + ... + 1/start size_t thread_num = thread_alloc::thread_num(); size_t num_threads = std::max(num_threads_, size_t(1)); bool ok = thread_num < num_threads; size_t start = work_all_[thread_num]->start; size_t stop = work_all_[thread_num]->stop; double sum = 0.; ok &= stop > start; size_t i = stop; while( i > start ) { i--; sum += 1. / double(i); } work_all_[thread_num]->sum = sum; work_all_[thread_num]->ok = ok; } }