---
title: "Comsol Guide"
canonical: "https://kb.uconn.edu/space/SH/26034012326/Comsol%20Guide"
format: markdown
---
This how-to article explains how to load and run Comsol on HPC.

## \uD83D\uDCD8 Instructions

### comsol with MPI

To run comsol with SLURM, please create following comsol.sh:

```
#!/bin/bash

# For general partition
#SBATCH -N 1
#SBATCH -p general
#SBATCH --cpus-per-task=126
#SBATCH --ntasks-per-node=1
#SBATCH --output comsol.log

# Clear the output log
echo -n > comsol.log

# Add debugging information.
scontrol show job $SLURM_JOBID

# Details of input and output files.
INPUTFILE=/path/to/input_model.mph
OUTPUTFILE=/path/to/output_model.mph

# Load our comsol module.
module purge
module load comsol/6.2

# Run comsol.
comsol batch \
    -clustersimple \
    -np $SLURM_CPUS_PER_TASK \
    -mpifabrics shm:ofa \
    -inputfile $INPUTFILE \
    -outputfile $OUTPUTFILE \
    -tmpdir temp

```


Then submit the script by issuing:

```
$ sbatch comsol.sh

```

### comsol with GPU

```
$ ssh <NetID>@login.storrs.hpc.uconn.edu
$ module load comsol/6.2

```

To run comsol with SLURM, please create following comsol.sh:

```
#!/bin/bash

# Ask for a number of compute nodes
#SBATCH -p general-gpu
#SBATCH --gres=gpu:1
#SBATCH -N 1
#SBATCH -n 62
# Set your email address to be notified of jobs updates
#SBATCH --mail-type=ALL
#SBATCH --mail-user=your@email.address

# Details of your input and output files
INPUTFILE=/path/to/input_model.mph
OUTPUTFILE=/path/to/output_model.mph
TMPDIR=

# Load our comsol module
source /etc/profile.d/modules.sh
module purge
module load comsol/6.2

######## DO NOT EDIT BELOW THIS LINE ########
# check if tmpdir exists
if [ ! -z $TMPDIR ]; then 
  TMPDIR="-tmpdir $TMPDIR"
fi
## Now, run COMSOL in batch mode with the input and output detailed above.
comsol -3drend ogl -np $SLURM_NTASKS -inputfile $INPUTFILE -outputfile $OUTPUTFILE $TMPDIR

```

Then submit the script by issuing:

```
$ sbatch comsol.sh

```

## comsol on single node

Some comsol algorithms like PARDISO do not make use of MPI like . To run these, you can specify `-np` instead of `-clustersimple` as follows

```
#!/bin/bash

# Ask for a number of compute nodes
#SBATCH -N 1
#SBATCH -n 126

# Details of your input and output files
INPUTFILE=input_model.mph
OUTPUTFILE=output_model.mph
TMPDIR=temp

######## DO NOT EDIT BELOW THIS LINE ########

# Load our comsol module
source /etc/profile.d/modules.sh
module purge
module load comsol/6.2

## Now, run COMSOL in batch mode with the input and output detailed above.
comsol batch -np $SLURM_NTASKS -inputfile $INPUTFILE -outputfile $OUTPUTFILE -tmpdir $TMPDIR

```

Then submit the script by issuing:

```
$ sbatch comsol.sh
```


> ℹ️ Highlight important information in a panel like this one. To edit this panel's color or style, select one of the options in the menu.

## \uD83D\uDCCB Related articles



> Macro (contentbylabel)