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

Unable to utilize all threads - Core i5-1135G7

muzamil-py
Novice
1,831 Views

Hi everyone, I am facing a problem.

Problem:
I installed OneAPI Base Toolkit on my Dell Inspiron 13 7306 which is having Core i5-1135G7. I am running both Windows and Linux (dual boot) on it. First I installed OneAPI Base Toolkit on Linux. After which I compiled and executed the following code but I am unable to use Max Number of Cores / Threads i.e 4 Cores and 8 Threads. In my code I have used 

"int numThreads = mkl_get_max_threads();" which returns 1. 
 
I have used: 
"mkl_set_num_threads(4);" to increase the number of threads but it does not increase the cores.
 
I have tested it on Windows as well and same issue.
 
Code
#include <iostream>
#include <mkl.h>
#include <chrono>


int main() {
mkl_set_num_threads(4);
int numThreads = mkl_get_max_threads();
std::cout << "Number of threads: " << numThreads << std::endl;
// Matrix dimensions
const int m = 10000;
const int n = 10000;
const int k = 10000;

// Allocate memory for matrices A, B, and C
double *A = (double*)mkl_malloc(m * k * sizeof(double), 64); // 64-byte alignment
double *B = (double*)mkl_malloc(k * n * sizeof(double), 64);
double *C = (double*)mkl_malloc(m * n * sizeof(double), 64);

// Initialize matrices A and B with random values
for (int i = 0; i < m * k; ++i)
A[i] = static_cast<double>(rand()) / RAND_MAX;

for (int i = 0; i < k * n; ++i)
B[i] = static_cast<double>(rand()) / RAND_MAX;

auto start = std::chrono::high_resolution_clock::now();
// Perform matrix multiplication using Intel MKL
mkl_set_num_threads(4);
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, k, 1.0, A, k, B, n, 0.0, C, n);
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);

// Print the result (printing a small part for illustration)
const int printSize = 5;
std::cout << "\nMatrix A: \n";
for (int i = 0; i < printSize; ++i) {
for (int j = 0; j < printSize; ++j)
std::cout << A[i * m + j] << " ";
std::cout << "\n";
}
std::cout << "\nMatrix B: \n";
for (int i = 0; i < printSize; ++i) {
for (int j = 0; j < printSize; ++j)
std::cout << B[i * m + j] << " ";
std::cout << "\n";
}
std::cout << "Result (showing first " << printSize << " elements):\n";
for (int i = 0; i < printSize; ++i) {
for (int j = 0; j < printSize; ++j)
std::cout << C[i * n + j] << " ";
std::cout << "\n";
}
std::cout << "Execution Time: " << duration.count() << " seconds" << std::endl;
// Deallocate memory
mkl_free(A);
mkl_free(B);
mkl_free(C);

return 0;
}
Compileg++ -o code code.cpp -I /opt/intel/oneapi/mkl/latest/include/ -L /opt/intel/oneapi/mkl/latest/lib/ -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
 
Execute: ./code
 
Is this a bug or it is meant to work like this? 
 
Thanks.
0 Kudos
1 Solution
muzamil-py
Novice
1,742 Views

SOLVED!

Thank you @Gennady_F_Intel , your answer lead towards the solution.

I used -lmkl_intel_thread intead of -lmkl_sequential. So my compile command was:
g++ -o code code.cpp -I/opt/intel/oneapi/mkl/latest/include -L/opt/intel/oneapi/mkl/latest/lib -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lpthread -lm -ldl

BUT it was giving a new error which was as follows: 

/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_critical_with_hint'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_critical'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float8_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_4'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_master'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_fini'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_4u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_reduce'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_flush'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_8u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_8u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_4'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_fork_call'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_push_num_threads'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_ordered'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_omp_task_alloc'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_8u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_barrier'

/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_cmplx8_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_omp_task'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_global_thread_num'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_4'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_critical'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_serialized_parallel'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_fixed4_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_omp_task_with_deps'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_reduce_nowait'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float4_max'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_master'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_single'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_fini_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_4u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_fixed8_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_cmplx4_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_ok_to_fork'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_single'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_4u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_ordered'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_reduce_nowait'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_serialized_parallel'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float4_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float8_max'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_reduce'
collect2: error: ld returned 1 exit status

So here are some changes I made which resolved this error: 
1. Used icpx -fsycl as my compiler.

2. Added -liomp5 flag. Reference: Intel MKL Thread 

After this my code compiled successfully and executed on max threads or any specified number of threads. 

My Final Build Command for the same code is now: 

icpx -fsycl -o code code.cpp -I/opt/intel/oneapi/mkl/latest/include -L/opt/intel/oneapi/mkl/latest/lib -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lm -ldl -liomp5 -lpthread

