Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help: Want to setup the IPP environment inside of my program

0 views
Skip to first unread message

Johnson

unread,
Jan 29, 2010, 5:57:28 PM1/29/10
to
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?

Thank you!

Johnson

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Johnson

unread,
Jan 29, 2010, 6:21:42 PM1/29/10
to
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 let me know if it is right.

_putenv( "KMP_AFFINITY=compact" );

Kaz Kylheku

unread,
Jan 29, 2010, 6:43:27 PM1/29/10
to
On 2010-01-29, Johnson <gpsa...@yahoo.com> wrote:
> 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 let me know if it is right.
>
> _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.

0 new messages