Prev | Next | harmonic_sum |
ok = harmonic_sum(sum, num_sum)
bool ok
If this return value is false, an error occurred during harmonic
.
double& sum
The input value of the argument does not matter.
Upon return it is the value of the summation; i.e. @(@
s
@)@.
size_t num_sum
It specifies the number of terms in the summation; i.e. @(@
n
@)@.
namespace { bool harmonic_sum(double& sum, size_t num_sum) { // sum = 1/num_sum + 1/(num_sum-1) + ... + 1 bool ok = true; ok &= thread_alloc::thread_num() == 0; // setup the work for multi-threading ok &= harmonic_setup(num_sum); // now do the work for each thread if( num_threads_ > 0 ) team_work( harmonic_worker ); else harmonic_worker(); // combine the result for each thread and takedown the multi-threading. ok &= harmonic_takedown(sum); return ok; } }