[Omp] #pragma for problem

sidharth garg sidharth.nitj at gmail.com
Sat Jun 30 08:58:40 PDT 2007


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/d360c2cd/attachment.html 


More information about the Omp mailing list