pipeline pulus parallel for

pipeline pulus parallel for

hi,

in my app, I want to parallelize it with pipeline and parallel for. Each stage characters serial(There are dependence between different items of the same stage), and in each stage, I want to process the data in parallel, now, I do it with parallel_for. But it seems does not work. 

My questions are: TBB does not support task parallelism in producer-consumer patter. So, how should I do it?

stage1 // serial

parallel_for

parallel_for

stage2 // serial

parallel_for

stage3 // serial

 

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I'm not sure I understand, but you should not have a problem calling parallel_for() from within a (parallel_)pipeline stage.

Are you saying that it works with a serial loop but not with a parallel loop, or is it something else?

Quote:

Xingjing Lu wrote:

hi,

in my app, I want to parallelize it with pipeline and parallel for. Each stage characters serial(There are dependence between different items of the same stage), and in each stage, I want to process the data in parallel, now, I do it with parallel_for. But it seems does not work. 

My questions are: TBB does not support task parallelism in producer-consumer patter. So, how should I do it?

stage1 // serial

parallel_for

parallel_for

stage2 // serial

parallel_for

stage3 // serial

 

I think you want something like:

stage1 // serial
stage 2 // parallel_for
stage 3 // parallel_for
stage 4 // serial (was stage2)
stage 5 // parallel_for
stage 6 // serial (was stage3)

Jim Dempsey

www.quickthreadprogramming.com

Quote:

Raf Schietekat wrote:

I'm not sure I understand, but you should not have a problem calling parallel_for() from within a (parallel_)pipeline stage.

Are you saying that it works with a serial loop but not with a parallel loop, or is it something else?

Yes, I made some mistakes when calling parallel_for().

But I still have another problem:

In the above example, I set the Number of threads to execute the pipeline like below:

pipeline.run(TheadNum); // ThreadNum = 3, the same number as the number of stages.

If I set up the task schedule for each parallel_for in different stages as:

task_scheduler_init init(4);

 parallel_for( blocked_range<int>(0, 4), PASSIN);

what will happened to stages and parallel_for, are there 3 threads for each stage, and another 4 threads for each parallel_for? or there are only 3 threads totally?

Thanks!

Quote:

jimdempseyatthecove wrote:

Quote:

Xingjing Lu wrote:

hi,

in my app, I want to parallelize it with pipeline and parallel for. Each stage characters serial(There are dependence between different items of the same stage), and in each stage, I want to process the data in parallel, now, I do it with parallel_for. But it seems does not work. 

My questions are: TBB does not support task parallelism in producer-consumer patter. So, how should I do it?

stage1 // serial

parallel_for

parallel_for

stage2 // serial

parallel_for

stage3 // serial

 

 

I think you want something like:

stage1 // serial
stage 2 // parallel_for
stage 3 // parallel_for
stage 4 // serial (was stage2)
stage 5 // parallel_for
stage 6 // serial (was stage3)

Jim Dempsey

Yes, What I want to do is  similar what you said above, but I cannot do this directly, because there are order constrains between different tokens.

 

Just to be sure, order constraints that are not addressed by serial_in_order?

(2014-08-09 Added after #7) Apparently I overlooked #4...

Best Reply

Quote:

Xingjing Lu wrote:

In the above example, I set the Number of threads to execute the pipeline like below:

pipeline.run(TheadNum); // ThreadNum = 3, the same number as the number of stages.

If I set up the task schedule for each parallel_for in different stages as:

task_scheduler_init init(4);

parallel_for( blocked_range<int>(0, 4), PASSIN);

what will happened to stages and parallel_for, are there 3 threads for each stage, and another 4 threads for each parallel_for? or there are only 3 threads totally?

It's a common mistake to think that the argument to pipeline.run() is the number of threads. It's not; it's maximal number of items that are allowed to flow through the pipeline at a time. And the motivation for this argument is not restricting concurrency but bounding resource usage (which could otherwise grow "over the top" when a serial filter is the bottleneck in the pipeline).

So if you instruct the task scheduler (via task_scheduler_init) to use 4 threads, that's what you will get (unless the scheduler was initialized earlier, possibly implicitly), no matter what token limit is set for pipeline.

Leave a Comment

Please sign in to add a comment. Not a member? Join today