Skip to main content

Some options are recommended when running COMSOL jobs.

Number of Processor Cores

By default, COMSOL will use all processors/cores available on the system. You’ll need to instead specify the number of cores you plan to use. The number you specify should match in both the job script and the COMSOL command:

#SBATCH -n 4 # number of cores  
comsol batch -np $SLURM_NTASKS -inputfile file.mph -outputfile file_output.mph

Temporary Files

COMSOL writes temporary files, by default, to /tmp. This directory is not very large and fills up very quickly so it’s better to create directories in your account for these temporary files. We recommend you create two directories using the following command:

mkdir ~/comsoltmp ~/comsolrecovery

Then your COMSOL command should reference these directories:

comsol batch -np $SLURM_NTASKS -inputfile file.mph -outputfile file_output.mph -tmpdir ~/comsoltmp -recoverydir ~/comsolrecovery

Full Example Job Script

Here’s a full example job script for running COMSOL

#!/bin/bash 
#SBATCH -p short # partition (queue) 
#SBATCH -N 1 # number of nodes (don't change this value)
#SBATCH -n 4 # number of cores 
#SBATCH --mem-per-cpu=8192 # memory per core 
#SBATCH --job-name="comsoljob" # job name 
#SBATCH -o slurm.%N.%j.stdout.txt # STDOUT 
#SBATCH -e slurm.%N.%j.stderr.txt # STDERR 
#SBATCH --mail-user=username@bucknell.edu # address to email 
#SBATCH --mail-type=ALL # mail events (NONE, BEGIN, END, FAIL, ALL) 

module load comsol 
comsol batch -np $SLURM_NTASKS -inputfile file.mph -outputfile file_output.mph -tmpdir ~/comsoltmp -recoverydir ~/comsolrecovery