コード例 #1
0
void * thread_trace(thr_parms * parms)
{
//// TBB allows user to specify a number of threads to be created in TBB thread pool.
//// This example expects user to specify number of threads through setting an environment
//// variable "TACHYON_NUM_THREADS", TBB creates a thread pool with the number of threads
//// equal to number of logical processors on the machine where application is running
//todo: uncomment following lines  in TBB implementation
/*
    int n, nthreads = tbb::task_scheduler_init::automatic;
    char *nthreads_str = getenv ("TACHYON_NUM_THREADS");
    if (nthreads_str && (sscanf (nthreads_str, "%d", &n) > 0) && (n > 0)) nthreads = n;
    tbb::task_scheduler_init init (nthreads);
*/
    // shared but read-only so could be private too
    all_parms = parms;
    scene = parms->scene;
    startx = parms->startx;
    stopx = parms->stopx;
    starty = parms->starty;
    stopy = parms->stopy;
    jitterscale = 40.0*(scene.hres + scene.vres);
    totaly = parms->scene.vres-1;

//// Although TBB provides an auto_partitioner - mechanism that controls iteration space partitioning
//// in order to obtain optimal granularity of parallelism, it is possible to specify grainsize manually
//// In this example it's done through setting an environment variable "TACHYON_GRAINSIZE"
//todo: uncomment following lines  in TBB implementation
/*
    int g, grain_size = 50;
    char *grain_str = getenv ("TACHYON_GRAINSIZE"); 
    if (grain_str && (sscanf (grain_str, "%d", &g) > 0) && (g > 0)) grain_size = g;
*/
//// A call to a serial function "draw_task" is substituted with a call to TBB's parallel algorithm
//// parallel_for, which partitions the iteration space into sub-spaces and evaluates the function
//// object over sub-spaces on different threads in parallel.
//// Note that no grainsize is provided to the blocked_range object. To take a manually set grainsize
//// into account please add a third argument to the tbb::blocked_range<int> constructor
//// to specify the grainsize - tbb::blocked_range<int>(starty, stopy, grain_size)
//todo: uncomment following line  in TBB implementation

//    tbb::parallel_for (tbb::blocked_range<int> (starty, stopy), draw_task (), tbb::auto_partitioner() );

 //todo: Comment out following line  in TBB implementation
  draw_task ();

    return(NULL);  
}
コード例 #2
0
ファイル: analyze_locks.cpp プロジェクト: jimmykaho/parallel
static void parallel_thread (void) {
    tbb::parallel_for (tbb::blocked_range <int> (starty, stopy), draw_task(), tbb::auto_partitioner());
}