multi threading slower than single threading on dual core. why?
I have one problem. My C application iz slower when I changed it to be a multi threaded application on dual core machine. Application is about image processing but that is not important. But it is important that this application isn't slower on single core machine.
Does anybody have any idea? What is going on? How can multi threaded application be slower than single threaded on dual core? |
Blocking among the threads maybe? Did you check CPU load on the two cores? Are they both loaded most of the time or is one of the cores idle?
|
Quote:
Does anybody have any idea? |
Quote:
Perhaps is it time for you to tell what O/S, kernel, threading library you are using, and explain why do you think your application is not the problem's root cause. |
Quote:
My OS is Kubuntu 6.06, I use POSIX threads. Application part for multi-threading is very simple, just create two threads and wait for them to finish. Threads function is same for windows and for linux, the difference is just functions that create threads and function that wait for threads(pthread_create(...) and pthread_join() for linux, and correspond for windows). Both threads work on different data(one matrix, but one thread works on one half and another on the second) so I needn't to synchronize them. Does anybody have any idea now? |
i have no idea what im talking about here, this is way over my head, but could it be because you arent using a smp kernel, so its just not ready to handle multithreading. ( my first google turned up something along these lines)
|
Quote:
|
It is certainly possible for a multi-threaded application to be slower than a single-threaded one, whether there are "dual cores" or two discrete CPUs.
There are two "bright line rules" that will help you to determine if a particular application will actually benefit from a multi-threaded implementation:
"Technically, 'So it goes.'" :rolleyes: If your application is truly designed to exploit multiple CPUs or cores, then it will truly "run faster." But if not, it may (as you have seen!) "run slower." Perhaps, much slower. |
Quote:
Quote:
Can you share your measurement methodology and results ? |
Quote:
Like I alredy said on the windows It works very good. Its faster for aboutd 30-40%. So ol important things for multhithreading is enabled. So this is not a problem. |
Quote:
The measurement methodology is using a system time. On the start of function I read the system time, and on the end again end just subtract them. Any new idea for my problem? |
There is nothing that would explain it from the few clues you post.
Can you write a small stripped down test case demonstrating the issue and post its whole source code ? |
Quote:
Now I wonder if that technically counts as two independent tasks. It seems possible thats problem that could be solved more effectively with single threading. Could vary from OS to OS. Perhaps the overhead of even loading the POSIX thread library, could buckle down a simple application. It could be for linux its best to let the operating system passively handle threads for simple applications that don't truely have independent tasks. And on windows its best to take charge. |
Looking at the task you are doing are the threads necessary? The time consuming part of the work would appear to be reading the data from hard-disk to RAM, then from RAM into CPU and then back to the hard disk, with the majority of the processing requiring data from RAM plus some processing, maybe there is more time waiting for the data to arrive from RAM to the CPU than actual processing. So what is your CPU load when you run this?
|
All times are GMT -5. The time now is 11:52 PM. |