![]() |
Prev | Next | harmonic_setup |
ok = harmonic_setup(num_sum)
num_sum
has prototype
size_t num_sum
It specifies the value of @(@
n
@)@ in the summation.
namespace { bool harmonic_setup(size_t num_sum) { // sum = 1/num_sum + 1/(num_sum-1) + ... + 1 size_t num_threads = std::max(num_threads_, size_t(1)); bool ok = num_threads == thread_alloc::num_threads(); ok &= thread_alloc::thread_num() == 0; ok &= num_sum >= num_threads; // for(size_t thread_num = 0; thread_num < num_threads; thread_num++) { // allocate separate memory for this thread to avoid false sharing size_t min_bytes(sizeof(work_one_t)), cap_bytes; void* v_ptr = thread_alloc::get_memory(min_bytes, cap_bytes); work_all_[thread_num] = static_cast<work_one_t*>(v_ptr); // // in case this thread's worker does not get called work_all_[thread_num]->ok = false; // parameters that define the work for this and previous thread if( thread_num == 0 ) work_all_[0]->start = 1; else { size_t index = (num_sum * thread_num) / num_threads; work_all_[thread_num-1]->stop = index; work_all_[thread_num]->start = index; } } work_all_[num_threads-1]->stop = num_sum + 1; return ok; } }