- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page