By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,205 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

openMP question

P: n/a
san
Hi,
I am not sure whether this is the right group to post this. Still here
I go:
I am new to OpenMP. I wrote a very simple code in C++.
The code is as below

#include <iostream.h>
#include <omp.h>
int main()
{
int nthreads, tid;
#pragma omp parallel num_threads(4)
{
int i = omp_get_thread_num();
cout << "Hello from thread " << i << endl;
}
return 0;
}

The output is:
Hello from thread 0

I am getting that line printed only once. Means there is only one
thread i.e. master thread.
What could be the reason for this. In what cases num_thread() or
omp_set_num_threads() fails.

Thanks.

Sep 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"san" <sa**********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com
Hi,
I am not sure whether this is the right group to post this. Still here
I go:
I am new to OpenMP. I wrote a very simple code in C++.
The code is as below
Try

comp.parallel

--
John Carson
Sep 17 '06 #2

P: n/a
<code>
#include "omp.h"
#include <iostream>

int main()
{

std::cout << "Max threads: " << omp_get_max_threads() << std::endl;

#pragma omp parallel for
for (int index=1; index<5000; index++)
{
int tid = omp_get_thread_num();
if (tid!=0)
std::cout << "Hello World from thread = " << tid <<
std::endl;
}

return 0;
}
</code>

compile it like
g++-4.2.0-alpha20060902 test.cc -fopenmp

and run it with
export OMP_NUM_THREADS=5
./a.out

greetz Maik

Oct 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.