$\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }$
Take Down Multi-threading Sum of 1/i

Syntax
ok = harmonic_takedown(sum) 
Purpose
This routine does the takedown for splitting the summation that defines the harmonic series $$s = 1 + 1/2 + 1/3 + ... + 1/n$$ into separate parts for each thread; see harmonic_setup .

It is assumed that this function is called by thread zero, and all the other threads have completed their work and are blocked (waiting).

sum
This argument has prototype       double& sum  The input value of the argument does not matter. Upon return it is the value of the summation; i.e. $s$.

Source

namespace {
bool harmonic_takedown(double& sum)
{     // sum = 1/num_sum + 1/(num_sum-1) + ... + 1
bool ok            = true;
sum                = 0.;
//
// go down so that free memory for other threads before memory for master
{     // check that this tread was ok with the work it did
//
//
// delete problem specific information
void* v_ptr = static_cast<void*>( work_all_[thread_num] );
}