3

I want to iterate an image pixel by pixel and do a 1000 of floating point operations per pixel. Do you think I should use multi-threading or multiprocessing, i.e. boost::thread or OpenMP for this? Is there a rule of thumb to choose between these 2 (for fastest speed)? I have understood that creating threads or switching between threads is multiple times faster than creating/switching processes. On the other hand implementing OpenMP code is much easier.

My solution right now:

#pragma omp parallel for
for(size_t i=0; i<640; ++i) {
    for(size_t j=0; j<480; ++j) {
        // do 1000 float operations
    }
} 
3
  • if you use vs 2012 magic might be done by compiler:msdn.microsoft.com/en-us/library/hh872235.aspx Jan 8, 2013 at 13:50
  • No, I don't use VS. Looking for a portable solution.
    – lahjaton_j
    Jan 8, 2013 at 14:14
  • If at all possible, you want to use something that'll run on the GPU such as OpenCL, CUDA or a shader (GLSL or HLSL). For an operation like this, you can expect it to be something like 100x faster than the best you can hope to accomplish on the CPU. Jan 8, 2013 at 14:17

1 Answer 1

3

OpenMP is more than sufficient for this, in fact boost does not even have a built-in parallel loop construct.

Do you think I should use multi-threading or multiprocessing

Although OpenMP stands for Open MultiProcessing, it is in fact a multithreading library.

An alternative library worth looking at is Intel TBB.

1
  • @lahjaton_j: No problem. Don't forget that you can mark an answer as accepted if it solved your problem.
    – Tudor
    Jan 8, 2013 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.