Shadowrun: Awakened 29 September 2011 - Build 871
Classes | Functions | Variables
main.cpp File Reference
#include "common.h"
#include "tbb/tick_count.h"
#include "tbb/task.h"
#include "tbb/task_scheduler_init.h"
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include "tbb/scalable_allocator.h"
Include dependency graph for Third Party Tech/TBB/tbb30_20100406oss_win/tbb30_20100406oss/examples/task/tree_sum/main.cpp:

Go to the source code of this file.

Classes

class  TreeMaker< use_tbbmalloc >
class  TreeMaker< use_tbbmalloc >::SubTreeCreationTask

Functions

int main (int argc, char *argv[])

Variables

static double Pi = 3.14159265358979
const bool stdmalloc = false
const bool tbbmalloc = true

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 141 of file Third Party Tech/TBB/tbb30_20100406oss_win/tbb30_20100406oss/examples/task/tree_sum/main.cpp.

References tbb::task_scheduler_init::automatic, tbb::tick_count::now(), OptimizedParallelSumTree(), SerialSumTree(), and SimpleParallelSumTree().

                                   {
    // Parse command line parameters
    // The format is: <exe_name> [-stdmalloc] [num_of_nodes [num_of_threads]]
    bool use_tbbmalloc = true;
    int arg_idx = 1;
    if( argc>1 && strcmp(argv[1], "-stdmalloc")==0 ) {
        use_tbbmalloc = false;
        arg_idx = 2;
    }
    long number_of_nodes = argc>arg_idx ? strtol(argv[arg_idx],0,0) : 10000000;
    ++arg_idx;
    int nthread = argc>arg_idx ? strtol(argv[arg_idx],0,0) : tbb::task_scheduler_init::automatic;

    // Start up scheduler
    // For production, no argument should be provided to the constructor, so that
    // the application gets the number of threads that are physically available.
    tbb::task_scheduler_init init(nthread);

    TreeNode* root;
    if( use_tbbmalloc ) {
        printf("Tree creation using TBB scalable allocator\n");
        root = TreeMaker<tbbmalloc>::create_and_time( number_of_nodes );
    } else {
        printf("Tree creation using standard operator new\n");
        root = TreeMaker<stdmalloc>::create_and_time( number_of_nodes );
    }

    // Warm up caches
    SerialSumTree(root);
    printf("Calculations:\n");
    const char* which;
    for( int i=0; i<3; ++i ) {
        tbb::tick_count t0 = tbb::tick_count::now();
        Value result;
        switch( i ) {
            case 0: 
                which = "SerialSumTree";
                result = SerialSumTree(root); 
                break;
            case 1: 
                which = "SimpleParallelSumTree";
                result = SimpleParallelSumTree(root); 
                break;
            case 2: 
                which = "OptimizedParallelSumTree";
                result = OptimizedParallelSumTree(root); 
                break;
        }
        tbb::tick_count t1 = tbb::tick_count::now();
        printf ("%24s: time = %.1f msec, sum=%g\n", which, (t1-t0).seconds()*1000, result);
    }
    return 0;
}

Variable Documentation

double Pi = 3.14159265358979 [static]
const bool stdmalloc = false
const bool tbbmalloc = true

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net