I compile the next hello program, but I don't get the result that I may expect.
program hello
print*, " Hello parallel world"
!$omp parallel
print*, omp_get_thread_num()
!$omp end parallel
print*, "Back to the sequential world"
end
To compile I use:
mpifort -fopenmp -o hello hello.f90
When I run it, it results:
Hello parallel world
0.00000000
0.00000000
0.00000000
0.00000000
Back to the sequential world
, but according to a manual (Parallel Programming in OpenMP by Rohit Chandra, Ramesh Menon, Leo Dagum, David Kohr, Dror Maydan, Jeff McDonald) I could get numbers between 0 and 3, not only zeros. There is something wrong?
You are missing use omp_lib
and the compiler implicitly assumes that omp_get_num_thread()
is a function that returns a floating-point value, because its name begins with o
. It is not though - it returns an integer
. Adding implicit none
right after program hello
will turn off implicit declarations and trigger a compile-time error without use omp_lib
.
program hello
use omp_lib
implicit none
print*, "Hello parallel world"
!$omp parallel
print*, omp_get_thread_num()
!$omp end parallel
print*, "Back to the sequential world"
end