javamultithreadingaparapi

Plain Java Thread Pool vs. Aparapi GPU for complex objects


I am evaluating whether to use a Java Thread Pool with a quad-core processor or the Aparapi GPU framework for my program.

Whereas the gain on a GPU would be nice, the speed difference between a quad-core processor and a GPU is not a knock out criterion for the algorithm. On the other hand, my program is very well structured with a lot of complex objects and - if I understand correctly - Aparapi does not support parallelization beyond primitive data types.

For those who have experience with both methods for complex objects, would you suggest to refactor the objects to primitive data types for Aparapi or to stick with a Java Thread Pool? Do I understand correctly that for a Java Thread Pool, there are not limitations for the type of objects it can deal with?


Solution

  • An ExecutorService like ThreadPoolExecutor is simply a pool of worker threads executing jobs (Runnables) pulled from a queue so there are no restriction on your objects except for the usual concurrency problems like data races and dead locks.

    If speed is very important to you then turning your objects into arrays of primitive data types and working on those arrays should be your first optimisation after introducing concurrency. If after that you want to move to the gpu then you already are on the level of primitive data structures.