Now that we have built an R shared object library that contains MPI code which is callable from R, let's investigate how to create an R package that contains a number of MPI-enabled functions, each callable from R.
Building a package for this can be useful for various reasons, including the following:
Maintainability: If each function has its own MPI setup and teardown, then you could end up with a lot of duplicate code to maintain.
Flexibility: From one invocation of MPI in your R script, you can easily call multiple, different MPI-enabled functions according to your needs.
Efficiency: If each function has its own separate shared object library, then each will go through their own
MPI_Init
/MPI_Finalize
stages when called, thus adding to the runtime.
The SPRINT package provides an R user with just such a suite of parallelized functions callable from R that exploit MPI. In the following sections, we will show you how to add your own function to the SPRINT package...