As a final wrapping up, I thought I would show how you can overcome some of the inherent single-threaded nature of R even further and demonstrate a hybrid approach to parallelism that combines two of the different techniques we covered previously within a single R program. We also discussed how heterogeneous computing is potentially the way of the future.
This example refers back to the code we developed in Chapter 5, The Supercomputer in your Laptop, and will utilize MPI through pbdMPI
together with ROpenCL
to enable us to exploit both the CPU and GPU simultaneously. While this is a slightly contrived example and both devices compute the same dist()
function, the intention is to show you just how far you can take things with R to get the most out of all your available compute resource.
Basically, all we need to do is to top and tail our implementation of the dist()
function in OpenCL with the appropriate pbdMPI
initialization and termination and run the script with mpiexec...