CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
set_get_in_parallel.hpp
Go to the documentation of this file.
1 // $Id$
2 # ifndef CPPAD_LOCAL_SET_GET_IN_PARALLEL_HPP
3 # define CPPAD_LOCAL_SET_GET_IN_PARALLEL_HPP
4 
5 /* --------------------------------------------------------------------------
6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
7 
8 CppAD is distributed under multiple licenses. This distribution is under
9 the terms of the
10  Eclipse Public License Version 1.0.
11 
12 A copy of this license is included in the COPYING file of this distribution.
13 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
14 -------------------------------------------------------------------------- */
15 
16 # include <cassert>
17 # include <cppad/configure.hpp>
18 namespace CppAD { namespace local { // BEGIN_CPPAD_LOCAL_NAMESPACE
19 
20 /*!
21 \file set_get_in_parallel.hpp
22 File used to set and get user in_parallel routine.
23 */
24 /*!
25 Set and call the routine that determine if we are in parallel execution mode.
26 
27 \return
28 value retuned by most recent setting for in_parallel_new.
29 If set is true,
30 or the most recent setting is CPPAD_NULL (its initial value),
31 the return value is false.
32 Otherwise the function corresponding to the most recent setting
33 is called and its value returned by set_get_in_parallel.
34 
35 \param in_parallel_new [in]
36 If set is false, in_parallel_new it is not used.
37 Otherwise, the current value of in_parallel_new becomes the
38 most recent setting for in_parallel_user.
39 
40 \param set
41 If set is true, then parallel_new is becomes the most
42 recent setting for this set_get_in_parallel.
43 In this case, it is assumed that we are currently in sequential execution mode.
44 */
45 static bool set_get_in_parallel(
46  bool (*in_parallel_new)(void) ,
47  bool set = false )
48 { static bool (*in_parallel_user)(void) = CPPAD_NULL;
49 
50  if( set )
51  { in_parallel_user = in_parallel_new;
52  // Doing a raw assert in this case because set_get_in_parallel is used
53  // by ErrorHandler and hence cannot use ErrorHandler.
54  // CPPAD_ASSERT_UNKNOWN( in_parallel_user() == false )
55  assert(in_parallel_user == CPPAD_NULL || in_parallel_user() == false);
56  return false;
57  }
58  //
59  if( in_parallel_user == CPPAD_NULL )
60  return false;
61  //
62  return in_parallel_user();
63 }
64 
65 } } // END_CPPAD_LOCAL_NAMESPACE
66 
67 # endif
static bool set_get_in_parallel(bool(*in_parallel_new)(void), bool set=false)
Set and call the routine that determine if we are in parallel execution mode.