Re: Having trouble with very basic OpenMP program



Carl,

I am ashamed to say that, that was indeed the problem.

I now recall deleting the original project, and creating a new one. I set
the flag in the first project, and not in the second.

Thanks for your help,
Hari

"Carl Daniel [VC++ MVP]" wrote:

> Hari wrote:
> > Hello,
> >
> > I have a hello world program that uses OpenMP, and I am unable to
> > understand it's behavior.
> >
> > The code is:
> >
> > #include <iostream>
> > #include <omp.h>
> >
> > using namespace std;
> >
> > int main ()
> > {
> > cout << "Max openMP threads = " << omp_get_max_threads () << endl;
> >
> > #pragma omp parallel
> > {
> > int num = omp_get_thread_num ();
> > cout << "Hello from thread " << num << endl;
> > }
> >
> > cout << endl << "Number of threads " << omp_get_num_threads ();
> > }
> >
> > Very basic program.
> >
> > My machine is a HyperThreaded P4, and omp_get_max_threads () returns
> > 2.
> >
> > I would now expect that the parallel code segment will be run on two
> > separate threads. But it is run on only 1.
> >
> > The program output is:
> >
> > "Max OpenMP threads = 2
> > Hello from thread 0
> >
> > Number of threads 1"
> >
> > So, the parallel segment is run on only 1 thread. Can someone explain
> > this behavior, and how I can fix it?
>
> Are you compiling with VC++ 2005? Are you using the /openmp command-line
> switch (or the corresponding IDE setting)?
>
> -cd
>
>
>
.