Thank you for your time in reading my post.
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?
I tried _putenv to assign the environment variables. However, I was not sure if it is the right way to assign to set the OpenMP environment variables. Please verify.
_putenv( "KMP_AFFINITY=compact" );
On a Windows system you can use the _putenv() function, but the effect will be limited to your process, and it may not have an impact on the OpenMP component of your app, depending on when that component initializes and reads the application environment space (the application environment space is essentially a copy of the system environment when your app started, similar to a Linux/UNIX machine). So this approach might not work... but I've never tested it so I can't be sure. Here's more info on that for Windows:
Here's a link to how to change the environment variables directly within your system environment space. You'll see there is a system environment and a personal environment. Both appear when you go to the command line (run a cmd.exe box) and type "set
You could also create a batch file that defines the environment variables and run it within a cmd.exe window before running your app (make sure to run the app from the same command line as the batch file, 'cause the environment variable changes implemented by the batch file will only apply to that cmd.exe window). Based on your post, the batch file could contain a single line:
You could follow that line with the name of your app, so the batch file would set the environment variable and then start your app.
Here's more info from Microsoft regarding the command line and batch files and environment variables.
Hope that helps,
Thank you for your reply, Paul.
I also tried
Environment::SetEnvironmentVariable Method (String, String) in my program. It works fine and I can read and write environment variables (user, system) for the whole application.