problem with openmp hello world!

problem with openmp hello world!

farzin p.'s picture

Dear all,

I have some problems in compiling the following prototype. I execute the attached simple program using multiple cores. Problem is that I am all the time getting just one instead of multiple 'Hello World's.I have used -openmp -Qparallel -fpp settings.

Thanks in advance.

AttachmentSize
Download openmp-hello-world.zip858.8 KB
7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
John Campbell's picture

try something like:

program main
 implicit none
 integer*4 omp_get_thread_num
 integer*4 i
write ( *, * ) 'A sequential hello to you!'
!$omp parallel do
 do i = 1,15
   write ( *, * ) ' Parallel hello''s to you!', i, omp_get_thread_num ()
 end do
 !$omp end parallel do
stop
 end

farzin p.'s picture

Dear John,

 I tried your code. But as can br seen, just 'thread 0' is working. what about the other threads? I'm using an intel  core i5-2400 CPU.

thanks.

 A sequential hello to you!
  Parallel hello's to you!           1           0
  Parallel hello's to you!           2           0
  Parallel hello's to you!           3           0
  Parallel hello's to you!           4           0
  Parallel hello's to you!           5           0
  Parallel hello's to you!           6           0
  Parallel hello's to you!           7           0
  Parallel hello's to you!           8           0
  Parallel hello's to you!           9           0
  Parallel hello's to you!          10           0
  Parallel hello's to you!          11           0
  Parallel hello's to you!          12           0
  Parallel hello's to you!          13           0
  Parallel hello's to you!          14           0
  Parallel hello's to you!          15           0

sgeard@cad-schroer.co.uk's picture

I'm not an expert on openmp but I thought you had to associate the parallel directive with do, workspace or section. Since you're not doing any of these you're not asking it to do anything in parallel. If you were expecting the outpout to appear once for each core then you'll still need to use a loop limited to the number of threads (which you can get with an OMP call). I tried the following variation on my machine which might be of help:

program main
use omp_lib
implicit none
integer :: i, nt
write ( *, * ) 'A sequential hello to you!'
!$omp parallel
nt = omp_get_num_threads()
!$omp do
do i=1,nt
write ( *, '(a,i0)' ) ' Parallel hello''s to you from ',i
end do
!$omp end do
!$omp end parallel
stop
end

 A sequential hello to you!
 Parallel hello's to you from 1
 Parallel hello's to you from 4
 Parallel hello's to you from 2
 Parallel hello's to you from 5
 Parallel hello's to you from 3
 Parallel hello's to you from 8
 Parallel hello's to you from 7
 Parallel hello's to you from 6

Note the out-of-sequence numbering which is what you shoud expect when executing a lop in parallel.

farzin p.'s picture

Dear sgeard

I trired your code. but I get this:

 A sequential hello to you!
 Parallel hello's to you from 1

why just one thread is recognized?

thanks

Lorri Menard (Intel)'s picture

There are a couple of things I see with your project that was attached in the original posting.

First - while /Qparallel was set, the setting "Language->Generate Parallel Code" was not set (that turns on the /Qopenmp switch).
When I changed that, I saw multiple "Parallel hello's to you" lines.

Also, you're using the DEBUG configuration, which has optimizations turned off.   Ultimately, this may have an effect on a "real" program instead of this prototype.

                     --Lorri

farzin p.'s picture

Dear Lorri,

Special thank for your usefull comment. Problem solved!

thanks everyone :)

Login to leave a comment.