<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Using CppAD in a Multi-Threading Environment</title>
<meta name="description" id="description" content="Using CppAD in a Multi-Threading Environment"/>
<meta name="keywords" id="keywords" content=" parallel mode execution multi-threading maximum number of threads Cppad_max_num_threads "/>
<style type='text/css'>
body { color : black }
body { background-color : white }
A:link { color : blue }
A:visited { color : purple }
A:active { color : purple }
</style>
<script type='text/javascript' language='JavaScript' src='_multi_thread_xml.js'>
</script>
</head>
<body>
<table><tr>
<td>
<a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a>
</td>
<td><a href="optimize.cpp.xml" target="_top">Prev</a>
</td><td><a href="parallel_ad.xml" target="_top">Next</a>
</td><td>
<select onchange='choose_across0(this)'>
<option>Index-&gt;</option>
<option>contents</option>
<option>reference</option>
<option>index</option>
<option>search</option>
<option>external</option>
</select>
</td>
<td>
<select onchange='choose_up0(this)'>
<option>Up-&gt;</option>
<option>CppAD</option>
<option>multi_thread</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>CppAD-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>multi_thread</option>
<option>library</option>
<option>cppad_ipopt_nlp</option>
<option>Example</option>
<option>preprocessor</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>multi_thread-&gt;</option>
<option>parallel_ad</option>
<option>thread_test.cpp</option>
</select>
</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Purpose</option>
<option>CPPAD_MAX_NUM_THREADS</option>
<option>parallel_setup</option>
<option>hold_memory</option>
<option>Parallel AD</option>
<option>Initialization</option>
<option>Same Thread</option>
<option>Parallel Prohibited</option>
<option>Contents</option>
</select>
</td>
</tr></table><br/>



<center><b><big><big>Using CppAD in a Multi-Threading Environment</big></big></b></center>
<br/>
<b><big><a name="Purpose" id="Purpose">Purpose</a></big></b>
<br/>
Extra steps and care must be taken to use CppAD 
in <a href="ta_in_parallel.xml" target="_top"><span style='white-space: nowrap'>parallel</span></a>
 execution mode. 
This section collects this information in one place.

<br/>
<br/>
<b><big><a name="CPPAD_MAX_NUM_THREADS" id="CPPAD_MAX_NUM_THREADS">CPPAD_MAX_NUM_THREADS</a></big></b>



<br/>
If the preprocessor symbol <code><font color="blue">CPPAD_MAX_NUM_THREADS</font></code> is defined
before including any CppAD header files,
it must be an integer greater than or equal to 4 and it
specifies an absolute maximum for 
the number of threads that CppAD should support.
Otherwise, CppAD may, or may not, define this preprocessor symbol
and impose an unspecified absolute maximum of its own.
Currently, CppAD sets this maximum to 48 and this maximum is only expected
to increase if it does change.
In the future, the need for this maximum may be eliminated.

<br/>
<br/>
<b><big><a name="parallel_setup" id="parallel_setup">parallel_setup</a></big></b>
<br/>
Using any of the following routines in a multi-threading environment
requires that <a href="ta_parallel_setup.xml" target="_top"><span style='white-space: nowrap'>thread_alloc::parallel_setup</span></a>
 
has been completed:
<a href="cppad_vector.xml#Memory and Parallel Mode" target="_top"><span style='white-space: nowrap'>CppAD::vector</span></a>
,
<a href="checksimplevector.xml#Parallel Mode" target="_top"><span style='white-space: nowrap'>CheckSimpleVector</span></a>
,
<a href="checknumerictype.xml#Parallel Mode" target="_top"><span style='white-space: nowrap'>CheckNumericType</span></a>
,
<a href="parallel_ad.xml" target="_top"><span style='white-space: nowrap'>parallel_ad</span></a>
.

<br/>
<br/>
<b><big><a name="hold_memory" id="hold_memory">hold_memory</a></big></b>
<br/>
Memory allocation should be much faster after calling
<code><font color="blue">hold_memory</font></code> with
<a href="ta_hold_memory.xml#value" target="_top"><span style='white-space: nowrap'>value</span></a>
 equal to true. 
This may even be true if there is only one thread.

<br/>
<br/>
<b><big><a name="Parallel AD" id="Parallel AD">Parallel AD</a></big></b>
<br/>
One must first call
<a href="ta_parallel_setup.xml" target="_top"><span style='white-space: nowrap'>thread_alloc::parallel_setup</span></a>
 
and then call <a href="parallel_ad.xml" target="_top"><span style='white-space: nowrap'>parallel_ad</span></a>
 before using <code><font color="blue">AD</font></code> types
in <a href="ta_in_parallel.xml" target="_top"><span style='white-space: nowrap'>parallel</span></a>
 execution mode.

<br/>
<br/>
<b><big><a name="Initialization" id="Initialization">Initialization</a></big></b>
<br/>
The following routines must be called at least once before being used
in parallel mode:
<a href="checksimplevector.xml#Parallel Mode" target="_top"><span style='white-space: nowrap'>CheckSimpleVector</span></a>
,
<a href="checknumerictype.xml#Parallel Mode" target="_top"><span style='white-space: nowrap'>CheckNumericType</span></a>
,
<a href="discrete.xml#Parallel Mode" target="_top"><span style='white-space: nowrap'>discrete&#xA0;functions</span></a>
,
<a href="nan.xml#Parallel Mode" target="_top"><span style='white-space: nowrap'>nan</span></a>
,
<a href="rosen34.xml#Parallel Mode" target="_top"><span style='white-space: nowrap'>Rosen34</span></a>
,
<a href="runge45.xml#Parallel Mode" target="_top"><span style='white-space: nowrap'>Runge45</span></a>
.

<br/>
<br/>
<b><big><a name="Same Thread" id="Same Thread">Same Thread</a></big></b>
<br/>
Some operations must be preformed by the same thread:
<a href="funconstruct.xml#Parallel Mode" target="_top"><span style='white-space: nowrap'>ADFun</span></a>
,
<a href="independent.xml" target="_top"><span style='white-space: nowrap'>Independent</span></a>
, <a href="dependent.xml" target="_top"><span style='white-space: nowrap'>Dependent</span></a>
.


<br/>
<br/>
<b><big><a name="Parallel Prohibited" id="Parallel Prohibited">Parallel Prohibited</a></big></b>
<br/>
The following routine cannot be called in parallel mode:
<a href="errorhandler.xml#Constructor.Parallel Mode" target="_top"><span style='white-space: nowrap'>ErrorHandler&#xA0;constructor</span></a>
.

<br/>
<br/>
<b><big><a name="Contents" id="Contents">Contents</a></big></b>
<br/>
<table>
<tr><td><a href="parallel_ad.xml" target="_top">parallel_ad</a></td><td>Enable&#xA0;AD&#xA0;Calculations&#xA0;During&#xA0;Parallel&#xA0;Mode</td></tr><tr><td><a href="thread_test.cpp.xml" target="_top">thread_test.cpp</a></td><td>Run&#xA0;Multi-Threading&#xA0;Examples&#xA0;and&#xA0;Speed&#xA0;Tests</td></tr></table>
<hr/>Input File: omh/multi_thread.omh

</body>
</html>

