Пример #1
0
int Fib ( int n ) {
    if( n < 2 ) {
        if ( g_sim ) {
            tbb::task_scheduler_init tsi(P_nested);
        }
        return n;
    } else {
        tbb::task_scheduler_init *tsi = NULL;
        tbb::task *cur = NULL;
        if ( g_sim ) {
            if ( n % 2 == 0 ) {
                if ( g_sim == tbbsched_auto_only || (g_sim == tbbsched_mixed && n % 4 == 0) ) {
                    // Trigger TBB scheduler auto-initialization
                    cur = &tbb::task::self();
                }
                else {
                    ASSERT ( g_sim == tbbsched_explicit_only || (g_sim == tbbsched_mixed && n % 4 != 0), NULL );
                    // Initialize TBB scheduler explicitly
                    tsi = new tbb::task_scheduler_init(P_nested);
                }
            }
        }
        int x, y;
        x = cilk_spawn Fib(n-2);
        y = cilk_spawn Fib(n-1);
        cilk_sync;
        if ( tsi )
            delete tsi;
        return x+y;
    }
}
Пример #2
0
int main()
{
    //set up one thread to eliminate scheduler overheads
    tbb::task_scheduler_init tsi(1);

    tbb::flow::graph g;

    //1. queue_node benchmark; calculate queue_node time + plus threads creation time (if we have multi-threading)
    std::cout << "queue benchmark: number of calls of putting element:" << nIter;
    const double tQueue = bm_queue_node(g, nIter);
    std::cout << ";  time:" << tQueue << std::endl << std::endl;

    //2. split_node benchmark
    std::cout << "split_node benchmark: number of calls:" << nIter;
    const double tSplitNode = bm_split_node(g, nIter);
    //output split_node benchmark result
    std::cout << ";  time:" << tSplitNode << std::endl;
    std::cout << "exclusive split_node time:" << tSplitNode - tQueue << std::endl << std::endl;

    //3. broadcast_node benchmark
    std::cout << "broadcast_node benchmark: number of calls:" << nIter;
    const double tBNode = bm_broadcast_node(g, nIter);
    //output broadcast_node benchmark result
    std::cout << ";  time:" << tBNode << std::endl;
    std::cout << "exclusive broadcast_node time:" << tBNode - tQueue << std::endl;

    return 0;
}