   [java] Threading math operations
  Hi guys,I want to thread my matrix multiplication. My code would be something like:public Matrix4x4 mult(Matrix4x4 matrix4x4){    element[0] = row1.dotProduct(matrix4x4.row1);    element[1] = row1.dotProduct(matrix4x4.row2);    element[2] = row1.dotProduct(matrix4x4.row3);    ... etc}Is there anyway in Java that I can do all the dotProducts simultaneously & exit the method knowing that all the dotProducts have been completed?   
  This isn't an answer to your question - but I believe the amount of time taken to create multiple threads and waiting for them to finish is going to be much larger than the time taken to do a few dot-products.I recommend profiling (timing) the threaded and the non-threaded version of this function to see which is faster.   ;Quote:Original post by CacksIs there anyway in Java that I can do all the dotProducts simultaneously & exit the method knowing that all the dotProducts have been completed?Yes, it's the same as in any language.- Create a thread pool- Partition the array between threads (for n threads and m elements, let each thread compute m/n elements)- Wait till all threads report completionSince Java uses lightweight threads, they don't map directly to system threads, meaning efficiency of such parallelism will be poor. You will also gain no benefit unless you're using multi-core machine.To wait for threads, wait on a lock in a while loop with a counter. Let threads call notify on it. Once all threads have called notify, you can exit the while loop.There might be better synchronization primitives available in Java 6, but I haven't looked into them in detail yet.   ;  Hi guys,good point, the threading of this would make performance slower. The code would get very complicated & I would have loads of threads all fighting one another to be executed. Just going to stick with the single thread approach.Cheers   