[R-sig-hpc] how to get job index into R?

Unger, Kristian 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").

Best wishes

Kristian Unger

_____ 

Dr Kristian Unger

Bioinformaticist Chernobyl Tissue Bank

Department of Histopathology

Imperial College London

Rm G02, Ground floor G Block
Hammersmith Hospital
Du Cane Road, 
London W12 0HS

Tel +44-20-8383-2443

Mob +44-795-1080619

Skype kristianunger

http://www1.imperial.ac.uk/medicine/about/divisions/is/histo/
http://www.chernobyltissuebank.com


-----Original Message-----
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]  1  4  9 16 25 36 49 64 81
R> 

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.

Cheers, Dirk
 
-- 
Three out of two people have difficulties with fractions.



More information about the R-sig-hpc mailing list