CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
omp_max_thread.hpp
Go to the documentation of this file.
1 // $Id$
2 # ifndef CPPAD_CORE_OMP_MAX_THREAD_HPP
3 # define CPPAD_CORE_OMP_MAX_THREAD_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 $begin omp_max_thread$$
17 $spell
18  alloc
19  num
20  omp
21  OpenMp
22  CppAD
23 $$
24 
25 $section OpenMP Parallel Setup$$
26 $mindex omp_max_thread$$
27 
28 $head Deprecated 2011-06-23$$
29 Use $cref/thread_alloc::parallel_setup/ta_parallel_setup/$$
30 to set the number of threads.
31 
32 $head Syntax$$
33 $codei%AD<%Base%>::omp_max_thread(%number%)
34 %$$
35 
36 $head Purpose$$
37 By default, for each $codei%AD<%Base%>%$$ class there is only one
38 tape that records $cref/AD of Base/glossary/AD of Base/$$ operations.
39 This tape is a global variable and hence it cannot be used
40 by multiple OpenMP threads at the same time.
41 The $code omp_max_thread$$ function is used to set the
42 maximum number of OpenMP threads that can be active.
43 In this case, there is a different tape corresponding to each
44 $codei%AD<%Base%>%$$ class and thread pair.
45 
46 $head number$$
47 The argument $icode number$$ has prototype
48 $codei%
49  size_t %number%
50 %$$
51 It must be greater than zero and specifies the maximum number of
52 OpenMp threads that will be active at one time.
53 
54 
55 $head Independent$$
56 Each call to $cref/Independent(x)/Independent/$$
57 creates a new $cref/active/glossary/Tape/Active/$$ tape.
58 All of the operations with the corresponding variables
59 must be preformed by the same OpenMP thread.
60 This includes the corresponding call to
61 $cref/f.Dependent(x,y)/Dependent/$$ or the
62 $cref/ADFun f(x, y)/FunConstruct/Sequence Constructor/$$
63 during which the tape stops recording and the variables
64 become parameters.
65 
66 $head Restriction$$
67 No tapes can be
68 $cref/active/glossary/Tape/Active/$$ when this function is called.
69 
70 $end
71 -----------------------------------------------------------------------------
72 */
73 
74 // BEGIN CppAD namespace
75 namespace CppAD {
76 
77 template <class Base>
78 void AD<Base>::omp_max_thread(size_t number)
79 {
80 # ifdef _OPENMP
83  );
84 # else
86  number == 1,
87  "omp_max_thread: number > 1 and _OPENMP is not defined"
88  );
89 # endif
90  parallel_ad<Base>();
91 }
92 
93 } // END CppAD namespace
94 
95 # endif
#define CPPAD_ASSERT_KNOWN(exp, msg)
Check that exp is true, if not print msg and terminate execution.
static bool in_parallel(void)
Are we in a parallel execution state; i.e., is it possible that other threads are currently executing...
Definition: omp_alloc.hpp:135
static void parallel_setup(size_t num_threads, bool(*in_parallel)(void), size_t(*thread_num)(void))
Set thread_alloc up for parallel mode usage.
static size_t get_thread_num(void)
Get current OpenMP thread number (zero if _OpenMP not defined).
Definition: omp_alloc.hpp:183
static void omp_max_thread(size_t number)