# Running Comsol jobs

It is assumed that the user has a good knowledge of Comsol and its main goal is to run simulations on the cluster that are already good to execute.

Running Comsol on the cluster can be done in two modes, interactively with the srun command or by submitting a batch script to SLURM. Since the syntax between the two is almost identical we will only give examples for the script version of the two modes.

Comsol can make efficient use of both multithreading and MPI so we will give two examples scripts that can be adapted to the user needs without too much modification (refer to link for more information about the difference between multithreading and MPI). The user needs to keep in mind that some of the optional parameters should not be changed otherwise it may interfer with others running jobs. We will indicate these options by the special variable comsol_options in the scripts. All the others options will be enumerated by the variable ComsolRunOptions.

### Running a serial or multithreaded job

Running a comsol serial or a multithreaded job on the cluster can be done with the following script. In the script, the Comsol model MPH-file for your computation would be somestudy.mph

#!/bin/bash

#SBATCH --nodes=1
#SBATCH --mem=4G
#SBATCH --mail-user=%u@oist.jp
#SBATCH --partition=compute

# define some common options such as using mkl for
# blas and lapack, -np indicates the number of processors

# create a scratch directory
tempdir=$(mktemp -d /flash/MyunitU/myprog.XXXXXX) comsol_options="-blas mkl -tmpdir${tempdir} -np ${SLURM_NPROCS} " #load the necessary modules module load intel/2019_update5 module load comsol/52 # go to the scratch directory (cd is also possible) pushd${tempdir}

# Copy the necessary files
cp ${SLURM_SUBMIT_DIR}/somestudy.mph . comsol${comsol_options} batch -inputfile somestudy.mph -outputfile somestudyout.mph -study std1 -batchlog ${tempdir}/somefile.log scp somestudyout.mph somefile.log deigo:${SLURM_SUBMIT_DIR}/

popd

It is possible to modify the option --cpus-per-task to any values between 1 to 24 (24 being the maximum number of cores available in one Sango node). Additional options can be given to the command comsol.

### Running a comsol MPI job

Running a Comsol job with MPI requires additional options. The script for running comsol jobs with MPI should look like this

#!/bin/bash

#SBATCH --mem=4G
#SBATCH --mail-user=%u@oist.jp
#SBATCH --partition=compute

# define some common options such as using mkl for
#  blas and lapack, -np indicates the number of processors

# create a scratch directory
tempdir=$(mktemp -d /flash/MyunitU/myprog.XXXXXX) comsol_options="-blas mkl -tmpdir${tempdir} -np 1 -mpi intel -mpibootstrap slurm "

module load comsol/52

# go to the scratch directory (cd is also possible)
pushd ${tempdir} cp${SLURM_SUBMIT_DIR}/model_in.mph .
comsol ${comsol_options} batch -inputfile model_in.mph -outputfile model_out.mph -study std1 -batchlog${tempdir}/somefile.log
scp model_out.mph somefile.log deigo:\${SLURM_SUBMIT_DIR}/
popd

The major difference between these two scripts is the number of tasks (MPI tasks, indicated by the option --ntasks=) and the number of processors per task (option --cpus-per-task=). These two parameters can be modified (if the number of proc per task is modified, the parameter -np should be modified to the specific value) the work flow and the command line being the same. Comsol will automatically load the required jobs so there is no need to use mpirun, mpiexec, or srun.

### Note on the graphical interface

The graphical interface will most likely crash when Comsol is run remotely on the Deigo cluster (see tips below). Although it may work in some cases, we suggest to avoid using the graphical interface from the cluster and recommend to the user to develop their model on a desktop computer and then perform the effective computation on the cluster.

##### Tips for Comsol GUI crashing with Java errors

On some clients, remote execution of Comsol GUI may crash with an error message related to Java. This is a problem related to the Java runtime embedded into the Comsol application, not to Deigo. In that case deactivate hardware acceleration into Comsol  might allow to successfully run the GUI.
Deactivation of hardware acceleration can be done either by running Comsol as follows

comsol -3Drend sw

or more permanentely by replacing the line

graphics.rendering.3drend=ogl

by

graphics.rendering.3drend=sw

into your Comsol preference file located at ~/.comsol/v50/comsol.prefs where (v50 has to be adapted to the actual Comsol version that you are using)