A very basic question

General OpenMP discussion

A very basic question

Postby UYNIX » Thu Apr 26, 2012 12:13 pm

Hi,

I am new to OpenMP, just start to write my first hello world problem with FORTRAN using an Intel Fortran compiler on a duo core machine. I started to twist a bit of the hello world program and something odd is happening. The code is as below.
!---------------------------------------------
program ompHelloWorld
use omp_lib
integer NTHREADS, TID, I, TID1

!$OMP PARALLEL
!$OMP MASTER
TID1 = OMP_GET_THREAD_NUM()
PRINT *, 'Master computer id is ', TID1
NTHREADS = OMP_GET_NUM_THREADS()
PRINT *, 'Number of threads = ', NTHREADS
!$OMP END MASTER
TID = OMP_GET_THREAD_NUM()
PRINT *, 'Hello World from thread = ', TID
!$OMP END PARALLEL
pause
end program ompHelloWorld
!--------------------
I am expecting the command window shows:
Master computer id is 0
Number of threads = 2
Hello World from thread = 0
Hello World from thread = 1

Instead, the program prints this from time to time (not consistent)
Master computer id is 0
Number of threads = 2
Hello World from thread = 0
Hello World from thread = 0

Can anyone please help me? I am scratching my head a thousand times now. The studying materials do not seem to be helpful.

Many thanks.

Cindy
UYNIX
 
Posts: 8
Joined: Thu Apr 26, 2012 11:58 am

Re: A very basic question

Postby UYNIX » Thu Apr 26, 2012 1:00 pm

I guess I am encounter the issue of data sharing. I should have set TID as private, then this error does not occur anymore.
UYNIX
 
Posts: 8
Joined: Thu Apr 26, 2012 11:58 am

Re: A very basic question

Postby ruud » Fri Apr 27, 2012 1:12 am

Hi Cindy,

I'm glad to hear you found the problem yourself.

It again demonstrates why I prefer (and highly recommend) to use the "default(none") clause.

This may seem more work, but the initial investment tends to be worth it, because errors like this are much less likely to happen. It is also simply good practice to think about the nature of your variables and decide yourself whether they should be private, shared, etc.

The default rules in OpenMP can also be somewhat subtle and unless you understand them really well, a mistake is easily made. I for one don't know them.

Ruud
ruud
 
Posts: 23
Joined: Mon Nov 26, 2007 2:13 am

Re: A very basic question

Postby johnbatt » Mon Jul 09, 2012 6:59 pm

I'm a beginner myself and was able to use the "default(none") clause with the problem above as well. Establishing variables ahead of time seems to be the best course of action before you starting writing anything. I will often use a piece of Mind Map software a friend of mine developed, it seems to help me plan everything out ahead of time and avoid (some) mistakes.

JB
johnbatt
 
Posts: 1
Joined: Sun Jul 08, 2012 6:45 am

Re: A very basic question

Postby rain_physics » Wed Jul 11, 2012 8:49 am

I don't know, is this the right place for my question or not, I just want to ask that I have to calculate eigenvalue value and eigen vector of a matrix,
- is there any library exist for eigenvalue value function
- which library I should use for this purpose
rain_physics
 
Posts: 2
Joined: Tue Jul 10, 2012 10:26 am


Return to Using OpenMP

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests

cron