CppAD: A C++ Algorithmic Differentiation Package
20130102
|
00001 /* $Id$ */ 00002 # ifndef CPPAD_OMP_MAX_THREAD_INCLUDED 00003 # define CPPAD_OMP_MAX_THREAD_INCLUDED 00004 00005 /* -------------------------------------------------------------------------- 00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-11 Bradley M. Bell 00007 00008 CppAD is distributed under multiple licenses. This distribution is under 00009 the terms of the 00010 Eclipse Public License Version 1.0. 00011 00012 A copy of this license is included in the COPYING file of this distribution. 00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses. 00014 -------------------------------------------------------------------------- */ 00015 /* 00016 $begin omp_max_thread$$ 00017 $spell 00018 alloc 00019 num 00020 omp 00021 OpenMp 00022 CppAD 00023 $$ 00024 00025 $section OpenMP Parallel Setup$$ 00026 00027 $head Deprecated$$ 00028 $index depreciated, omp_max_thread$$ 00029 $index omp_max_thread, depreciated$$ 00030 Use $cref/thread_alloc::parallel_setup/ta_parallel_setup/$$ 00031 to set the number of threads. 00032 00033 $head Syntax$$ 00034 $codei%AD<%Base%>::omp_max_thread(%number%) 00035 %$$ 00036 00037 $head Purpose$$ 00038 By default, for each $codei%AD<%Base%>%$$ class there is only one 00039 tape that records $cref/AD of Base/glossary/AD of Base/$$ operations. 00040 This tape is a global variable and hence it cannot be used 00041 by multiple OpenMP threads at the same time. 00042 The $code omp_max_thread$$ function is used to set the 00043 maximum number of OpenMP threads that can be active. 00044 In this case, there is a different tape corresponding to each 00045 $codei%AD<%Base%>%$$ class and thread pair. 00046 00047 $head number$$ 00048 The argument $icode number$$ has prototype 00049 $codei% 00050 size_t %number% 00051 %$$ 00052 It must be greater than zero and specifies the maximum number of 00053 OpenMp threads that will be active at one time. 00054 00055 00056 $head Independent$$ 00057 Each call to $cref/Independent(x)/Independent/$$ 00058 creates a new $cref/active/glossary/Tape/Active/$$ tape. 00059 All of the operations with the corresponding variables 00060 must be preformed by the same OpenMP thread. 00061 This includes the corresponding call to 00062 $cref/f.Dependent(x,y)/Dependent/$$ or the 00063 $cref/ADFun f(x, y)/FunConstruct/Sequence Constructor/$$ 00064 during which the tape stops recording and the variables 00065 become parameters. 00066 00067 $head Restriction$$ 00068 No tapes can be 00069 $cref/active/glossary/Tape/Active/$$ when this function is called. 00070 00071 $end 00072 ----------------------------------------------------------------------------- 00073 */ 00074 00075 // BEGIN CppAD namespace 00076 namespace CppAD { 00077 00078 template <class Base> 00079 void AD<Base>::omp_max_thread(size_t number) 00080 { 00081 # ifdef _OPENMP 00082 thread_alloc::parallel_setup( 00083 number, omp_alloc::in_parallel, omp_alloc::get_thread_num 00084 ); 00085 # else 00086 CPPAD_ASSERT_KNOWN( 00087 number == 1, 00088 "omp_max_thread: number > 1 and _OPENMP is not defined" 00089 ); 00090 # endif 00091 parallel_ad<Base>(); 00092 } 00093 00094 } // END CppAD namespace 00095 00096 # endif