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

the OMP_NUM_THREADS didn't work

史_建鑫
Beginner
2,798 Views

I am struggling with the OpenMP. Through a pdf file "Parallel Programming: OpenMP + FORTRAN" by John Burkardt, I began with a simple "hello world" program.

The Code

[fortran]

program main
    USE IFPORT
    implicit none
    LOGICAL(4) success
    INTEGER(4) length
    CHARACTER(80) val
    
    success = SETENVQQ("OMP_NUM_THREADS=2")
    length = GETENVQQ("OMP_NUM_THREADS", val)
    write(*,*) "val=",val
    write(*,*) success
    
    write ( *, * ) 'A sequential hello to you!'
    !$omp parallel
    write ( *, * ) ' Parallel hello''s to you!'
    !$omp end parallel
    stop
    
end

[/fortran]

I Set the concole properties->Fortran->Language->Process OpenMP Directives to "/Qopenmp", But i still get the four line of "Parallel hello''s to you" no matter i Set the number of OMP_NUM_THREADS.

I use the Intel Parallel Studio XE 2011 + VS2010 + Win 7 64bit + Intel i5-2400 (4 Cores)

Please Help me! Thank you!

0 Kudos
3 Replies
Simon_Geard
New Contributor I
2,798 Views
I don't think your program is doing what you think it is doing since setting the environment variable in a running program won't affect the environment in which the program is running. Instead try [fortran] call omp_set_num_threads(2) [/fortran] Simon
0 Kudos
史_建鑫
Beginner
2,798 Views
thank you very much. it works :) But if i want to set the environment variable before program run, how should i do?
0 Kudos
Simon_Geard
New Contributor I
2,798 Views
It depends on the OS/Shell combination you're running and on how you're invoking the executable. If you have a command line and just want to run the program from that you can set the envirnment variable directly, e.g. Linux/Unix bash export OMP_NUM_THREADS=2 ./your_program Linux/Unix csh setenv OMP_NUM_THREADS 2 ./your_program Windows/DOS set OMP_NUM_THREADS=2 your_program If want to run a file directly that does this you'll need to write a wrapper file that essentially does one of the above. Simon
0 Kudos
Reply