Last active
August 29, 2015 14:21
-
-
Save explodecomputer/fa3e3ddea60a7cc6868a to your computer and use it in GitHub Desktop.
Batching up on BC3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
arguments <- commandArgs(T) | |
splits <- as.numeric(arguments[1]) | |
outdir <- arguments[2] | |
savefile <- arguments[3] | |
l <- list() | |
for(i in 1:splits) | |
{ | |
cat(i, "\n") | |
filename <- outdir, paste("/results", i, ".RData", sep="") | |
if(file.exists(filename)) | |
{ | |
load(filename) | |
l[[i]] <- parameters | |
} else { | |
message("Missing ", filename) | |
} | |
} | |
parameters <- rbind_all(l) | |
save(parameters, file = savefile) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main <- function() | |
{ | |
# Create parameters to test | |
parameters <- expand.grid( | |
start1 = 1:3700, | |
start2 = 1:3700, | |
treatment = c(14, 60), | |
measure1 = NA, | |
measure2 = NA | |
) | |
# Only keep days when start1 is less than or equal to start2 | |
# When start1 == start2 this is the 1 day scenario | |
parameters <- subset(parameters, start1 < start2) | |
# Parallel | |
arguments <- commandArgs(T) | |
jid <- "all" | |
outdir <- "./" | |
if(length(arguments) > 0) | |
{ | |
jid <- as.numeric(arguments[1]) | |
splits <- as.numeric(arguments[2]) | |
outdir <- arguments[3] | |
stopifnot(all(!is.na(jid), !is.na(splits), !is.na(outfile))) | |
first <- (jid - 1) * splits + 1 | |
last <- min(nrow(parameters), jid * splits) | |
parameters <- parameters[first:last, ] | |
} | |
# Set output file | |
outfile <- paste(outdir, "/results", jid, ".RData", sep="") | |
message("Running ", jid, ": ", nrow(parameters), " rows") | |
message("Saving in ", outfile) | |
for(i in 1:nrow(parameters)) | |
{ | |
message(i) | |
res <- with(parameters[i, ], | |
get_measures(start1, start2, treatment, countdata) | |
) | |
parameters$measure1[i] <- res$measure1 | |
parameters$measure2[i] <- res$measure2 | |
} | |
save(parameters, file=outfile) | |
} | |
# Get data needed to calculate measures | |
load(countdata) | |
# Write function to get measures | |
get_measures <- function(start1, start2, treatment, countdata) | |
{ | |
return(list(measure1=measure1, measure2=measure2)) | |
} | |
# Run everything | |
main() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#PBS -N jobname | |
#PBS -o job_reports/jobname-output | |
#PBS -e job_reports/jobname-error | |
#PBS -l walltime=12:00:00 | |
#PBS -t 1-1000 | |
#PBS -l nodes=1:ppn=4 | |
#PBS -S /bin/bash | |
set -e | |
echo "Running on ${HOSTNAME}" | |
if [ -n "${1}" ]; then | |
echo "${1}" | |
PBS_ARRAYID=${1} | |
fi | |
i=${PBS_ARRAYID} | |
splits=13687 | |
outdir="~/path/to/dir" | |
R --no-save --args ${i} ${splits} ${outdir} < ~/path/to/run_analysis.R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment