the OMP_NUM_THREADS didn't work

the OMP_NUM_THREADS didn't work

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

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

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!

4 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

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


call omp_set_num_threads(2)

Simon

thank you very much. it works :)
But if i want to set the environment variable before program run, how should i do?

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

Faça login para deixar um comentário.