I have two questions:

I'm new to openMP and currently working my way through the openMP tutorial given at

http://kallipolis.com/openmp/

Question1:

I have installed the C++ and Fortran compiler and tested the (C++) programs

(serial and parallel versions). However, when I try to compile the parallel version (the

one including the openMP directives) without the -openmp option, I get error messages like

******************************************************************************************

tobiash@arpc2/parallel> icc taylor_yes_omp.c -o taylor_yes_omp.c.exe

taylor_yes_omp.c(15): warning #161: unrecognized #pragma

#pragma omp parallel sections num_threads(2)

^

taylor_yes_omp.c(17): warning #161: unrecognized #pragma

#pragma omp section

^

taylor_yes_omp.c(31): warning #161: unrecognized #pragma

#pragma omp section

******************************************************************************************

I thought, that when compiling a (parallelized) code without enabling the -openmp option

should compile the code in (default?) serial mode?!?

Question 2:

I'm a Fortran programmer and therefore I translated the taylor program into

Fortran90 language. Here is the code:

**************************************************************************************

program taylor

implicit none

double precision :: s_tart,s_top

double precision :: e,pi,factorial,product,test

integer*8 :: i,j,num_steps

num_steps = 20000000

call CPU_TIME(s_tart)

print *, 'Calculating e is started'

e = 1.0

factorial = 1.0

!$omp parallel do

do i=1,num_steps

factorial = factorial * i

e = e + 1.0/factorial

end do

print *, 'Calculating e is done, e=',e

print *, '*********************'

print *, 'Calculating pi is started'

pi = 0.0

!$omp parallel do

do j = 0,num_steps*10

pi = pi + 1.0/(j*4.0 + 1.0)

pi = pi - 1.0/(j*4.0 + 3.0)

end do

pi = pi * 4.0

print *, 'Calculating pi is done, pi=',pi

product = e * pi

call CPU_TIME(s_top)

print *, 'Reached result', product, 'in', s_top-s_tart, 'seconds.'

end

*******************************************************************************

However, when I run the code, I get erratic results! Sometimes PI is calculated

correctly and e is not correct and sometimes e is calculated correctly and PI is

not correct! And sometimes both are not calculated correctly!

Here is an example of the output (I compile in the beginning and run the code

7 times from the prompt):

tobiash@arpc2/parallel> ifort -openmp taylor.f90 -o taylor.f90.exe

taylor.f90(17): (col. 7) remark: OpenMP DEFINED LOOP WAS PARALLELIZED.

taylor.f90(28): (col. 7) remark: OpenMP DEFINED LOOP WAS PARALLELIZED.

tobiash@arpc2/parallel> ./taylor.f90.exe

Calculating e is started

Calculating e is done, e= 1.00000010000000

*********************

Calculating pi is started

Calculating pi is done, pi= 3.14159264858941

Reached result 3.14159296274867 in 26.6179540000000 seconds.

tobiash@arpc2/parallel> ./taylor.f90.exe

Calculating e is started

Calculating e is done, e= 1.00000010000000

*********************

Calculating pi is started

Calculating pi is done, pi= 2.499999959002954E-009

Reached result 2.500000209002950E-009 in 26.7519340000000 seconds.

tobiash@arpc2/parallel> ./taylor.f90.exe

Calculating e is started

Calculating e is done, e= 1.00000010000000

*********************

Calculating pi is started

Calculating pi is done, pi= 2.499999959002954E-009

Reached result 2.500000209002950E-009 in 26.5929570000000 seconds.

tobiash@arpc2/parallel> ./taylor.f90.exe

Calculating e is started

Calculating e is done, e= 1.00000010000000

*********************

Calculating pi is started

Calculating pi is done, pi= 2.499999959002954E-009

Reached result 2.500000209002950E-009 in 26.7169390000000 seconds.

tobiash@arpc2/parallel> ./taylor.f90.exe

Calculating e is started

Calculating e is done, e= 1.00000010000000

*********************

Calculating pi is started

Calculating pi is done, pi= 2.499999959002954E-009

Reached result 2.500000209002950E-009 in 26.5649620000000 seconds.

tobiash@arpc2/parallel> ./taylor.f90.exe

Calculating e is started

Calculating e is done, e= 1.00000010000000

*********************

Calculating pi is started

Calculating pi is done, pi= 3.14159264858941

Reached result 3.14159296274867 in 26.7009400000000 seconds.

tobiash@arpc2/parallel> ./taylor.f90.exe

Calculating e is started

Calculating e is done, e= 2.71828182845905

*********************

Calculating pi is started

Calculating pi is done, pi= 2.499999959002954E-009

Reached result 6.795704459706088E-009 in 26.5679620000000 seconds.

tobiash@arpc2/parallel>

However, when I compile without -openmp option. I get correct results everytime! But then,

of course, only fully serial!

What is going wrong!? Any help and explanations are very welcomed. This experience disencouraged

me in proceeding with openMP, since I'm reading Chandra et al. (Parallel Programming in OpenMP) and

wanted to test the "!$omp parallel do" directive on the taylor program - but getting wrong results! The

two do-loops in the taylor program are fully parallelisable and hence, each time the loops should split

into two threads. I don't understand why this problem occurs!

Any help/explanation is appreciated, but remember I'm new to OpenMP! I'm running Fedora 5 with an

Intel Pentium D (dual-core) processor.

Thank you!

Tobias