I am developing a C++ program with Visual Studio 2008 at Windows Vista
platform. I would like to set a few OpenMP environment variables inside
of my program. For example, I would like to set "KMP_AFFINITY=compact".
Could anybody show me how to do it? I think setenv only works for UNIX
and LINUX, right?
I also would like to know how to set the OpenMP environment variables
manually or in the script. Is there any script/configuration file for
the IPP? Can I set the OpenMP environment variables the same way as
other windows system variables? I mean, buy opening "My Computer",
select "Environment Variables", and create a variable for the
environment variable then set its value?
Thank you!
Johnson
--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---
_putenv( "KMP_AFFINITY=compact" );
How do you know that the place where you call this is not too late for OpenMP
to notice? Where is it documented that you can do this from within the program,
when it's already running?
15 seconds of googling confirms the intuition that there is a library API to
obtain the same effect, from within the program, as setting the KMP_AFFINITY
variable before running the program.
The documentation even provides a code sample for how to mimic the
behavior of KMP_AFFINITY=compact. Quote:
``Therefore, by creating a parallel region at the start of the program whose
sole purpose is to set the affinity mask for each thread, the user can
mimic the behavior of the KMP_AFFINITY environment variable with low-level
affinity API calls, if program execution obeys the three aforementioned
rules from the OpenMP specification. Consider again the example presented
in the previous figure. To mimic KMP_AFFINITY=compact, in each OpenMP
thread with global thread ID n, we need to create an affinity mask
containing OS proc IDs n modulo c, n modulo c + c, and so on, where c is
the number of cores. This can be accomplished by inserting the following C
code fragment into the application that gets executed at program startup
time: ...''
RTFM for the code.