Skip to content
Derek Weitzel edited this page Aug 22, 2014 · 10 revisions

A parameter sweep is a type of execution where you wish to run multiple executions of the same function with different inputs. For example if we run a simple function, say from our Intro Example:

> a <- function(s) { return (s*2) }

A parameter sweep could run the function a hundreds of times, for various values of s. GridR distributes each execution of the function onto a separate processor on the remote cluster, thereby parallelizing the execution of the calculations.

This example uses many aspects of the Intro Example. Please read that example before moving onto the Parameter Sweep Example below.

Example

In this example we want to do something very simple. For the numbers 1 to 10, we want to multiply them each by 2 and return the results. Just like in the Intro Example, we must load and initialize the GridR library:

> library(GridR)
> grid.init(service="bosco.direct", localTmpDir="tmp")

Next we will use the same function from the Intro Example:

> a <- function(s) { return (2*s) }

Like the previous example, we will run the grid.apply function. But, we will use a new feature, the batch argument.

> grid.apply("x", a, c(1:10), batch=c(1))

In the above call to grid.apply, we are telling GridR that we want to run the function a by batching the first argument (c(1) is a vector of size 1 with the first element = 1). GridR will run the function a with the arguments 1, 2, 3, ... 10. The results will be placed into the variable x as a size 10 vector.

Like before, you can view the status of the jobs with the printJobs command:

> grid.printJobs()

Running jobs:
1:x --- grid-Derek-Weitzels-MacBook-Pro-2.local-84078-2013-07-31-17-34-17-1

Once the job has completed, you can view the output by printing the variable x:

> x
[[1]]
[1] 2

[[2]]
[1] 4

[[3]]
[1] 6
...
[[10]]
[1] 20

The code for this example is available as a gist.

Next Steps

Next, you can check out the MonteCarlo example, where we use the parameter sweep ideas to calculate PI.