- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a Fortran code comprised of many subroutines that use the MKL LAPACK routines. Some of the LAPACK calls are within an OpenMP loop and some are outside of the OpenMP loop. I would like to run LAPACK outside of the parallelized loops using all of the threads available however inside the parallelized loop I want (and have to) call the LAPACK routine with only 1 thread.
How do I set up my code to do this? In Visual Studio, Properties -> Fortran -> Libraries -> Use Intel Math Kernel Library, if I set this to Sequential then the call to LAPACK will work properly inside the parallel loop but will not run with all of the threads outside of the loop. If I set the MKL to Parallel then this will not run properly inside the loop.
Is there a way to pass in the number of threads into the LAPACK routines during runtime?
Thank you so much for your help!
Sincerely,
David
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes, it is possible by using mkl_set_num_threads() routines before the specific mkl's routine.
the pseudo-code will look like as follows:
mkl_set_num_threads(1)
getrf(*,*,*....)
int numthr=mkl_get_max_threads();
mkl_set_num_threads(numthr);
getrf(.....);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much for your reply Gennady!
So, just to clarify, is the following pseudo code correct,
N = mkl_get_max_threads() OR N = OMP_get_max_threads()
call mkl_set_num_threads(N)
call getrf(...)
call mkl_set_num_threads(1)
call OMP_set_num_threads(N)
!$OMP PARALLEL ...
do i = 1,M
call getrf(...)
end do
!$OMP END PARALLEL DO
1) Are the MKL and OMP routines independent from each other. Do the MKL commands control the threading of each MKL algorithm and the OMP commands control the thread count for the loops?
2) Do I call the mkl_set_num_threads once before entering the OMP loop or does it have to be called each time within the parallelized loop?
3) Can I use the OpenMP or MKL command to get the number of threads but then apply 2) above to tell the code how to use them?
So I guess that I always compile with, Properties -> Fortran -> Libraries -> Use Intel Math Kernel Library set to Parallel and then use the commands above as "switches" to run in sequential (Nthread = 1) and parallel (Nthread = N)?
Thanks you so much again for your help. This will be extremely useful in my computational heavy calculations!!
Sincerely,
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
David,
1) MKL uses OpenMP (libiomp5*.*) library as a one of backend threading runtime, but if you call call mkl_set_num_threads(1) then MKL will execute the single thread computation. You may check it by enabling the verbose mode (e.x – set/export MKL_VERBOSE=1) to see how many threads will be used by mkl’s routines.
2)Yes, You could call mkl_set_num_thread once before OMP loop.
3) yes you can call MKL functions many times to get/set differen number of threads
And Yes, in the case if you are working from within the MVSV IDE, you could set Properties -> Fortran -> Libraries -> Use Intel Math Kernel Library set to Parallel
And then there OpenMP threaded mkl libs will be linked with your application.
-Gennady
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This issue has been resolved and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page