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 contact bisonnet@bucknell.edu about creating a scratch directory for you to store these files. Once your scratch directory has been created, create two directories inside that folder with a command like the following (substitute your Bucknell username, e.g. abc123, where appropriate below):

mkdir /scratch/bucknellusername/comsoltmp /scratch/bucknellusername/comsolrecovery

Then your COMSOL command should reference these directories:

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

Keep in mind that the scratch area has a quota so you will need to periodically remove files that COMSOL leaves behind in your scratch directories.

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=16384 # total memory in MB
#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 /scratch/bucknellusername/comsoltmp -recoverydir /scratch/bucknellusername/comsolrecovery