Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6704 Discussions

Disable Multithreading (SetNumthread(1))

gregsch
Beginner
611 Views

Hi,

I'm analysing some IPP-Functions on my Dell Desktop Computer (Core2 Dual).

My intention is to compare the calculation time of imageprocessing routines

(for Example: ippiRGBToHSV ).

I'm treating two case. First, the two cores, and second only one core.

The system automaticly use two core. But to use only one is morechallenging.

My idea: If i'm using one thread (SetNumthread(1)), it is only possible for my system to use one Processor.

But this does not work. the second core is still used(system monitor).

So howcanI disable(With IPP) the second core without a workaround like:

::

SetProcessAffinityMask(::GetCurrentProcess(), processorBitMask );

thanks Gregor

0 Kudos
11 Replies
Vladimir_Dudnik
Employee
611 Views

Hi Gregor,

how can you see with system monitor that it is IPP DLL uses both cores? How intensively both cores ae loaded? Could you please provide your test case?

Note, internal threading in IPP is implemented with OpenMP API. That mean OpenMP run time will create two threads (by default on dual-core system), so called master thread and worker thread. If you do not limit number of available cores for IPP both threads will do some job. But after call ippSetNumThreads(1) function, worker thread will be placed in sleep state (not closed).

Btw, in system monitor, you can see overall system activity, including OS and other applications.

Regards,
Vladimir

0 Kudos
gregsch
Beginner
611 Views
Hey!Thanks for reply.
Im using the Taskmanager watching the operatig grade. 
Thecore is shown in two different windows. 
Here is a code examle. In this case both cores have a workload 
of approx.50% 

widthPixels = 4000;

heightPixels = 4000;

int step_B=widthPixels;

Ipp16u* HSV_image = ippiMalloc_16u_C3(widthPixels, heightPixels,&step_B);

Ipp16u* RGB_image = ippiMalloc_16u_C3(widthPixels, heightPixels,&step_B);

int step_16u = widthPixels;

IppiSize roi_16u={widthPixels, heightPixels};

ippSetNumThreads(1);

if (ippiRGBToHSV_16u_C3R(RGB_image,step_16u,HSV_image,step_16u,roi_16u)!=ippStsNoErr)

{

throw std::string("RGBtoHSV/YUV");

}

for (int i=0;i<100;i++)

{

int dt;

{

ScopeTimer timer(dt);

ippiRGBToHSV_16u_C3R(RGB_image,step_16u,HSV_image,step_16u,roi_16u);

}

}

Using ::SetProcessAffinityMask(::GetCurrentProcess(), processorBitMask );

before I start the loop, its a 90%-5%ratio.

thanks, Greg

0 Kudos
Vladimir_Dudnik
Employee
611 Views

Greg,

there is a mistake in your sample code. You have to pass image step returned by ippiMalloc function,it might differ from one you calculate by yourself because of alignment.

Regards,
Vladimir

0 Kudos
brooksharris
Beginner
611 Views
Hi,

I've got a related, or maybe its the same, question.

I've got an 8-core to develope muti-threaded apps on, but possible target machines might be be 1, 2, 4, or 8 core. I've got some of these, but its impractical to replicate and maintan the entire build envorinoment on them all.

Is there a way to actually turn off cores to mimic another (lesser) machine? Ideally there'd be an app to select how many cores to employ, but even with BIOS and reboot might be acceptable, I guess.

(Remote debugging is partly helpful here, but not the answer I'm looking for because it requires the presence of another machine)

-Brooks
0 Kudos
Vladimir_Dudnik
Employee
611 Views

Hi Brooks,

there are several options available to test multithreaded IPP application against not threaded:

1. You can link application with IPP non-threaded static libraries to compare it vs the same application, linked with either threaded IPP static libraries or IPP DLLs.

2. You may use ippSetNumThreads(1) call to disable threading. That should work in general, we will check if there is any issue in the particular function you tried, but for the rest of IPP functions that approach should work.

3. You can set environment variable OMP_NUM_THREADS=n, where n is desired number of threads to be used by OpenMP run time (1,...).

Regards,
Vladimir

0 Kudos
brooksharris
Beginner
611 Views
Thanks Vladimir, this is useful information where IPP is concerned. But these won't effect the OS itself, will they? Only the IPP components of an app, right?

I was thinking about the whole machine and OS. I've got several multi-threaded apps which use straight Win32 (CreateThread) and MFC, not IPP. So do you know a way to TURN OFF a core, as if you were running on a fewer-core machine? For example, I'm working on a four-core, then I want to make it behave EXACTLY like a two-core, in all respects, as if I'd physically remove a processor.

I know thats not strictly an IPP question, but it is a Intel question. Any other source of information you could recommend?

-Brooks
0 Kudos
Vladimir_Dudnik
Employee
611 Views

Hi Brooks,

in that case, I think, the best approach will be to turn off additional cores in BIOS settings. I'm not sure ifthere is single standard way for different manufacturers, for example, on my system there is option to disable second core in BIOS.

Regards,
Vladimir

0 Kudos
PaulF_IntelCorp
Employee
611 Views
There is a method available to limit Windows to a specific number of hardware threads. I just put this article in the KB to explain:

http://software.intel.com/en-us/articles/limiting-the-number-of-cores-of-execution-on-a-windows-system/

Paul
0 Kudos
pvonkaenel
New Contributor III
611 Views

About 2 years ago I ran into this and I think (at the time) there was a problem with using the API call to set the number of threads to 1. From the testing I ran it looked like setting the number of threads to 1 would create a single OpenMP worker thread that would perform the IPP work for you. The problem with this was if you already have multiple threads in your application all using IPP all parallel IPP calls would be serialized through the single worker thread. Does this really happen? My solution to work around this and gain more control was to statically link with IPP and not use the threading layer. Is there a way to dynamically link with IPP without the threading layer?

Thanks,
Peter
0 Kudos
matthieu_darbois
New Contributor III
611 Views
Quoting - pvonkaenel

About 2 years ago I ran into this and I think (at the time) there was a problem with using the API call to set the number of threads to 1. From the testing I ran it looked like setting the number of threads to 1 would create a single OpenMP worker thread that would perform the IPP work for you. The problem with this was if you already have multiple threads in your application all using IPP all parallel IPP calls would be serialized through the single worker thread. Does this really happen? My solution to work around this and gain more control was to statically link with IPP and not use the threading layer. Is there a way to dynamically link with IPP without the threading layer?

Thanks,
Peter

Hi,
I do all the multi-threading in my application and call ippSetNumThread(1). All goes well, I can see that the calls are not serialized in a unique worker thread. I tested this with IPP 5.3 and 6.0 dynamic libraries.

Matthieu
0 Kudos
pvonkaenel
New Contributor III
611 Views

Hi,
I do all the multi-threading in my application and call ippSetNumThread(1). All goes well, I can see that the calls are not serialized in a unique worker thread. I tested this with IPP 5.3 and 6.0 dynamic libraries.

Matthieu

That's great. Thanks for the correction.

Peter
0 Kudos
Reply