- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have an application that uses Windows threads on a high level for parallelization. MKL is called on each thread.
In certain critical sections of the program threads are executed serially (think mutex). In these critical sections MKL functions are also called.
If my machine has N processors, I create N Windows threads so that at a very high level I achieve the parallelization I want. At this point I would like to set MKL_NUM_THREADS to 1 as I have no more processor power left.
However, at the critical sections I would like to set MKL_NUM_THREADS to N.
My question: is there a way to continuosly change the value of this environment variable? I'm concerned about when a MKL function will actually check the value of the environment variable. If I use "putenv" this may not be good enough.
Thanks.
I have an application that uses Windows threads on a high level for parallelization. MKL is called on each thread.
In certain critical sections of the program threads are executed serially (think mutex). In these critical sections MKL functions are also called.
If my machine has N processors, I create N Windows threads so that at a very high level I achieve the parallelization I want. At this point I would like to set MKL_NUM_THREADS to 1 as I have no more processor power left.
However, at the critical sections I would like to set MKL_NUM_THREADS to N.
My question: is there a way to continuosly change the value of this environment variable? I'm concerned about when a MKL function will actually check the value of the environment variable. If I use "putenv" this may not be good enough.
Thanks.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use the MKL function, mkl_set_num_threads() to set/modify the number of threads at run-time and this function has precedence overthe environment variable, MKL_NUM_THREADS.
You can refer to section 5 ("Manging Performance and Memory") of the MKL user guide located at, http://software.intel.com/en-us/articles/intel-math-kernel-library-documentation/ for more details and code examples.
You can refer to section 5 ("Manging Performance and Memory") of the MKL user guide located at, http://software.intel.com/en-us/articles/intel-math-kernel-library-documentation/ for more details and code examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting mullervki
However, at the critical sections I would like to set MKL_NUM_THREADS to N.
As Vamsi said, you should be able to call mkl_set_num_threads to set the number for the next MKL function call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You probably misunderstand the role of environmental variables. They provide a means of communication with the runtime of the compiler, or with the operating system. The runtime or the OS may be written to query the existence and value of an environmental variable, and decide to allocate threads, allocate more memory, abort a process, etc. The hardware itself knows NOTHING about environmental variables.
Secondly, an environmental variable is not a semaphore. Your program inherits the environment that existed when the process was started. Subsequent changes to the environment are not communicated to your program.
> If my machine has N processors, I create N Windows threads so that at a very high level I achieve the parallelization I want. At this point I would like to set MKL_NUM_THREADS to 1 as I have no more processor power left.
If all possible threads have been allocated, how can you do anything but wait for at least one thread to finish? If you terminate threads before they finished, would your results not be junk?
Why don't you create N-1 (or N-M) threads, instead?
Secondly, an environmental variable is not a semaphore. Your program inherits the environment that existed when the process was started. Subsequent changes to the environment are not communicated to your program.
> If my machine has N processors, I create N Windows threads so that at a very high level I achieve the parallelization I want. At this point I would like to set MKL_NUM_THREADS to 1 as I have no more processor power left.
If all possible threads have been allocated, how can you do anything but wait for at least one thread to finish? If you terminate threads before they finished, would your results not be junk?
Why don't you create N-1 (or N-M) threads, instead?

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page