Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

A openMP question

FortCpp
Beginner
554 Views

Dear IVF users and developers,

I am learning OpenMP today. I followed a tutorial: http://www.openmp.org/presentations/miguel/F95_OpenMPv1_v2.pdf

But when I compile and run this:

[fortran]

    program OpenMPpractice

    implicit none

    ! Variables

    ! Body of OpenMPpractice
    !$OMP PARALLEL
        write(*,*) "Hello"
        !$OMP PARALLEL
            write(*,*) "Hi"
        !$OMP END PARALLEL
    !$OMP END PARALLEL
    end program OpenMPpractice

[/fortran]

The result is:

 Hello
 Hello
 Hello
 Hello
 Hi
 Hello
 Hello
 Hello
 Hi
 Hi
 Hello
 Hi
 Hi
 Hi
 Hi
 Hi

But according to the tutorial, I can see that there are 8 threads in the first level of parallel. But in the second level of parallel, the situation is different. I was thinking there should be 64 "Hi"s printed, but there are only 8.

Can anyone tell me what happened there?

 

Thanks,

 

0 Kudos
2 Replies
Roman1
New Contributor I
554 Views

Hi,

I think you need nested parallelism enabled.  Can you try adding:

call omp_set_nested(.true.)

 

Roman

 

0 Kudos
FortCpp
Beginner
554 Views

Hi Roman,

It works! Thanks.

I add use omp_lib. Everything compiles OK.

0 Kudos
Reply