Parallel processing in multi-core arquitectures

Started by
3 comments, last by DrEvil 17 years, 6 months ago
I was wondering, how can a program take control of what instructions are processed in one core or the other? There are mechanisms in place to try to make the most of the available processing power, by making a good distribution between the cores, but of course the programmer is in a better position to make assumptions and say what code can be parallel to what (assuming a programming language with such capabilities). I hope this question does not show that I'm grossly uninformed or whatever, but I would like to know if direct methods of controlling this distribution are available as assembly opcodes (or something else for that matter).
Advertisement
It's dependent upon the operating system/platform really.

If you're working on a console which has multiple cores you can set exactly which processor the thread runs on.

In Windows you can tell a thread which processors it is allowed to run on by setting it's affinity mask, but that simply limits the processors which Windows can give the thread a timeslice to. As there are usually many competing threads in windows you are much better off just letting windows decide the best place to let the thread run as the operating system has a much better idea of how to balance the threads it needs to execute.
When people were using single core CPU, they assumed they shouldn't stay in the way of OS scheduler (and expect preemptive multithreading). Assuming the scheduler isn't completely retarded, it's better to don't stay in the way.
There is also a problem called other programs on the OS, basically user might do sensitive rendering OS wouldn't be normally a retard and schedule both programs correctly, however programmer would change rules and rendering would get hickups.

As for your questions about assembly, current thread distribution is done mainly in software, thus aside a limited SSE3 instruction, there is pretty much lack of support for this (if you don't count ability of ASM programmers to write without cache into the memory).

The affinity mask setting is used when you have more than one thread that each operate on fairly independent data and would rather avoid cache misses than get maximum CPU time. In other words, setting the affinity mask can sometimes be used to improve efficiency - which may improve or degrade performance for the app depending on other issues. Particularly I have seen people sucessfully use affinity mask to set 2 threads which have slightly high mutex contention to both run only on the first processor, which basically means - for those two threads it is a single core computer. But the other thread which are more free running the remaining computing slices will be allocated however the OS wants.
This article has alot of good info for multi threaded programming
Coding For Multiple Cores on Xbox 360 and Microsoft Windows

This topic is closed to new replies.

Advertisement