1. 1. Run COMSOL on server
How to use COMSOL on server

This note is to show the way of using COMSOL on our server (ubuntu). We hope that we can run them with bash code in background and after we logout or exit the server the simulations will continue. We also need to know the simulation progress from a log file. These needs can all be satisfied only if you write proper bash code.

Run COMSOL on server

If you want to run COMSOL on server, you can use the command of the following form

nohup comsol batch -inputfile <inputfilename> -outputfile <outputfilename> -batchlog <logfilename> -np <number of cores> -study <study tag> l&

above command shows the smallest example and the “< >” isn’t included in the actual terminal command. The form nohup <command> & is used to execute the command in the background even if we logout from the server. To avoid confusion, I give a more specific example, If we want to simulate the file “test.mph”, then the command should be as follows

nohup comsol batch -inputfile test.mph -outputfile test_out.mph -batchlog test.log -np 30 &

In above example we use 30 cores (set with “-np 30”)to simulate our mph file. If we have many mph files to simulate, we can write a bash code to arrange our simulation works. We create a file with the name “” with the following content

#! /bin/bash
nohup comsol batch -inputfile test1.mph -outputfile test1_out.mph -batchlog test1.log -np 30 &&
nohup comsol batch -inputfile test2.mph -outputfile test2_out.mph -batchlog test2.log -np 30 &&
nohup comsol batch -inputfile test3.mph -outputfile test3_out.mph -batchlog test3.log -np 30 &

Above code will simulate the file “test1.mph”, “test2.mph”, “test3.mph” respectively. The “&&” at the end of the line will let the server to execute the next command only when this command complete. if you use “&” then all the mission will simultaneously execute. You need upload the “” file to the correct folder and make it executable

chmod +x ./

then in the corresponding folder type


The simulation will begin and you can see the progress from the log file by typing vi test.log.

If you write the bash code on windows then upload the file to the server, when you try to run the bash file there may be error: “/bin/bash^M:bad interpreter:No such file or directory“, this is because of the difference of coding in Unix and Windows. You can use the following command in the corresponding folder to fix it

sed -i -e 's/\r$//' ./

if you use vi on the server to create the bash file, this error can also be avoided.

Author: Knifelee
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
  • 微信
  • 支付寶