[R-sig-hpc] how to get job index into R?
k.unger at imperial.ac.uk
Tue Nov 3 14:33:17 CET 2009
Many thanks Dirk!
I actually did exactly this in my R script. The problem was that I did not know how to get the job index into R. Richard Pearson who replied earlier gave me the R command for doing this which is "Sys.getenv". Using this command I easily grab the job index number by using Sys.getenv("PBS_ARRAY_INDEX").
Dr Kristian Unger
Bioinformaticist Chernobyl Tissue Bank
Department of Histopathology
Imperial College London
Rm G02, Ground floor G Block
Du Cane Road,
London W12 0HS
From: Dirk Eddelbuettel [mailto:edd at debian.org]
Sent: 03 November 2009 12:36
To: Unger, Kristian
Cc: r-sig-hpc at r-project.org
Subject: Re: [R-sig-hpc] how to get job index into R?
On 3 November 2009 at 10:50, Unger, Kristian wrote:
| Hi there!
| I am fairly new to HPC therefore I am asking a pretty basic question. I would like to submit a job array which uses one single R script. The R script uses one dataset which I want to analyse a defined set of say 100 sets of variables. Which variables to choose should be determined by the job array index number. But how can the job index number handed over to the R script? Would this concept work out at all?
One common approach is to enumerate the set of variable or values in a data
structure and to then unroll that data.structure. E.g.
R> z <- 1:9
R> sapply(z, function(x) x^2)
 1 4 9 16 25 36 49 64 81
Conceptually, parallel computing is the same: create a data structure 'z',
and then use anything from, say, mclapply (from multicore) or parSapply (from
snow) to unroll the computing of a function over z as I did here.
See e.g. my 'Intro to HPC with R' tutorial slides for more examples.
Three out of two people have difficulties with fractions.
More information about the R-sig-hpc