/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/omp_max_thread.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_OMP_MAX_THREAD_INCLUDED
00002 # define CPPAD_OMP_MAX_THREAD_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     Common Public License Version 1.0.
00010 
00011 A copy of this license is included in the COPYING file of this distribution.
00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00013 -------------------------------------------------------------------------- */
00014 /*
00015 $begin omp_max_thread$$
00016 $spell
00017         omp
00018         OpenMp
00019         CppAD
00020 $$
00021 
00022 $section OpenMP Maximum Thread Number$$
00023 
00024 $index omp_max_thread$$
00025 $index thread, multiple$$
00026 $index multiple, thread$$
00027 $index OpenMP, CppAD$$
00028 $index CppAD, OpenMP$$
00029 
00030 $head Syntax$$
00031 $syntax%AD<%Base%>::omp_max_thread(%number%)
00032 %$$
00033 
00034 $head Purpose$$
00035 By default, for each $syntax%AD<%Base%>%$$ class there is only one 
00036 tape that records $cref/AD of Base/glossary/AD of Base/$$ operations.
00037 This tape is a global variable and hence it cannot be used
00038 by multiple OpenMP threads at the same time. 
00039 The $code omp_max_thread$$ function is used to set the 
00040 maximum number of OpenMP threads that can be active.
00041 In this case, there is a different tape corresponding to each 
00042 $syntax%AD<%Base%>%$$ class and thread pair. 
00043 
00044 $head number$$
00045 The argument $italic number$$ has prototype
00046 $syntax%
00047         size_t %number%
00048 %$$
00049 It must be greater than zero and specifies the maximum number of
00050 OpenMp threads that will be active at one time.
00051 
00052 
00053 $head Independent$$
00054 Each call to $cref/Independent(x)/Independent/$$ 
00055 creates a new $cref/active/glossary/Tape/Active/$$ tape.
00056 All of the operations with the corresponding variables 
00057 must be preformed by the same OpenMP thread.
00058 This includes the corresponding call to 
00059 $cref/f.Dependent(x,y)/Dependent/$$ or the 
00060 $cref/ADFun f(x, y)/FunConstruct/Sequence Constructor/$$
00061 during which the tape stops recording and the variables
00062 become parameters.
00063 
00064 $head Restriction$$
00065 No tapes can be 
00066 $cref/active/glossary/Tape/Active/$$ when this function is called.
00067 
00068 $head Example and Tests$$
00069 $children%
00070         openmp/run.sh
00071 %$$
00072 The shell script $cref/openmp_run.sh/$$ can be used to 
00073 compile and run the OpenMP examples and tests.
00074 
00075 $end
00076 -----------------------------------------------------------------------------
00077 */
00078 
00079 // BEGIN CppAD namespace
00080 namespace CppAD {
00081 
00082 template <class Base>
00083 size_t AD<Base>::omp_max_thread(size_t number)
00084 {       static size_t max_thread = 1;
00085 
00086         // number equal zero case is not part of user interface
00087         if( number > 0 )
00088         {
00089 # ifndef NDEBUG
00090                 CPPAD_ASSERT_KNOWN(
00091                         number <= CPPAD_MAX_NUM_THREADS,
00092                         "omp_max_thread argument is too large."
00093                 );
00094 # endif
00095 
00096                 max_thread = number;
00097         }
00098 
00099         // the return value is not part of the user interface
00100         return max_thread;
00101 }
00102 
00103 } // END CppAD namespace
00104 
00105 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7