I am trying to test future.batchtools for parallelisation in R.
I have a small test job (run_futurebatchtools_job.R) as:
library(future)
library(future.batchtools)
# Set up the future plan to use SLURM via batchtools
plan(batchtools_slurm,
template = "Scripts/batch_tools_test/slurm_future_config.tmpl",
resources = list( partition = "small",
walltime = 86400,
memory = 1024,
ntasks = 1)
)
# Define your function
my_fun <- function(x) {
Sys.sleep(x) # Simulate heavy computation
x^2
}
# Input values
input_values <- 100:150
# Run in parallel using future_lapply
results <- future.apply::future_lapply(input_values, my_fun)
# Check results
print(results)
print(warnings())
The slurm config file (slurm_future_config.tmpl) is:
#!/bin/bash
#SBATCH --job-name=<%= job.name %>
#SBATCH --output=<%= log.file %>
#SBATCH --ntasks=<%= resources$ntasks %>
#SBATCH --mem=<%= resources$memory %>MB
#SBATCH --partition=<%= resources$partition %>
#SBATCH --time=<%= ceiling(resources$walltime / 3600) %>:00:00
module purge
module load r/4.3.3
Rscript -e 'batchtools::doJobCollection("<%= uri %>")'
The job runs as expected when I run interactive on the login node. As expected it spawns child jobs to be executed on slurm. But when I submit this parent job as a slurm job (run_futurebatchtools.sh), it fails.
#!/bin/bash
#SBATCH --job-name=futurebatchtools_test
#SBATCH --output=futurebatchtools_test.log
#SBATCH --ntasks=1
#SBATCH --time=01:00:00
#SBATCH --mem=2G
#SBATCH --partition=small
# Load R
module load r/4.3.3
# Run your R script
Rscript Scripts/batch_tools_test/run_futurebatchtools_job.R
Since it will not be possible to run the job in the login node, I need to push it to the slurm array. How can I do it? I was initially trying to use batchtools directly. What I observed was that the parent job exits the cluster leaving the child jobs running. Is this issue inheritted by future.batchtools?