Prev Next harmonic_worker

@(@\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}} }@)@This is cppad-20221105 documentation. Here is a link to its current documentation .
Do One Thread's Work for Sum of 1/i

Syntax
harmonic_worker()

Purpose
This routines computes the sum the summation that defines the harmonic series
    1/
start + 1/(start+1) + ... + 1/(end-1)

start
This is the value of the harmonic_common information
    
start = work_all_[thread_num]->start

end
This is the value of the harmonic_common information
    
end = work_all_[thread_num]->end

thread_num
This is the number for the current thread; see thread_num .

Source

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;
}
}

Input File: example/multi_thread/harmonic.cpp