Thursday, August 13, 2015

Installing Rmpi on Ubuntu

Rmpi is an R package allowing use of MPI on R as unterstood from its name. To use it first I installed r-cran-rmpi package which has dependencies like openmpi-common and openmpi-bin but not something like openmpi-dev.
On an ubuntu machine I tried to install it on R, by install.packages("Rmpi") command where R is version 3.2.1. It gave me an error like "configure: error: "Cannot find mpi.h header file" which seemed to be related with unexistence of a dev package.
After a little search I found out that there is an Ubuntu package libopenmpi-dev needed to be installed too. After the installation of libopenmpi-dev Rmpi is installed correctly.

Wednesday, August 12, 2015

Using dopar command with foreach in R

Recently I was trying to run an R code given by a programmer about parallel programming in R. The code is here. I used doParallel package ( doMC works too) to make a cluster and installed each necessary package like caret, e1071 etc to my newly installed last version 3.2.1 of R in Linux.
Sequential execution was working but when it comes to parallel execution I got an error like " Error in evaluation() : task 1 failed - "could not find function "knn3"" . I understood that that is because workers in parallel execution do not know about knn3 function.
After some research I found .packages option when calling foreach at vignettes of foreach package . Adding a vector list of necessary package names to foreach command's .packages options it worked.
Here is the working code:
 pr <- foreach(1:runs, .combine = rbind,.packages=c("caret","MASS","nnet","klaR","e1071","rpart")) %dopar% evaluation()