View solution in original post

0 Kudos
5 Replies
Gennady_F_Intel
Moderator
1,790 Views

You have to link this test against -lmkl_intel_thread instead of -lmkl_sequential.  

0 Kudos
muzamil-py
Novice
1,743 Views

SOLVED!

Thank you @Gennady_F_Intel , your answer lead towards the solution.

I used -lmkl_intel_thread intead of -lmkl_sequential. So my compile command was:
g++ -o code code.cpp -I/opt/intel/oneapi/mkl/latest/include -L/opt/intel/oneapi/mkl/latest/lib -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lpthread -lm -ldl

BUT it was giving a new error which was as follows: 

/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_critical_with_hint'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_critical'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float8_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_4'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_master'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_fini'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_4u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_reduce'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_flush'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_8u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_8u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_4'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_fork_call'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_push_num_threads'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_ordered'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_omp_task_alloc'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_8u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_barrier'

/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_cmplx8_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_omp_task'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_global_thread_num'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_4'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_critical'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_serialized_parallel'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_fixed4_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_omp_task_with_deps'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_reduce_nowait'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float4_max'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_master'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_single'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_fini_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_4u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_fixed8_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_cmplx4_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_ok_to_fork'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_single'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_4u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_ordered'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_reduce_nowait'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_serialized_parallel'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float4_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float8_max'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_reduce'
collect2: error: ld returned 1 exit status

So here are some changes I made which resolved this error: 
1. Used icpx -fsycl as my compiler.

2. Added -liomp5 flag. Reference: Intel MKL Thread 

After this my code compiled successfully and executed on max threads or any specified number of threads. 

My Final Build Command for the same code is now: 

icpx -fsycl -o code code.cpp -I/opt/intel/oneapi/mkl/latest/include -L/opt/intel/oneapi/mkl/latest/lib -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lm -ldl -liomp5 -lpthread

0 Kudos
muzamil-py
Novice
1,742 Views

Thank you @Gennady_F_Intel , your answer led towards solution.

I replaced -lmkl_sequential with -lmkl_intel_thread but I was still getting an error.

Error:

/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_critical_with_hint'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_critical'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float8_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_4'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_master'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_fini'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_4u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_reduce'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_flush'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_8u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_8u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_4'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_fork_call'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_push_num_threads'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_ordered'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_omp_task_alloc'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_8u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_barrier'

/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_cmplx8_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_omp_task'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_global_thread_num'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_4'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_critical'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_serialized_parallel'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_fixed4_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_omp_task_with_deps'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_reduce_nowait'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float4_max'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_master'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_single'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_fini_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_4u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_8'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_fixed8_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_cmplx4_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_ok_to_fork'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_single'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_4u'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_ordered'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_end_reduce_nowait'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_serialized_parallel'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float4_add'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float8_max'
/usr/bin/ld: /opt/intel/oneapi/mkl/latest/lib/libmkl_intel_thread.so: undefined reference to `__kmpc_reduce'

To solve this: 

  1. I used icpx compiler instead of g++.
  2. added -liomp5 flag. (Reference to this change: Intel MKL Thread)

After appending these changes my code successfully compiled and executed with multiple threads.

My final build command now is: 

icpx -fsycl -o test test.cpp -I/opt/intel/oneapi/mkl/latest/include -L/opt/intel/oneapi/mkl/latest/lib -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lm -ldl -liomp5 -lpthread

0 Kudos
muzamil-py
Novice
1,756 Views

@Gennady_F_Intel I found a solution but upon posting it, it is being marked spam. Tried posting 2 times.

0 Kudos
muzamil-py
Novice
1,752 Views

Thank you @Gennady_F_Intel , your answer led towards solution.


I used -lmkl_intel_thread intead of -lmkl_sequential. So my compile command was:
g++ -o code code.cpp -I/opt/intel/oneapi/mkl/latest/include -L/opt/intel/oneapi/mkl/latest/lib -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lpthread -lm -ldl

I replaced -lmkl_sequential with -lmkl_intel_thread but I was still getting an error.

Errorcollect2: error: ld returned 1 exit status (Screenshot Attached.)

To solve this: 

  1. I used icpx compiler instead of g++.
  2. added -liomp5 flag. (Reference to this change: Intel MKL Thread)

After appending these changes my code successfully compiled and executed with multiple threads.

My final build command now is: 

icpx -fsycl -o test test.cpp -I/opt/intel/oneapi/mkl/latest/include -L/opt/intel/oneapi/mkl/latest/lib -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lm -ldl -liomp5 -lpthread

0 Kudos
Reply