473,385 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

openMP question

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
2 1974
"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
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rodrigo Perottoni | last post by:
I'm trying compiling and running the OpenMP Benchmark, but I have some problems. Anyone knows how I compiling and running OpenMP? Thank You.
5
by: Vladimir_petter | last post by:
Hello guys, Looks like this technology is comming along with VS2005. Anybody has an expirience of using it along with C++? What are the patterns? Thanks, Vladimir.
8
by: Gabest | last post by:
I really like the new openmp implementation of vc, but I ran into a something which may be a bug. Please see the following little example: void funct() { __declspec(align(16)) BYTE buff;...
1
by: Carl J. Van Arsdall | last post by:
Hey everyone, I know I've posted several questions regarding python and python's parallel capabilities so bear with me as I've never attempted to incite discussion. However, today I'm...
0
by: BallCOMET | last post by:
I have an application that I built with Visual Studio 2005 and for which I enabled OpenMP. If I open the compiled binary in Visual Studio, this is the manifest that is embedded in the executable...
2
by: firenet | last post by:
gcc -g -fopenmp openmp.c -o openmp cc1: error: unrecognized command line option "-fopenmp" i wrote a simple openmp.c and wanted to compile it, but i got this error. What should i do ? Thanks
7
by: s.z.s | last post by:
Hi! Is anybody using an openmp compiler under cygwin? I tried to install gcc 4.2.2 without success and now I'm looking for alternatives. Thanks, Steffen
6
by: Renato Perini | last post by:
Hi all!!! I'm trying to find a *good* book about OpenMP and C, but I can't find anything specific. Can you advice me some good (and updated) books about OpenMP using the C interface? I'd like a...
0
by: Alien | last post by:
Hi, I am having bit of confusion about !$OPENMP DO/!$OPENMP END DO and !$OPENMP PARALLEL DO/!$OPENMP END PARALLEL DO directives. Having looked at my notes, the only difference I can find is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.