Codebase list cppad / upstream/2015.00.00.7 doc / harmonic.cpp.xml
upstream/2015.00.00.7

Tree @upstream/2015.00.00.7 (Download .tar.gz)

harmonic.cpp.xml @upstream/2015.00.00.7raw · history · blame

<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Multi-Threaded Implementation of Summation of 1/i</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="Multi-Threaded Implementation of Summation of 1/i"/>
<meta name="keywords" id="keywords" content=" harmonic multi_thread thread multi multi-threaded implementation of summation 1/i syntax ok sum num_sum num_threads source "/>
<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='_harmonic.cpp_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="team_example.cpp.xml" target="_top">Prev</a>
</td><td><a href="harmonic_time.cpp.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>
<option>thread_test.cpp</option>
<option>harmonic.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>CppAD-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>preprocessor</option>
<option>multi_thread</option>
<option>library</option>
<option>ipopt_solve</option>
<option>Example</option>
<option>speed</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>multi_thread-&gt;</option>
<option>parallel_ad</option>
<option>thread_test.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>thread_test.cpp-&gt;</option>
<option>a11c_openmp.cpp</option>
<option>a11c_bthread.cpp</option>
<option>a11c_pthread.cpp</option>
<option>simple_ad_openmp.cpp</option>
<option>simple_ad_bthread.cpp</option>
<option>simple_ad_pthread.cpp</option>
<option>team_example.cpp</option>
<option>harmonic.cpp</option>
<option>multi_newton.cpp</option>
<option>team_thread.hpp</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>harmonic.cpp-&gt;</option>
<option>harmonic_time.cpp</option>
<option>harmonic_work.cpp</option>
</select>
</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Syntax</option>
<option>Summation</option>
<option>ok</option>
<option>sum</option>
<option>num_sum</option>
<option>num_threads</option>
<option>Contents</option>
<option>Source</option>
</select>
</td>
</tr></table><br/>








<center><b><big><big>Multi-Threaded Implementation of Summation of 1/i</big></big></b></center>
<br/>
<b><big><a name="Syntax" id="Syntax">Syntax</a></big></b>

<br/>

<code><i><font color="black"><span style='white-space: nowrap'>ok</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;harmonic(</span></font><i><font color="black"><span style='white-space: nowrap'>sum</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>num_sum</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>num_threads</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>


<br/>
<br/>
<b><big><a name="Summation" id="Summation">Summation</a></big></b>
<br/>
Multi-threaded computation of the summation that defines the harmonic series 

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mi mathvariant='italic'>s</mi>
<mo stretchy="false">=</mo>
<mn>1</mn>
<mo stretchy="false">+</mo>
<mn>1</mn>
<mo stretchy="false">/</mo>
<mn>2</mn>
<mo stretchy="false">+</mo>
<mn>1</mn>
<mo stretchy="false">/</mo>
<mn>3</mn>
<mo stretchy="false">+</mo>
<mo stretchy="false">.</mo>
<mo stretchy="false">.</mo>
<mo stretchy="false">.</mo>
<mo stretchy="false">+</mo>
<mn>1</mn>
<mo stretchy="false">/</mo>
<mi mathvariant='italic'>n</mi>
</mrow></math>

<br/>
<b><big><a name="ok" id="ok">ok</a></big></b>
<br/>
This return value has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;bool&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>ok</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
If this return value is false, an error occurred during <code><font color="blue">harmonic</font></code>.

<br/>
<br/>
<b><big><a name="sum" id="sum">sum</a></big></b>
<br/>
This argument has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;double&amp;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>sum</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
The input value of the argument does not matter.
Upon return it is the value of the summation; i.e. 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>s</mi>
</mrow></math>

.

<br/>
<br/>
<b><big><a name="num_sum" id="num_sum">num_sum</a></big></b>
<br/>
This argument has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;size_t&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>num_sum</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
It specifies the number of terms in the summation; i.e. 
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow>
<mi mathvariant='italic'>n</mi>
</mrow></math>

.

<br/>
<br/>
<b><big><a name="num_threads" id="num_threads">num_threads</a></big></b>
<br/>
This argument has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;size_t&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>num_threads</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
It specifies the number of threads that are available for this test.
If it is zero, the test is run without a multi-threading environment.

<br/>
<br/>
<b><big><a name="Contents" id="Contents">Contents</a></big></b>
<br/>
<table>
<tr><td><a href="harmonic_time.cpp.xml" target="_top">harmonic_time.cpp</a></td><td>Timing&#xA0;Test&#xA0;of&#xA0;Multi-Threaded&#xA0;Summation&#xA0;of&#xA0;1/i</td></tr><tr><td><a href="harmonic_work.cpp.xml" target="_top">harmonic_work.cpp</a></td><td>Multi-threading&#xA0;Sum&#xA0;of&#xA0;1/i&#xA0;Utility&#xA0;Routines</td></tr></table><br/>
<b><big><a name="Source" id="Source">Source</a></big></b>

<code><font color="blue">
<br/>
<pre style='display:inline'> 
// general purpose multi-threading interface
# include &quot;team_thread.hpp&quot;
// special utilities for the harmonic problem
# include &quot;harmonic_work.hpp&quot;

bool harmonic(double&amp; sum, size_t num_sum, size_t num_threads)
{	// sum = 1/num_sum + 1/(num_sum-1) + ... + 1
	bool ok = true;

	// setup the work for num_threads_ threads
	ok &amp;= harmonic_setup(num_sum, num_threads);

	// now do the work for each thread
	if( num_threads &gt; 0 )
		team_work( harmonic_worker );
	else	harmonic_worker();

	// now combine the result for all the threads
	ok &amp;= harmonic_combine(sum);

	return ok;
}
</pre>

</font></code>


<hr/>Input File: multi_thread/harmonic.cpp

</body>
</html>