[Omp] #pragma for problem

Meadows, Lawrence F lawrence.f.meadows at intel.com
Sat Jun 30 10:41:28 PDT 2007


#pragma omp parallel starts a parallel region. All threads executed the
same code redundantly
#pragma omp for is a worksharing construct that partitions the work
among the threads. In this case the iterations of the following for loop
are partitioned among the threads executing the parallel region.
#pragma omp parallel for is shorthand for:
#pragma omp parallel
{
#pragma omp for
for (...) { }
}
 
There are other worksharing constructs. Worksharing constructs in serial
region have essentially no effect.

________________________________

From: omp-bounces at openmp.org [mailto:omp-bounces at openmp.org] On Behalf
Of sidharth garg
Sent: Saturday, June 30, 2007 8:59 AM
To: omp at openmp.org
Subject: [Omp] #pragma for problem


hello frenz.
 i recently started using openmp....but can't figure out what is the
diffrence betwenn 
 #pragma omp for     &  #pragma omp parallel for
i tried following two programs
#include<stdio.h>
#include<omp.h>
int main()
{
 int i=0;
omp_set_num_threads(8);
#pragma omp for
for(i=0;i<1000;i++)
{ printf("\n Thread number %d",omp_get_thread_num()); }
return 0;
}


Output:
Thread number 0
Thread number 0 ....uptill 100 times

thus this whole code is executed by first thread only..... 


#include<stdio.h>
#include<omp.h>
int main()
{
 int i=0;
omp_set_num_threads(8);
#pragma omp parallel for
for(i=0;i<1000;i++)
{ printf("\n Thread number %d",omp_get_thread_num()); }
return 0;
}
output:
 Thread number "diffrent each time"  from 1 to 7

that is perfectly fine that parallel make the code to transfer to each
thread and each thread execute its part...then if it is done using
#pragma omp parallel for
then 
what is the use of #pragma omp for

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://openmp.org/pipermail/omp/attachments/20070630/baec556b/attachment.html 


More information about the Omp mailing list