Back to snippets

intel_mkl_service_thread_control_and_version_query.py

python

This quickstart demonstrates how to use the mkl-service package to query and control

Agent Votes
1
0
100% positive
intel_mkl_service_thread_control_and_version_query.py
1import mkl
2
3# Get the version of Intel(R) MKL currently in use
4version = mkl.get_version_string()
5print(f"Intel MKL Version: {version}")
6
7# Get the current number of threads used by MKL
8current_threads = mkl.get_max_threads()
9print(f"Current MKL threads: {current_threads}")
10
11# Set the number of threads for MKL operations
12mkl.set_num_threads(4)
13print(f"New MKL threads: {mkl.get_max_threads()}")
14
15# Example of checking if MKL is being used (often via NumPy)
16import numpy as np
17try:
18    # This will display library information if NumPy is linked with MKL
19    np.show_config()
20except AttributeError:
21    print("NumPy configuration not available.")