Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

How to bind just one thread to run my code?

tang__chao
Beginner
2,905 Views

Hi,

I have tried to use KEY_CPU_BIND_THREAD to be NO,but doesn't work.

This is my code:

        std::map<std::string, std::string> config;
        config[PluginConfigParams::KEY_CPU_BIND_THREAD] = PluginConfigParams::NO;

        auto executable_network = plugin.LoadNetwork(network, config);

When I run the sample_ssd code,all of the CPU will be used.So I want to use one thread to run one code.

Could someone tell me how to solve it?

Thanks very much!

0 Kudos
1 Solution
Jeffrey_M_Intel1
Employee
2,905 Views

THe OpenVINO CPU plugin, MKLDNN, uses OpenMP for threading.  This means you can use standard OpenMP controls.  For example,

export OMP_NUM_THREADS=1

means that MKLDNN will only run on 1 thread.  You can further control behavior with tools like numactl and taskset, as you would with any other CPU application.

View solution in original post

0 Kudos
3 Replies
Jeffrey_M_Intel1
Employee
2,906 Views

THe OpenVINO CPU plugin, MKLDNN, uses OpenMP for threading.  This means you can use standard OpenMP controls.  For example,

export OMP_NUM_THREADS=1

means that MKLDNN will only run on 1 thread.  You can further control behavior with tools like numactl and taskset, as you would with any other CPU application.

0 Kudos
Kranauskas__Justas
2,905 Views

Hello,

Can we control this from the code, i.e. without setting environment variable? For the record, adding the line "omp_set_num_threads(1);" to the top of classification sample does not change a thing.

0 Kudos
Lourenco__Miguel
Beginner
2,905 Views

Hello all,

I am facing the same issues regarding OpenVino single thread execution. From what I saw, once I load the network 2 threads are launched, but I would like to avoid this behaviour.

Is there any way to do it? omp_set_num_threads() and a set of other variables (KEY_CPU_THREADS_NUM, KEY_CPU_BIND_THREAD) without any success.

Looking forward for your help.

Miguel

 

0 Kudos
Reply