$\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}} }$

Syntax
ok = multi_newton_setup(      num_sub, xlow, xup, epsilon, max_itr, num_threads )

Purpose
These routine does the setup for splitting finding all the zeros in an interval into separate sub-intervals, one for each thread.

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

num_sub
See num_sub in multi_newton_run .

xlow
See xlow in multi_newton_run .

xup
See xup in multi_newton_run .

epsilon
See epsilon in multi_newton_run .

max_itr
See max_itr in multi_newton_run .

See num_threads in multi_newton_run .

Source

namespace {
bool multi_newton_setup(
size_t num_sub                              ,
double xlow                                 ,
double xup                                  ,
double epsilon                              ,
size_t max_itr                              ,
{

// inputs that are same for all threads
epsilon_ = epsilon;
max_itr_ = max_itr;

// resize the work vector to accomidate the number of threads
ok &= work_all_.size() == 0;

// length of each sub interval
sub_length_ = (xup - xlow) / double(num_sub);

// determine values that are specific to each thread
size_t num_min   = num_sub / num_threads; // minimum num_sub
size_t num_more  = num_sub % num_threads; // number that have one more
size_t sum_num   = 0;  // sum with respect to thread of num_sub
{
// allocate separate memory for this thread to avoid false sharing
size_t min_bytes(sizeof(work_one_t)), cap_bytes;

// thread_alloc is a raw memory allocator; i.e., it does not call
// the constructor for the objects it creates. The vector
// class requires it's constructor to be called so we do it here
# else
# endif

// number of sub-intervalse for this thread

double xlow_thread = xlow + double(sum_num) * sub_length_;

xlow + double(sum_num + num_sub_thread) * sub_length_;

// update sum_num for next time through loop

// input information specific to this thread
}