OpenMp takes some time to set up the parallel region. This overhead means you need to be careful that the overhead isn't greater than the performance that is gained by setting up a parallel region. In your case this means that only when N reaches a certain number will openMP speed up the calculation.
Up vote 3 down vote favorite share g+ share fb share tw.
I am working on the code that compares image histograms, buy calculating correlation, intersection, ChiSquare and few other methods. General look of these functions are very similar to each other. Usually I working with pthreads, but this time I decided to build small prototype with openMP (due to it simplicity) and see what kind of results I will get.
This is example of comparing by correlation, code is identical to serial implementation except single line of openMP loop. Double comp(CHistogram* h1, CHistogram* h2){ double Sa = 0; double Sb = 0; double Saa = 0; double Sbb = 0; double Sab = 0; double a, b; int N = h1->length; #pragma omp parallel for reduction(+:Sa,Sb,Saa,Sbb,Sab) private(a ,b) for (int I = 0; idatai; be =h2->datai; Sa+=a; Sb+=b; Saa+=a*a; Sbb+=b*b; Sab+=a*b; } double sUp = Sab - Sa*Sb / N; double sDown = (Saa-Sa*Sa / N)*(Sbb-Sb*Sb / N); return sUp / sqrt(sDown); } Are there more ways to speed up this function with openMP? Thanks!
PS: I know that fastest way would be just to compare different pairs of histograms across multiple threads, but this is not applicable to my situation since only 2 histograms are available at a time. Tested on quad core machine I have a little bit of uncertainty, on a longer run openmp seems to perform better than a serial. But if I compare it just for a single histogram and measure time in useconds, then serial is faster in about 20 times.
I guess openmp puts some optimization once it see outside for loop. But in a real solution I will have some code in between histogram comparisons, and I not sure if it will behave the same way. C++ optimization pthreads parallel openmp link|improve this question edited Jul 31 '11 at 14:52 asked Jul 31 '11 at 14:082di220211 74% accept rate.
– kenny Jul 31 '11 at 14:50 @kenny, this is impossible in a parallel program altbeit being a strange suggestion considering the power of optimizers – unkulunkulu Jul 31 '11 at 14:54.
OpenMp takes some time to set up the parallel region. This overhead means you need to be careful that the overhead isn't greater than the performance that is gained by setting up a parallel region. In your case this means that only when N reaches a certain number will openMP speed up the calculation.
You should think about ways to reduce the total number of openMP calls, for instance is it possible to set up a parallel region outside this function so that you compare different histograms in parallel?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.