several basic questions

several basic questions

hi, there
I am programming on some image processing algorithms and thinking about using tbb to speed up. The data I am dealing with are often 400*400 2D pixels (each presented in gsl_vector) or sometimes a collection of free draw line in the image. The machine is 2core/4processor intel.
My questions are:
1. If I launch the calculation in multi-thread in the bash command, then I won't benefit from ttb on the algorithm level, am I right?
2. Will tbb benefit me on single core single processor cpu?
3. Although the parallel_for works for std::vector, it has performance deduction due to the iterator according to the post here. How serious is that deduction?
4. For the concurrency/lock-unlock problem, for e.g.
void function1(int& x){//x needs to be concurrent
x = some complication on x; //at this time the x should be locked
function2(); // Is x free for the other to use now?
}
5.Suppose I have a double loop, long iteration on outer loop and small iteration in the inner loop.
for (int i = 0; i < 200; i++)
for (int j = 0; j < 20; j++)
function3(variable(i,j));
For my case, I can't do parallel on the outer loop for my algorithm, will tbb benefit me by applying on the small inner loop? The function3 is my "atomic" calculation that doing matrix calculation so it does takes much more time than the iteration of the loop.
Thank you very much for your comments.
zl.

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

zhliuncc:1. If I launch the calculation in multi-thread in the bash command, then I won't benefit from ttb on the algorithm level, am I right?

I am not sure I understand your question. Did you mean launching separate instances of your application at once? In fact, such a setup would not be multi-threading, but multi-processing; and TBB is all about coordinating threads in a single process, so it would not help.

2. Will tbb benefit me on single core single processor cpu?

Generally for single core execution, TBB will add some overhead (little if all is done right). In some cases, however, rewriting an application to TBB could provide some speedup, due to better data locality. But this can not be promised,

3. Although the parallel_for works for std::vector, it has performance deduction due to the iterator according to the post here. How serious is that deduction?

Not sure which post you mean, could you put the link? If you do not change the size of the vector in the parallel loop, you are fine.

4. For the concurrency/lock-unlock problem, for e.g.
void function1(int& x){//x needs to be concurrent
x = some complication on x; //at this time the x should be locked
function2(); // Is x free for the other to use now?
}

I do not see where TBB is in your example, neither do I see locks. It all depends how you use the function. Moreover, the lock should not be associated with the function but with the specific data it processes.

5.Suppose I have a double loop, long iteration on outer loop and small iteration in the inner loop.
for (int i = 0; i < 200; i++)
for (int j = 0; j < 20; j++)
function3(variable(i,j));
For my case, I can't do parallel on the outer loop for my algorithm, will tbb benefit me by applying on the small inner loop? The function3 is my "atomic" calculation that doing matrix calculation so it does takes much more time than the iteration of the loop.

You could still reap some benefit for a small number of cores, but rather obviously this approach will not scale well - there is too few tasks to feed multiple cores and to efficiently balance the load. Though with TBB, you can take benefits of nested parallelism; so if you have some parallelism inside your "atomic" calculation, it could provide enough parallel slack.

Leave a Comment

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