Skip to content

Instantly share code, notes, and snippets.

@benfasoli
Created May 30, 2018 01:08
Show Gist options
  • Save benfasoli/c36b9d517c333685d1e50b9676d892ea to your computer and use it in GitHub Desktop.
Save benfasoli/c36b9d517c333685d1e50b9676d892ea to your computer and use it in GitHub Desktop.
Verify that a list column of a data frame is passed through rslurm::slurm_apply to mapped function
# Ben Fasoli
# Check that rslurm::slurm_apply accepts a list as a dataframe column
library(rslurm)
slurm_options <- list(
time = '300:00:00',
account = 'lin-kp',
partition = 'lin-kp'
)
fun <- function(x, y) {
str(y)
m <- matrix(1:(x * y), nrow = x, ncol = mean(y))
mean(m)
}
args <- data.frame(x = 1:100, y = 1:100)
args$y <- as.list(args$y)
args$y <- lapply(args$y, function(x) c(x, 10*x))
# Remove previous _rslurm dumps
system('rm -r _rslurm_*')
# Run fun on each row of args
output <- slurm_apply(fun, args, nodes = 1,
cpus_per_node = 16, slurm_options = slurm_options)
# Pause while slurm job completes
wait_for_slurm <- function(slr_job) {
cmd <- paste('squeue -hn', slr_job$jobname)
while (length(system(cmd, intern = T)) > 0) {
Sys.sleep(1)
}
}
wait_for_slurm(output)
# Grab slurm dump of the structure of argument y
id <- dir('.', '_rslurm')
system(paste('head', (file.path(id, 'slurm_0.out'))))
# num [1:2] 1 10
# num [1:2] 17 170
# num [1:2] 33 330
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment