In pseudo code show how to add the terms of the harmonic ser
In pseudo code, show how to add the terms of the harmonic series (1 + 1/2 + 1/3 + ...) using 4 threads. Stop adding terms when they become smaller than 10^(-5).
Solution
bool harmonic(double& sum, size_t num_sum, size_t num_threads) { // sum = 1/num_sum + 1/(num_sum-1) + ... + 1 bool ok = true; // setup the work for num_threads_ threads ok &= harmonic_setup(num_sum, num_threads); // now do the work for each thread if( num_threads > 0 ) team_work( harmonic_worker ); else harmonic_worker(); // now combine the result for all the threads ok &= harmonic_combine(sum); return ok; if(sum