Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Threads are fine, but as others have noted, you have to be highly aware of your bottlenecks. Your algorithm sounds like it would be susceptible to cache contention between multiple CPUs - this is particularly nasty because it has the potential to hit the performance of all of your threads (normally you think of using multiple threads to continue processing while waiting for slow or high latency IO operations).</p> <p>Cache contention is a very important aspect of using multi CPUs to process a highly parallelized algorithm: Make sure that you take your memory utilization into account. If you can construct your data objects so each thread has it's own memory that it is working on, you can greatly reduce cache contention between the CPUs. For example, it may be easier to have a big array of ints and have different threads working on different parts of that array - but in Java, the bounds checks on that array are going to be trying to access the same address in memory, which can cause a given CPU to have to reload data from L2 or L3 cache.</p> <p>Splitting the data into it's own data structures, and configure those data structures so they are thread local (might even be more optimal to use <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html" rel="noreferrer">ThreadLocal</a> - that actually uses constructs in the OS that provide guarantees that the CPU can use to optimize cache.</p> <p>The best piece of advice I can give you is test, test, test. Don't make assumptions about how CPUs will perform - there is a <em>huge</em> amount of magic going on in CPUs these days, often with counterintuitive results. Note also that the JIT runtime optimization will add an additional layer of complexity here (maybe good, maybe not). </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