Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Problems about how to use multithreaded intel MKL

Huang_X_2
Beginner
1,331 Views

Hello,

I have some problems about multithreaded intel MKL

1.    I use the function MKL_SET_NUM_THREADS(2) to change the thread number. Then I want to check the value of MKL_NUM_THREADS, by using function getnv (mklname, value), mklname = MKL_NUM_THREADS. The value is always 1.

I wonder if the value of MKL_NUM_THREADS will be changed when the parallelization starts.

If so, is there a way to check the value of MKL_NUM_THREADS? How do I know if the value of MKL_NUM_THREADS is really changed after I set it?

 

2.   I use the function MKL_SET_NUM_THREADS(2) to change the thread number. According to the runtime it works and the cpu efficiency is about 200%. The function I test is DGEMM. But when I test DGEQP3 or DGEQPF, the runtime is not changed and the cpu efficiency is always 100%.

I think there is something wrong but I can’t figure it out.

I want to know why.

Is there some examples for me about how to use multithreaded intel MKL?

 

Thank you !

 

OS: Linux, Red Hat 5.5

MKL: compilerpro-12.0.0.084

Ifort: composerxe-2011.0.084

0 Kudos
5 Replies
SergeyKostrov
Valued Contributor II
1,331 Views
Try to use an MKL function kmp_set_defaults( "<...env variable=value...>" ).
0 Kudos
Gennady_F_Intel
Moderator
1,331 Views

MKL doesn’t provide routine to track env variables value, but by design this env variable have not to be changed. If this happens then this is the real issue. 

Regard to DGEQP3 or DGEQPF – what is the problem size did you tried to solve?

Is there some examples for me about how to use multithreaded intel MKL?  -- pls have a look at the MKL User Guide. You may find out there the “Changing the Number of OpenMP* Threads at Run Time” example

0 Kudos
Jing_Xu
Employee
1,331 Views
0 Kudos
SergeyKostrov
Valued Contributor II
1,331 Views
>>...MKL doesn’t provide routine to track env variables value... A CRT function getenv needs to be used.
0 Kudos
SergeyKostrov
Valued Contributor II
1,331 Views
At runtime mkl_set_num_threads needs to be used instead to change running number of OpenMP processing threads and here is a C example:

...
    printf("Finding max number of threads Intel(R) MKL can use for parallel runs\n\n");
    max_threads = mkl_get_max_threads();

    printf("Running Intel(R) MKL from 1 to %i threads\n\n", max_threads);

    for( i = 4; i <= max_threads; i += 16 )
    {
        for( j = 0; j < (m*n); j++ )
            C = 0.0;

        printf("Requesting Intel(R) MKL to use %i thread(s)\n\n", i );
        mkl_set_num_threads( i );

        printf("Measuring performance of matrix product using Intel(R) MKL dgemm function \n"
               "via CBLAS interface on %i thread(s)\n\n", i);

        s_initial = dsecnd();
        for( r = 0; r < LOOP_COUNT; r++ )
        {
            cblas_dgemm( CblasRowMajor, CblasNoTrans, CblasNoTrans,
                         m, n, p, alpha, A, p, B, n, beta, C, n );
        }
        s_elapsed = (dsecnd() - s_initial) / LOOP_COUNT;

        printf("== Matrix multiplication using Intel(R) MKL dgemm completed ==\n"
               "== at %.5f seconds using %d thread(s) ==\n\n", (s_elapsed), i);
    }

...

 

0 Kudos
Reply