The R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, ...) and graphical techniques, and is highly extensible.

R is a language and environment for statistical computing and graphics. R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, etc.) and graphical techniques, and is highly extensible.

One of R's strengths is the ease with which well-designed publication-quality plots can be produced, including mathematical symbols and formulae where needed. Great care has been taken over the defaults for the minor design choices in graphics, but the user retains full control.

...

...

@@ -10,11 +10,11 @@ Another convenience is the ease with which the C code or third party libraries m

Extensive support for parallel computing is available within R.

Read more on [http://www.r-project.org/][a],[http://cran.r-project.org/doc/manuals/r-release/R-lang.html][b].

Read more on [http://www.r-project.org/][a] and[http://cran.r-project.org/doc/manuals/r-release/R-lang.html][b].

## Modules

The R version 3.1.1 is available on the cluster, along with GUI interface RStudio

R version 3.1.1 is available on the cluster, along with GUI interface RStudio

The R on cluster is linked to highly optimized MKL mathematical library. This provides threaded parallelization to many R kernels, notably the linear algebra subroutines. The R runs these heavy calculation kernels without any penalty. By default, the R would parallelize to 24 (Salomon) or 16 (Anselm) threads. You may control the threads by setting the OMP_NUM_THREADS environment variable.

R on cluster is linked to a highly optimized MKL mathematical library. This provides threaded parallelization to many R kernels, notably the linear algebra subroutines. R runs these heavy calculation kernels without any penalty. By default, R would parallelize to 24 (Salomon) or 16 (Anselm) threads. You may control the threads by setting the OMP_NUM_THREADS environment variable.

### Interactive Execution

To run R interactively, using RStudio GUI, log in with ssh -X parameter for X11 forwarding. Run rstudio:

To run R interactively, using RStudio GUI, log in with the ssh -X parameter for X11 forwarding. Run RStudio:

```console

$ml RStudio

...

...

@@ -66,7 +66,7 @@ cp routput.out $PBS_O_WORKDIR/.

exit

```

This script may be submitted directly to the PBS workload manager via the qsub command. The inputs are in rscript.R file, outputs in routput.out file. See the single node jobscript example in the [Job execution section - Anselm][1].

This script may be submitted directly to the PBS workload manager via the qsub command. The inputs are in the rscript.R file, the outputs in the routput.out file. See the single node jobscript example in the [Job execution section - Anselm][1].

## Parallel R

...

...

@@ -83,7 +83,7 @@ $ R

>library(parallel)

```

More information and examples may be obtained directly by reading the documentation available in R

More information and examples may be obtained directly by reading the documentation available in R:

```r

>?parallel

...

...

@@ -91,7 +91,7 @@ More information and examples may be obtained directly by reading the documentat

>vignette("parallel")

```

The forking is the most simple to use. Forking family of functions provide parallelized, dropin replacement for the serial apply() family of functions.

The forking is the most simple to use. Forking family of functions provide parallelized, drop-in replacement for the serial apply() family of functions.

!!! warning

Forking via package parallel provides functionality similar to OpenMP construct omp parallel for

...

...

@@ -142,24 +142,24 @@ Every evaluation of the integrad function runs in parallel on different process.

## Package Rmpi

package Rmpi provides an interface (wrapper) to MPI APIs.

Package Rmpi provides an interface (wrapper) to MPI APIs.

It also provides interactive R slave environment. On the cluster, Rmpi provides interface to the [OpenMPI][3].

Read more on Rmpi [here][c], reference manual is available [here][d].

When using package Rmpi, both openmpi and R modules must be loaded

When using package Rmpi, both the openmpi and R modules must be loaded:

```console

$ml OpenMPI

$ml R

```

Rmpi may be used in three basic ways. The static approach is identical to executing any other MPI programm. In addition, there is Rslaves dynamic MPI approach and the mpi.apply approach. In the following section, we will use the number π integration example, to illustrate all these concepts.

Rmpi may be used in three basic ways. The static approach is identical to executing any other MPI program. In addition, there is the Rslaves dynamic MPI approach and the mpi.apply approach. In the following section, we will use the number π integration example, to illustrate all these concepts.

### Static Rmpi

Static Rmpi programs are executed via mpiexec, as any other MPI programs. Number of processes is static - given at the launch time.

Static Rmpi programs are executed via mpiexec, as any other MPI programs. The number of processes is static - given at the launch time.

Dynamic Rmpi programs are executed by calling the R directly. OpenMPI module must be still loaded. The R slave processes will be spawned by a function call within the Rmpi program.

Dynamic Rmpi programs are executed by calling the R directly. The OpenMPI module must still be loaded. The R slave processes will be spawned by a function call within the Rmpi program.

Dynamic Rmpi example:

...

...

@@ -277,7 +277,7 @@ workerpi()

mpi.quit()

```

The above example is the dynamic MPI example for calculating the number π. Both master and slave processes carry out the calculation. Note the mpi.spawn.Rslaves(), mpi.bcast.Robj2slave()** and the mpi.bcast.cmd()** function calls.

The above example is the dynamic MPI example for calculating the number π. Both master and slave processes carry out the calculation. Note the mpi.spawn.Rslaves(), mpi.bcast.Robj2slave(), **and the mpi.bcast.cmd()** function calls.

Execute the example as:

...

...

@@ -285,7 +285,7 @@ Execute the example as:

$mpirun -np 1 R --slave--no-save--no-restore-f pi3Rslaves.R

```

Note that this method uses MPI_Comm_spawn (Dynamic process feature of MPI-2) to start the slave processes - the master process needs to be launched with MPI. In general, Dynamic processes are not well supported among MPI implementations, some issues might arise. Also, environment variables are not propagated to spawned processes, so they will not see paths from modules.

Note that this method uses MPI_Comm_spawn (Dynamic process feature of MPI-2) to start the slave processes - the master process needs to be launched with MPI. In general, Dynamic processes are not well supported among MPI implementations, some issues might arise. In addition, environment variables are not propagated to spawned processes, so they will not see paths from modules.

Currently, the two packages cannot be combined for hybrid calculations.

Currently, the two packages cannot be combined for hybrid calculations.

## Parallel Execution

The R parallel jobs are executed via the PBS queue system exactly as any other parallel jobs. User must create an appropriate jobscript and submit via the **qsub**

R parallel jobs are executed via the PBS queue system exactly as any other parallel jobs. The user must create an appropriate jobscript and submit it via the **qsub**

Example jobscript for [static Rmpi][4] parallel R execution, running 1 process per core:

An example jobscript for [static Rmpi][4] parallel R execution, running 1 process per core: