Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
Is it appropriate to have a program that uses a core to do an intensive calculation and another core to output the results simultaneously on a dualcore machine? can i use MPI library to do this task?

I tried multithreading on a dualcore machine with the same idea that one thread does the calculation while the other thread displaying results, but the two cores do not process simultaneously.

Thanks,
Posted

Short answer: you do not control it explicitly. The system runs several threads on several cores. Which core is loaded with which thread at each thread time spice is decided by the system threading scheduler.

However, there are ways to affect this behavior programmatically.
Remember, in almost all cases this is not recommended! The cases when it can help are very rare.

See the following Windows API: GetThreadAffinityMask/SetThreadAffinityMask, GetProcessAffinityMask/SetProcessAffinityMask and SetThreadIdealProcessor.

General information on thread affinity: http://en.wikipedia.org/wiki/Processor_affinity[^],
see also this discussion: The perils of thread affinity:
http://www.bluebytesoftware.com/blog/PermaLink,guid,8c2fed10-75b2-416b-aabc-c18ce8fe2ed4.aspx[^].

On MSDN, start here:
http://msdn.microsoft.com/en-us/library/ms685096(v=VS.85).aspx[^],
http://msdn.microsoft.com/en-us/library/ms684251(v=vs.85).aspx[^].

Again, don't interfere in thread/process affinity unless you know exactly what are you doing!

(I know just one case when modification of affinity can be helpful: working with standard hardware (typically industrial) which is "bad" in the sense that it requires extensive polling as interrupt-driven operation is node accessible via API; in this case it is beneficial to dedicate on code to some threads serving these "bad" parts of equipment, which makes other threads' timing to be more predictable.)

[EDIT]

Parallel computing is a big topic which goes well above the usage of CPU/cores.
For approaches to parallel computing, see:
http://technet.microsoft.com/en-us/library/ff919485(v=ws.10).aspx[^],
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=f9d74066-0dfd-4a38-9bad-bff5e15c9629[^],
http://academic.research.microsoft.com/Publication/1693102/on-task-mapping-optimization-for-parallel-decoding-of-low-density-parity-check-codes-on[^].

It will give you the idea on what's involved. Do your research, find some more articles.

Start with: http://en.wikipedia.org/wiki/Parallel_computing[^].

—SA
 
Share this answer
 
v6
Comments
Hans Dietrich 10-May-11 23:30pm    
Agree. Letting the system choose the processor is nearly always the right way. Great links. My 5.
Sergey Alexandrovich Kryukov 10-May-11 23:34pm    
Thank you, Hans.
--SA
fjdiewornncalwe 11-May-11 13:45pm    
A huge +5 for this one. I would encourage the OP to read this and take it to heart very carefully.
Sergey Alexandrovich Kryukov 11-May-11 14:01pm    
Thank you Marcus.
--SA
fjdiewornncalwe 11-May-11 13:46pm    
OP's comment: Thanks for all answers. I want to take the advantage of the multicore to process my program in real time or near real time. What are the approaches?

SAKryukov, I will read your links.
"but the two cores do not process simultaneously" ??


Well, depending on the "particular" of each thread there might be a delay of some kind between the thread that does the calculation and the thread that display the results.

IMO, you should get a good experience base using threads and all the synchronisation mechanisms before using something more complex (like mpi) unless you absolutly need features that it offers.

Anyway, good luck

M.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-May-11 22:00pm    
It has nothing to do with delay. In fact, all cores do work "simultaneously", but the scheduler does not have to distribute the thread on one process onto difference cores.

Please see my answer.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900