how to set omp environment from executable?

how to set omp environment from executable?

Hi there,

I am wondering whether it is possible to setup the OMP environment, namely, OMP_PLACES and OMP_PROC_BIND by the executable at the start of the program, so NOT via bashrc etc. The reason is that users may forget to or not be aware of how to do the proper bashrc settings.

I found an old thread where people used

success = SETENVQQ("OMP_PLACES=cores")

form inside the executable, which is what I want too, but I am wondering whether that has any effect at all once the program runs.

I tried this:

Program Test
  !$ use omp_lib
  USE IFPORT, only: SETENVQQ
  implicit none
  character(len=50) :: val
  integer :: istat
  !$ write(*,*) omp_get_proc_bind()
  call GET_ENVIRONMENT_VARIABLE(name="OMP_PROC_BIND",value=val,Status=istat)
  write(*,*) "OMP_PROC_BIND: ", trim(adjustl(val))
  istat = SETENVQQ("OMP_PROC_BIND=spread")
  call GET_ENVIRONMENT_VARIABLE(name="OMP_PROC_BIND",value=val,Status=istat)
  write(*,*) "OMP_PROC_BIND: ", trim(adjustl(val))
  !$ write(*,*) omp_get_proc_bind()
End Program Test

and the ouput was that:

          0
 OMP_PROC_BIND: 
 OMP_PROC_BIND: spread
           0

which, according to the omp manual, implies that "OMP_PROC_BIND" is still "false" after setting the environment variable.

Any suggestions are highly appreciated.

Thanks

publicaciones de 3 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

I don't think there's a way to do this from inside the executable. As best as I can tell, the environment variables are queried in a call made automatically by the compiler at the start of the main program, before any of your statements are executed.

Maybe you could supply your program as a script that sets the variables and then runs the executable?

Steve (aka "Doctor Fortran") - Retired from Intel

If you really want to play these games, look at Low Level Affinity API. Or see Portable Hardware Locality (hwloc) library for more abstraction.

There is also PROC_BIND clause to !$OMP PARALLEL directive.

You can also build your sources with prescribed thread affinity via compiler options: par-affinity, Qpar-affinity

 

Note. Options above will bind threads to "places" or "cores" or will modify threads affinity. They will not modify the original environment that is passed to the process as it is initiated.

 

Modifying environment variables in runtime is not portable and is a bad idea.

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya