Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes and no.. If you want to be able to program as normal, but having the system 'magically' use multiple threads, then you need to look at some of the multi-processing frameworks out there. For example: <a href="http://openmp.org/wp/" rel="nofollow noreferrer">OpenMP</a>.</p> <p>If you want to run through an array, using all your cores, code similar to this:</p> <pre><code>int main(int argc, char **argv) { const int N = 100000; int i, a[N]; #pragma omp parallel for for (i = 0; i &lt; N; i++) a[i] = 2 * i; return 0; } </code></pre> <p>Just adding the #pragma makes your code magically multi-threaded. Now, you will have to understand some restrictions, eg. you cannot use the value of one element in the processing of the next (ie you cannot set a[0] to 1, then a<a href="http://openmp.org/wp/" rel="nofollow noreferrer">1</a> to a[0]+1, etc as they'll no doubt be processed by different threads, and therefore may not be computed when you need them) or you'll get an error from the openmp compiler, but if you work within these restrictions (and there are many) then you can get what you want.</p> <p>The restrictions are what makes your ultimate goal of making your code impossible. As in my example, you simply cannot compute 1 element based on another unless the first element is already computed. This effectively means code like that <em>can only</em> be single-threaded, no matter how many cores you have. </p> <p>It also means that 80-core chips will not really take off anytime soon, not unless they are all 3Ghz general purpose processors, so you don't need to worry too much about having to code for them. Now, add-on co-processors that can crunch arrays coded like in my example, that's another matter, and I expect to see more of that in the future. You'll probably <a href="http://en.wikipedia.org/wiki/OpenCL" rel="nofollow noreferrer">use the graphics card for that kind of thing</a> and have thousands of 'cpus' instead of a mere 80.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload