![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
#include "tbb/parallel_do.h"#include "tbb/atomic.h"#include <vector>#include <algorithm>#include <cstring>#include <cstdio>#include "Graph.h"#include <cctype>#include "tbb/task_scheduler_init.h"#include "tbb/tick_count.h"
Include dependency graph for parallel_preorder.cpp:Go to the source code of this file.
Classes | |
| class | Body |
| struct | IntRange |
| A closed range of int. | |
Functions | |
| int | main (int argc, char *argv[]) |
| void | ParallelPreorderTraversal (const vector< Cell * > &root_set) |
| static void | ParseCommandLine (int argc, char *argv[]) |
| Parse the command line. | |
| void | Usage (char *argv0) |
| Displays usage message. | |
Variables | |
| static IntRange | NThread (1, 4) |
| Number of threads to use. | |
| int | ntrial = 50 |
| Number of trials. Can be changed from command line. | |
| static bool | PauseFlag = false |
| If true, then at end wait for user to hit return. | |
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 143 of file parallel_preorder.cpp.
References Graph::create_random_dag(), g, Graph::get_root_set(), IntRange::high, IntRange::low, tbb::tick_count::now(), NThread, ntrial, ParallelPreorderTraversal(), ParseCommandLine(), PauseFlag, tbb::tick_count::interval_t::seconds(), and t0.
{
ParseCommandLine(argc,argv);
// Start scheduler with given number of threads.
for( int p=NThread.low; p<=NThread.high; ++p ) {
tbb::task_scheduler_init init(p);
srand(2);
tbb::tick_count::interval_t interval;
size_t total_root_set_size = 0;
for( int trial=0; trial<ntrial; ++trial ) {
Graph g;
g.create_random_dag(1000);
vector<Cell*> root_set;
g.get_root_set(root_set);
total_root_set_size += root_set.size();
tbb::tick_count t0 = tbb::tick_count::now();
for( int i=0; i<10; ++i ) {
ParallelPreorderTraversal(root_set);
}
tbb::tick_count t1 = tbb::tick_count::now();
interval += t1-t0;
}
printf("%g seconds using %d threads (average of %g nodes in root_set)\n",interval.seconds(),p,(double)total_root_set_size/ntrial);
}
if (PauseFlag) {
printf ("Press return key to exit");
char c;
int n = scanf("%c", &c);
if( n!=1 ) {
fprintf(stderr,"Fatal error: unexpected end of input\n");
exit(1);
}
}
return 0;
}
| void ParallelPreorderTraversal | ( | const vector< Cell * > & | root_set | ) |
Definition at line 67 of file parallel_preorder.cpp.
References tbb::parallel_do().
Referenced by main().
{
tbb::parallel_do(root_set.begin(), root_set.end(),Body());
}
| static void ParseCommandLine | ( | int | argc, |
| char * | argv[] | ||
| ) | [static] |
Definition at line 116 of file parallel_preorder.cpp.
References NThread, ntrial, PauseFlag, IntRange::set_from_string(), and Usage().
{
int i = 1;
if( i<argc && !isdigit(argv[i][0]) ) {
// Command line is garbled.
Usage(argv[0]);
exit(1);
}
if( i<argc )
NThread.set_from_string(argv[i++]);
if( i<argc && !isdigit(argv[i][0]) ) {
// Command line is garbled.
Usage(argv[0]);
exit(1);
}
if (i<argc) {
ntrial = strtol(argv[i++], 0, 0);
}
if (ntrial == 0) {
// Command line is garbled.
Usage(argv[0]);
exit(1);
}
if (i<argc && strcmp( argv[i], "pause" )==0 ) {
PauseFlag = true;
}
}
| void Usage | ( | char * | argv0 | ) |
Definition at line 108 of file parallel_preorder.cpp.
References IntRange::high, IntRange::low, and NThread.
Referenced by ParseCmdLine(), ParseCommandLine(), and run_pipeline().
{
fprintf(stderr, "Usage: %s [nthread [ntrials ['pause']]]\n", argv0);
fprintf(stderr, "where nthread is a non-negative integer, or range of the form low:high [%d:%d]\n", NThread.low, NThread.high);
fprintf(stderr, "ntrials is a positive integer. Default value is 50, reduce it (e.g. to 5) to shorten example run time\n");
fprintf(stderr, "The application waits for user to hit return if 'pause' is specified\n");
}
Referenced by main(), ParseCommandLine(), and Usage().
| int ntrial = 50 |
Definition at line 43 of file parallel_preorder.cpp.
Referenced by main(), and ParseCommandLine().
Definition at line 105 of file parallel_preorder.cpp.
Referenced by main(), and ParseCommandLine().
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.