# [R-sig-hpc] snowFT with changing arguments

Hana Sevcikova hanas at uw.edu
Mon Oct 7 11:55:40 CEST 2013

```Duncan,

What you can do is to pass a number (or character string) that would
tell the process which iteration it is. Then the slicing would happen in
the child process. I.e.

res <- performParallel(p, 1:r, fun=fun, ...)

fun <- function(i, ...) {
n = list(c(1000, 0, 1), c(2000, 1, 1), c(3000, 2, 1))[[i]]
...
}

or with character strings:
res <- performParallel(p, c('first', 'second', 'third'), fun=fun, ...)

fun <- function(i, ...) {
n = list(first=c(1000, 0, 1), second=c(2000, 1, 1), third=c(3000, 2,
1))[[i]]
...
}

Hana

On 06/10/2013 21:51, Duncan Wadsworth wrote:
> Hello,
> I'm trying to pass different arguments to each of the initiated processes using snowFT.  In the examples for performParallel() we have## Not run:
> # generates n normally distributed random numbers in r replicates
> # on p nodes and prints their mean after each r/10 replicate.
>
> printfun <- function(res, n, args=NULL) {
>    res <- unlist(res)
>    res <- res[!is.null(res)]
>    print(paste("mean after:", n,"replicates:", mean(res),
>             "(from",length(res),"RNs)"))
>    }
>
> r<-1000; n<-100; p<-5
> res <- performParallel(p, rep(n,r), fun=rnorm,
>    gentype="RNGstream", seed=rep(1,6), printfun=printfun)
>
> # Setting p<-0 will run rnorm sequentially and should give
> # exactly the same resultsbut I'd like to use a matrix or list or ideally a dataframe so I can pass different string arguments with the n.  For example, I'd like to pass different values for n, mean, and sd in rnorm(), i.e. something like:
> n = list(first = c(1000, 0, 1), second = c(2000, 1, 1), third = c(3000, 2, 1))r = 96
> It's possible to do:
> n = c(1, 10, 100, 1000)r = 96
> but that only allows me to change the first argument to rnorm().
> Any ideas?
> Thanks.
>
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-hpc mailing list
> R-sig-hpc at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc
>

```