Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

OpenMP Hello World.

Intel_C_Intel
Employee
963 Views

I am sorry for asking suck a simple question but I am having hard time to execute simple program using multiple cores. I am using Intel Visual Fortran Compiler 9.1 Professional with Microsoft Visual Studio 2005, and I have Intel Core 2 Duo Processor. Here is the code which I am compiling.

program OpenMP

use omp_lib

implicit none

!$omp parallel

print *, 'Hello World'

!$omp end parallel

call system("PAUSE")

end program OpenMP

But I am all the time getting just one Hello World instead of two. Can anyone tell me what I am doing wrong?

Thanks in advance.

0 Kudos
5 Replies
Mark_Westwood
Beginner
963 Views
Hi

I use VS 2003 and Intel Fortran 10.x but I guess this might help:

From the project menu select project Properties, select the Fortran branch, then Language. Here you'll find a line with the name 'Process OpenMP Directives'; I guess that you have not set this to Generate Parallel Code.

Check out the documentation for further detail.

Regards

Mark Westwood
0 Kudos
TimP
Honored Contributor III
963 Views
Besides checking your project properties (enable /Qopenmp for compile and link), you might start with one of the examples posted on the web.
0 Kudos
Intel_C_Intel
Employee
963 Views

Thanks. I have one more question, what exactly going to happen with shared variables when they step in to parallel region, I mean what value they would have. Because right now during debugging I can see that they have totally different values inside parallel region.

For example:

REAL*8 some_num = 10;

INTEGER other_number = 5;

INTEGER I;

!$omp parallel default(none)&

!$omp shared(some_num, other_number)

!$omp do lastprivate(i) schedule(static, 2)

DO I = 2, 10

some_num = some_num + other_number

other_number = other_number + i

END DO

!$omp end do

!$omp end parallel

NOTE: some_number and other_number are not eq to 5 and 10 inside parallel region why?

Thanks in advance.

0 Kudos
TimP
Honored Contributor III
963 Views
As you declared those variables shared, each thread tries to update the same (only) copies of the variables. There is no guarantee about the order of events, beyond the partial control implied by your schedule clause. This is called a race condition. The result will depend, among other things, on how many threads you specify.
You could make the other_number consistent by specifying a reduction, and changing the code so that it is not a SAVEd variable (implied by initializing at declaration).
If you used Qparallel and Qpar-report, instead of OpenMP, you might get some diagnostics (possibly obscure) about what is wrong with attempting to parallelize this.

0 Kudos
Intel_C_Intel
Employee
963 Views

Thanks for answering, what will happen if I will do something like this:

 DO N=1,10 

!$omp parallel default(none)&

!$omp shared(N)

!$omp do lastprivate(L, I, J, K) schedule(static,5)

DO L=2,10

I = N + L !here I and L are shared but not N.

J = 0

DO K=L,10

J = J + 1 !here J is shared would it work fine?. &nbs p;

END DO

END DO

!$omp end do

!$omp end parallel

END DO

What value would have I and J? is it race condition? And in which case I should use !$omp atomic ?

Thanks in advance.

0 Kudos
Reply