multi_newton_common

View page source

Common Variables use by Multi-Threaded Newton Method

Purpose

This source code defined the common include files, defines, and variables that are used by the multi-newton method.

Source

# include <cppad/cppad.hpp>
# include <cppad/utility/time_test.hpp>
# include <cmath>
# include <cstring>
# include "multi_newton.hpp"
# include "team_thread.hpp"
# define USE_THREAD_ALLOC_FOR_WORK_ALL 1

namespace {
   using CppAD::thread_alloc; // fast multi-threadeding memory allocator
   using CppAD::vector;       // uses thread_alloc

   // number of threads, set by multi_newton_time.
   size_t num_threads_ = 0;

   // function we are finding zeros of, set by multi_newton_time
   void (*fun_)(double x, double& f, double& df) = 0;

   // convergence criteria, set by multi_newton_setup
   double epsilon_ = 0.;

   // maximum number of iterations, set by  multi_newton_setup
   size_t max_itr_ = 0;

   // length for all sub-intervals
   double sub_length_ = 0.;

   // structure with information for one thread
   typedef struct {
      // number of sub intervals (worker input)
      size_t num_sub;
      // beginning of interval (worker input)
      double xlow;
      // end of interval (worker input)
      double xup;
      // vector of zero candidates (worker output)
      // after call to multi_newton_setup:    x.size() == 0
      // after call to multi_newton_work:     x.size() is number of zeros
      // after call to multi_newton_takedown: x.size() == 0
      vector<double> x;
      // false if an error occurs, true otherwise (worker output)
      bool   ok;
   } work_one_t;
   // vector with information for all threads
   // after call to multi_newton_setup:    work_all.size() == num_threads
   // after call to multi_newton_takedown: work_all.size() == 0
   // (use pointers instead of values to avoid false sharing)
   vector<work_one_t*> work_all_;
}