Submit a CmdStan Job
This example shows how to run a CmdStan model using Slurm.
1 Example Stan model
Create normal.stan:
data {
int<lower=0> N;
array[N] real y;
}
parameters {
real mu;
real<lower=0> sigma;
}
model {
y ~ normal(mu, sigma);
}2 Compile the model
If CmdStan is available in your environment:
make normalor use CmdStanR from R.
3 Example Slurm script for CmdStan
Create run-cmdstan.sh:
#!/bin/bash
#SBATCH --job-name=cmdstan-test
#SBATCH --cpus-per-task=4
#SBATCH --mem=8G
#SBATCH --output=cmdstan-test.out
#SBATCH --error=cmdstan-test.err
export STAN_NUM_THREADS=$SLURM_CPUS_PER_TASK
./normal sample data file=data.json output file=output.csv4 Submit the job
sbatch run-cmdstan.sh5 Check output
cat cmdstan-test.out6 Notes
CmdStan models can use multiple CPU threads when the model and settings support threading.
Only request multiple CPUs if your model can use them.