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

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

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

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Run Multi-Threading Examples and Speed Tests</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="Run Multi-Threading Examples and Speed Tests"/>
<meta name="keywords" id="keywords" content=" thread_test example speed thread multi run multi-threading examples and tests syntax running threading openmp pthread bthread purpose a11c simple_ad team_example harmonic test_time max_threads mega_sum multi_newton num_zero num_sub num_sum use_ad team implementations 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='_thread_test.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="parallel_ad.xml" target="_top">Prev</a>
</td><td><a href="a11c_openmp.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>
</select>
</td>
<td>
<select onchange='choose_down2(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_down1(this)'>
<option>multi_thread-&gt;</option>
<option>parallel_ad</option>
<option>thread_test.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down0(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_current0(this)'>
<option>Headings-&gt;</option>
<option>Syntax</option>
<option>Running Tests</option>
<option>---..threading</option>
<option>Purpose</option>
<option>a11c</option>
<option>simple_ad</option>
<option>team_example</option>
<option>harmonic</option>
<option>---..test_time</option>
<option>---..max_threads</option>
<option>---..mega_sum</option>
<option>multi_newton</option>
<option>---..test_time</option>
<option>---..max_threads</option>
<option>---..num_zero</option>
<option>---..num_sub</option>
<option>---..num_sum</option>
<option>---..use_ad</option>
<option>Team Implementations</option>
<option>Source</option>
</select>
</td>
</tr></table><br/>










<center><b><big><big>Run Multi-Threading Examples and Speed Tests</big></big></b></center>
<br/>
<b><big><a name="Syntax" id="Syntax">Syntax</a></big></b>

<br/>

<code><font color="blue"><span style='white-space: nowrap'>./multi_thread_</span></font><i><font color="black"><span style='white-space: nowrap'>threading</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;a11c<br/>
./multi_thread_</span></font><i><font color="black"><span style='white-space: nowrap'>threading</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;simple_ad<br/>
./multi_thread_</span></font><i><font color="black"><span style='white-space: nowrap'>threading</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;team_example<br/>
./multi_thread_</span></font><i><font color="black"><span style='white-space: nowrap'>threading</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;harmonic&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>test_time</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>max_threads</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>mega_sum</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
./multi_thread_</span></font><i><font color="black"><span style='white-space: nowrap'>threading</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;multi_newton&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>test_time</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>max_threads</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;\<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>num_zero</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>num_sub</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'>use_ad</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
<br/>
<b><big><a name="Running Tests" id="Running Tests">Running Tests</a></big></b>
<br/>
You can build this program and run the default version of its test
parameters by executing the following commands:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;cd&#xA0;multi_thread<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;make&#xA0;test<br/>
</span></font></code>
After this operation you can run the syntax above
for the different valid values of 
<code><i><font color="black"><span style='white-space: nowrap'>threading</span></font></i></code>
:

<br/>
<br/>
<b><a name="Running Tests.threading" id="Running Tests.threading">threading</a></b>



<br/>
If the <a href="cmake.xml" target="_top"><span style='white-space: nowrap'>cmake</span></a>
 command output indicates that 
<code><font color="blue">openmp</font></code> is supported by your system,
you can execute the syntax above with

<code><i><font color="black"><span style='white-space: nowrap'>threading</span></font></i></code>
 equal to <code><font color="blue">openmp</font></code>.
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>If the <a href="cmake.xml" target="_top"><span style='white-space: nowrap'>cmake</span></a>
 command output indicates that 
<code><font color="blue">pthreads</font></code> with barriers is supported by your system,
you can execute the syntax above with

<code><i><font color="black"><span style='white-space: nowrap'>threading</span></font></i></code>
 equal to <code><font color="blue">pthread</font></code>.
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>If the <a href="cmake.xml" target="_top"><span style='white-space: nowrap'>cmake</span></a>
 command output indicates that 
<code><font color="blue">boost</font></code> threads is supported is by your system,
you can execute the syntax above with

<code><i><font color="black"><span style='white-space: nowrap'>threading</span></font></i></code>
 equal to <code><font color="blue">bthread</font></code>.


<br/>
<br/>
<b><big><a name="Purpose" id="Purpose">Purpose</a></big></b>
<br/>
Runs the CppAD multi-threading examples and timing tests:



<br/>
<br/>
<b><big><a name="a11c" id="a11c">a11c</a></big></b>
<br/>
The examples 
<a href="a11c_openmp.cpp.xml" target="_top"><span style='white-space: nowrap'>a11c_openmp.cpp</span></a>
,
<a href="a11c_bthread.cpp.xml" target="_top"><span style='white-space: nowrap'>a11c_bthread.cpp</span></a>
, and
<a href="a11c_pthread.cpp.xml" target="_top"><span style='white-space: nowrap'>a11c_pthread.cpp</span></a>

demonstrate simple multi-threading, 
without algorithmic differentiation.

<br/>
<br/>
<b><big><a name="simple_ad" id="simple_ad">simple_ad</a></big></b>
<br/>
The examples 
<a href="simple_ad_openmp.cpp.xml" target="_top"><span style='white-space: nowrap'>simple_ad_openmp.cpp</span></a>
,
<a href="simple_ad_bthread.cpp.xml" target="_top"><span style='white-space: nowrap'>simple_ad_bthread.cpp</span></a>
,
and
<a href="simple_ad_pthread.cpp.xml" target="_top"><span style='white-space: nowrap'>simple_ad_pthread.cpp</span></a>

demonstrate simple multi-threading, 
with algorithmic differentiation, using
OpenMP, boost threads and pthreads respectively.

<br/>
<br/>
<b><big><a name="team_example" id="team_example">team_example</a></big></b>
<br/>
The <a href="team_example.cpp.xml" target="_top"><span style='white-space: nowrap'>team_example.cpp</span></a>
 routine
demonstrates simple multi-threading with algorithmic differentiation
and using a <a href="team_thread.hpp.xml" target="_top"><span style='white-space: nowrap'>team&#xA0;of&#xA0;threads</span></a>
. 

<br/>
<br/>
<b><big><a name="harmonic" id="harmonic">harmonic</a></big></b>
<br/>
The <a href="harmonic_time.cpp.xml" target="_top"><span style='white-space: nowrap'>harmonic_time.cpp</span></a>
 routine
preforms a timing test for a multi-threading 
example without algorithmic differentiation using a team of threads.

<br/>
<br/>
<b><a name="harmonic.test_time" id="harmonic.test_time">test_time</a></b>
<br/>
Is the minimum amount of wall clock time that the test should take.
The number of repeats for the test will be increased until this time
is reached. 
The reported time is the total wall clock time divided by the
number of repeats.

<br/>
<br/>
<b><a name="harmonic.max_threads" id="harmonic.max_threads">max_threads</a></b>
<br/>
If the argument 
<code><i><font color="black"><span style='white-space: nowrap'>max_threads</span></font></i></code>
 is a non-negative integer specifying
the maximum number of threads to use for the test.
The specified test is run with the following number of threads:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#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'>&#xA0;=&#xA0;0&#xA0;,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>...</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>max_threads</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
The value of zero corresponds to not using the multi-threading system.

<br/>
<br/>
<b><a name="harmonic.mega_sum" id="harmonic.mega_sum">mega_sum</a></b>
<br/>
The command line argument 
<code><i><font color="black"><span style='white-space: nowrap'>mega_sum</span></font></i></code>
 
is an integer greater than or equal one and has the same meaning as in
<a href="harmonic_time.cpp.xml#mega_sum" target="_top"><span style='white-space: nowrap'>harmonic_time.cpp</span></a>
.

<br/>
<br/>
<b><big><a name="multi_newton" id="multi_newton">multi_newton</a></big></b>
<br/>
The <a href="multi_newton_time.cpp.xml" target="_top"><span style='white-space: nowrap'>multi_newton_time.cpp</span></a>
 routine
preforms a timing test for a multi-threading 
example with algorithmic differentiation using a team of threads.

<br/>
<br/>
<b><a name="multi_newton.test_time" id="multi_newton.test_time">test_time</a></b>
<br/>
Is the minimum amount of wall clock time that the test should take.
The number of repeats for the test will be increased until this time
is reached. 
The reported time is the total wall clock time divided by the
number of repeats.

<br/>
<br/>
<b><a name="multi_newton.max_threads" id="multi_newton.max_threads">max_threads</a></b>
<br/>
If the argument 
<code><i><font color="black"><span style='white-space: nowrap'>max_threads</span></font></i></code>
 is a non-negative integer specifying
the maximum number of threads to use for the test.
The specified test is run with the following number of threads:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#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'>&#xA0;=&#xA0;0&#xA0;,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>...</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>max_threads</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
The value of zero corresponds to not using the multi-threading system.

<br/>
<br/>
<b><a name="multi_newton.num_zero" id="multi_newton.num_zero">num_zero</a></b>
<br/>
The command line argument 
<code><i><font color="black"><span style='white-space: nowrap'>num_zero</span></font></i></code>
 
is an integer greater than or equal two and has the same meaning as in
<a href="multi_newton_time.cpp.xml#num_zero" target="_top"><span style='white-space: nowrap'>multi_newton_time.cpp</span></a>
.

<br/>
<br/>
<b><a name="multi_newton.num_sub" id="multi_newton.num_sub">num_sub</a></b>
<br/>
The command line argument 
<code><i><font color="black"><span style='white-space: nowrap'>num_sub</span></font></i></code>
 
is an integer greater than or equal one and has the same meaning as in
<a href="multi_newton_time.cpp.xml#num_sub" target="_top"><span style='white-space: nowrap'>multi_newton_time.cpp</span></a>
.

<br/>
<br/>
<b><a name="multi_newton.num_sum" id="multi_newton.num_sum">num_sum</a></b>
<br/>
The command line argument 
<code><i><font color="black"><span style='white-space: nowrap'>num_sum</span></font></i></code>
 
is an integer greater than or equal one and has the same meaning as in
<a href="multi_newton_time.cpp.xml#num_sum" target="_top"><span style='white-space: nowrap'>multi_newton_time.cpp</span></a>
.

<br/>
<br/>
<b><a name="multi_newton.use_ad" id="multi_newton.use_ad">use_ad</a></b>
<br/>
The command line argument 
<code><i><font color="black"><span style='white-space: nowrap'>use_ad</span></font></i></code>
 is either 
<code><font color="blue">true</font></code> or <code><font color="blue">false</font></code> and has the same meaning as in
<a href="multi_newton_time.cpp.xml#use_ad" target="_top"><span style='white-space: nowrap'>multi_newton_time.cpp</span></a>
.

<br/>
<br/>
<b><big><a name="Team Implementations" id="Team Implementations">Team Implementations</a></big></b>
<br/>
The following routines are used to implement the specific threading
systems through the common interface <a href="team_thread.hpp.xml" target="_top"><span style='white-space: nowrap'>team_thread.hpp</span></a>
:
<table><tr><td align='left'  valign='top'>

<a href="team_openmp.cpp.xml" target="_top">team_openmp.cpp</a></td><td>
OpenMP Implementation of a Team of AD Threads</td></tr>
<tr><td>

<a href="team_bthread.cpp.xml" target="_top">team_bthread.cpp</a></td><td>
Boost Thread Implementation of a Team of AD Threads</td></tr>
<tr><td>

<a href="team_pthread.cpp.xml" target="_top">team_pthread.cpp</a></td><td>
Pthread Implementation of a Team of AD Threads</td></tr>
<tr><td>

</td></tr>
</table>
<br/>
<b><big><a name="Source" id="Source">Source</a></big></b>

<code><font color="blue">
<br/>
<pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;
# include &lt;cmath&gt;
# include &lt;cstring&gt;
# include &lt;ctime&gt;
# include &quot;team_thread.hpp&quot;
# include &quot;team_example.hpp&quot;
# include &quot;harmonic_time.hpp&quot;
# include &quot;multi_newton_time.hpp&quot;

extern bool a11c(void);
extern bool simple_ad(void);

namespace {
	size_t arg2size_t(
		const char* arg       , 
		int limit             , 
		const char* error_msg )
	{	int i = std::atoi(arg);
		if( i &gt;= limit )
			return size_t(i);
		std::cerr &lt;&lt; &quot;value = &quot; &lt;&lt; i &lt;&lt; std::endl;
		std::cerr &lt;&lt; error_msg &lt;&lt; std::endl;
		exit(1);
	}
	double arg2double(
		const char* arg       , 
		double limit          , 
		const char* error_msg )
	{	double d = std::atof(arg);
		if( d &gt;= limit )
			return d;
		std::cerr &lt;&lt; &quot;value = &quot; &lt;&lt; d &lt;&lt; std::endl;
		std::cerr &lt;&lt; error_msg &lt;&lt; std::endl;
		exit(1);
	}
}

int main(int argc, char *argv[])
{	using CppAD::thread_alloc;
	bool ok         = true;
	using std::cout;
	using std::endl;

	// commnd line usage message
	const char* usage = 
	&quot;./&lt;thread&gt;_test a11c\n&quot;
	&quot;./&lt;thread&gt;_test simple_ad\n&quot;
	&quot;./&lt;thread&gt;_test team_example\n&quot;
	&quot;./&lt;thread&gt;_test harmonic    test_time max_threads mega_sum\n&quot;
	&quot;./&lt;thread&gt;_test multi_newton test_time max_threads\\\n&quot;
	&quot;	num_zero num_sub num_sum use_ad\\\n&quot;
	&quot;where &lt;thread&gt; is bthread, openmp, or pthread&quot;;

	// command line argument values (assign values to avoid compiler warnings)
	size_t num_zero=0, num_sub=0, num_sum=0;
	bool use_ad=true;

	// put the date and time in the output file
	std::time_t rawtime;
	std::time( &amp;rawtime );
	const char* gmt = std::asctime( std::gmtime( &amp;rawtime ) );
	size_t len = size_t( std::strlen(gmt) );
	cout &lt;&lt; &quot;gmtime        = '&quot;;
	for(size_t i = 0; i &lt; len; i++) 
		if( gmt[i] != '\n' ) cout &lt;&lt; gmt[i];
	cout &lt;&lt; &quot;';&quot; &lt;&lt; endl;

	// CppAD version number
	cout &lt;&lt; &quot;cppad_version = '&quot; &lt;&lt; CPPAD_PACKAGE_STRING &lt;&lt; &quot;';&quot; &lt;&lt; endl; 

	// put the team name in the output file
	cout &lt;&lt; &quot;team_name     = '&quot; &lt;&lt; team_name() &lt;&lt; &quot;';&quot; &lt;&lt; endl;

	// print command line as valid matlab/octave
	cout &lt;&lt; &quot;command       = '&quot; &lt;&lt; argv[0];
	for(int i = 1; i &lt; argc; i++)
		cout &lt;&lt; &quot; &quot; &lt;&lt; argv[i];
	cout &lt;&lt; &quot;';&quot; &lt;&lt; endl;

	ok = false;
	const char* test_name = &quot;&quot;;
	if( argc &gt; 1 )
		test_name = *++argv;
	bool run_a11c         = std::strcmp(test_name, &quot;a11c&quot;)         == 0;
	bool run_simple_ad    = std::strcmp(test_name, &quot;simple_ad&quot;)    == 0;
	bool run_team_example = std::strcmp(test_name, &quot;team_example&quot;) == 0;
	bool run_harmonic     = std::strcmp(test_name, &quot;harmonic&quot;)     == 0;
	bool run_multi_newton = std::strcmp(test_name, &quot;multi_newton&quot;) == 0;
	if( run_a11c || run_simple_ad || run_team_example )
		ok = (argc == 2);
	else if( run_harmonic )
		ok = (argc == 5);  
	else if( run_multi_newton )
		ok = (argc == 8);
	if( ! ok )
	{	std::cerr &lt;&lt; &quot;test_name     = &quot; &lt;&lt; test_name &lt;&lt; endl;	
		std::cerr &lt;&lt; &quot;argc          = &quot; &lt;&lt; argc      &lt;&lt; endl;	
		std::cerr &lt;&lt; usage &lt;&lt; endl;
		exit(1);
	}
	if( run_a11c || run_simple_ad || run_team_example )
	{	if( run_a11c )
			ok        = a11c();
		else if( run_simple_ad )
			ok        = simple_ad();
		else	ok        = team_example();
		if( thread_alloc::free_all() )
			cout &lt;&lt; &quot;free_all      = true;&quot;  &lt;&lt; endl;
		else
		{	ok = false;
			cout &lt;&lt; &quot;free_all      = false;&quot; &lt;&lt; endl;
		}
		if( ok )
			cout &lt;&lt; &quot;OK            = true;&quot;  &lt;&lt; endl;
		else cout &lt;&lt; &quot;OK            = false;&quot; &lt;&lt; endl;
		return ! ok;
	}

	// test_time 
	double test_time = arg2double( *++argv, 0., 
		&quot;run: test_time is less than zero&quot;
	);

	// max_threads 
	size_t max_threads = arg2size_t( *++argv, 0, 
		&quot;run: max_threads is less than zero&quot;
	);

	size_t mega_sum = 0; // assignment to avoid compiler warning
	if( run_harmonic )
	{	// mega_sum
		mega_sum = arg2size_t( *++argv, 1, 
			&quot;run: mega_sum is less than one&quot;
		);
	}
	else
	{	ok &amp;= run_multi_newton;

		// num_zero
		num_zero = arg2size_t( *++argv, 2,
			&quot;run: num_zero is less than two&quot;
		);

		// num_sub
		num_sub = arg2size_t( *++argv, 1,
			&quot;run: num_sub is less than one&quot;
		);
       
		// num_sum 
		num_sum = arg2size_t( *++argv, 1,
			&quot;run: num_sum is less than one&quot;
		);

		// use_ad
		++argv;
		if( std::strcmp(*argv, &quot;true&quot;) == 0 )
			use_ad = true;
		else if( std::strcmp(*argv, &quot;false&quot;) == 0 )
			use_ad = false;
		else
		{	std::cerr &lt;&lt; &quot;run: use_ad = '&quot; &lt;&lt; *argv;
			std::cerr &lt;&lt; &quot;' is not true or false&quot; &lt;&lt; endl;
			exit(1);
		}
	}

	// run the test for each number of threads
	size_t num_threads, inuse_this_thread = 0;
	cout &lt;&lt; &quot;time_all  = [&quot; &lt;&lt; endl;
	for(num_threads = 0; num_threads &lt;= max_threads; num_threads++)
	{	double time_out;

		// set the number of threads
		if( num_threads &gt; 0 )
			ok &amp;= team_create(num_threads);

		// ammount of memory initialy inuse by thread zero
		ok &amp;= 0 == thread_alloc::thread_num();
		inuse_this_thread = thread_alloc::inuse(0);

		// run the requested test
		if( run_harmonic ) ok &amp;= 
			harmonic_time(time_out, test_time, num_threads, mega_sum);
		else
		{	ok &amp;= run_multi_newton;
			ok &amp;= multi_newton_time(
				time_out                ,
				test_time               ,
				num_threads             ,
				num_zero                ,
				num_sub                 ,
				num_sum                 ,
				use_ad
			);
		}

		// set back to one thread and fee all avaialable memory
		if( num_threads &gt; 0 )
			ok &amp;= team_destroy();
		size_t thread;
		for(thread = 0; thread &lt; num_threads; thread++)
		{	thread_alloc::free_available(thread);
			if( thread == 0 )
				ok &amp;= thread_alloc::inuse(thread) == inuse_this_thread;
			else	ok &amp;= thread_alloc::inuse(thread) == 0;
		}
		cout &lt;&lt; &quot;\t&quot; &lt;&lt; time_out &lt;&lt; &quot; % &quot;;
		if( num_threads == 0 )
			cout &lt;&lt; &quot;no threading&quot; &lt;&lt; endl;
		else	cout &lt;&lt; num_threads &lt;&lt; &quot; threads&quot; &lt;&lt; endl;
	}
	cout &lt;&lt; &quot;];&quot; &lt;&lt; endl;
	//
	if( thread_alloc::free_all() )
		cout &lt;&lt; &quot;free_all      = true;&quot;  &lt;&lt; endl;
	else
	{	ok = false;
		cout &lt;&lt; &quot;free_all      = false;&quot; &lt;&lt; endl;
	}
	if( ok )
		cout &lt;&lt; &quot;OK            = true;&quot;  &lt;&lt; endl;
	else cout &lt;&lt; &quot;OK            = false;&quot; &lt;&lt; endl;

	return  ! ok;
}

</pre>

</font></code>


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

</body>
</html>