[Omp] omp parallel sections and omp parallel for what are differences?

Alexander Bubnov alexander.bubnov at gmail.com
Wed Aug 1 00:48:22 PDT 2007


Thanks for the answer. It is clear.

2007/7/31, Eric Duncan <Eric.Duncan at sun.com>:
> I have to run to a meeting - so the short answer is yes - they are
> different.
>
> The "pragma parallel for" says that this is a workshare that is to be
> run in parallel.  Parts of the loop are scheduled to run on different
> threads - depending on how many threads you say to use.
>
>
> Alexander Bubnov wrote:
> > As far as I understand for loop the same as each function runs inside
> > one thread. Does "pragma for" process by other way?
> >
> > 2007/7/31, Eric Duncan <Eric.Duncan at sun.com>:
> >
> >> First, your syntax is wrong.  In the first case, it should be "section"
> >> and not "single", as in:
> >>
> >> #pragma omp parallel sections
> >> {
> >> #pragma omp section
> >>   func1();
> >> ...
> >> }
> >>
> >> But to try and answer your question, it depends on the OpenMP implementation and the number of threads you are using.  For example, if you are using 3 threads and the for loop default is schedule(static, 1), then I would think that with most OpenMP implementations, the two constructs would have about the same performance.  However, if the default for the for loop is different or you are running with less than 3 threads, I could see that the performance that you see could be quite different.
> >>
> >> For example, if the default for loop schedule were "static,2", then one thread might get multiple  chunks that both required a long execution causing it to appear to have worse performance.  Or if 2 threads were used and a static type schedule were used for the sections construct (which is implementation dependent and not something you can control), then two of the sections might be assigned to the same thread and if they were both long running, then it could appear that it has worse performance than the for loop.
> >>
> >>
> >> Alexander Bubnov wrote:
> >>
> >>> Hello, all!
> >>>
> >>> I have questions for you.
> >>>
> >>> FIRST CASE:
> >>> #pragma omp parallel sections
> >>> {
> >>> #pragma omp single
> >>>   func1();
> >>> #pragma omp single
> >>>   func2();
> >>> #pragma omp single
> >>>   func3();
> >>> }
> >>>
> >>> SECOND CASE:
> >>>
> >>> {
> >>>   void (*f[])() = {func1,func2,func2};
> >>> #pragma omp parallel for
> >>>   for(i=0; i<3; ++i)
> >>>   {
> >>>     f[i]();
> >>>   }
> >>>
> >>> }
> >>>
> >>> Are these cases same or different from each other by performance?
> >>> Which of them is better and why? Or do they depend on?
> >>>
> >>>
> >>>
> >>
> >
> >
> >
>
>


-- 
/BR, Alexander


More information about the Omp mailing list