Running COMSOL Multiphysics > The COMSOL Commands > COMSOL Commands on Linux

COMSOL Commands on Linux
Use the comsol command to start COMSOL products with detailed start-up options.
The general syntax of the COMSOL command is
comsol [<target>] [<options>] [<target arguments>]
where square brackets indicate optional arguments. The comsol command can be combined with optional targets to achieve various results. The table below lists the command and targets:
Start MATLAB® and connect to a COMSOL Multiphysics server
Requires LiveLinkfor MATLAB® license
The comsol command is located in the bin folder in the COMSOL installation directory.
INI Files
There is a number of .ini files in the subdirectories glnx86 and glnxa64 in the bin directory. It is sometimes recommended that you edit these files. For example, you can add options to any of the above commands by modifying the corresponding ini file. To change the option opt to value val, add the line
-Dopt=val
to the file comsol.ini. Change the file comsolbatch.ini for comsol batch, and similarly for the other COMSOL targets.
Options
You can enter various options after the comsol command and target. Table 21-14 lists the options (See [<options>] in the command syntax) available for all comsol commands. Always issue these options between the command and the target (if any).
-docroot <path>
-np <no. of cores>
-numasets <no. of sets>
-numafirst <numa number>
-mpmode throughput | turnaround | owner
-blas {auto} | mkl | acml | path
-nn <no. of nodes>
-nnhost <no. of nodes>
-mpi {auto} | intel | mpich2 | wccs2003 | whpc2008 | user | path
-mpipath <path>
-mpiroot <path>
-mpibootstrap {ssh} | rsh | fork | slurm | ll | lsf | sge | jmi
-scalapack {auto} | mpich2 | wccs2003 | whpc2008 | user | path
-tmpdir <path>
-version <target>
-data <path>
For the -tmpdir option, the COMSOL Multiphysics software uses the specified directory to store temporary files. Use the -prefsdir option to specify the directory where COMSOL Multiphysics stores the preference file.
Documentation and Application Libraries Root Directories
In a default COMSOL Multiphysics installation, the documentation files are located in the directory doc under the installation root directory. You can use the -docroot option if you want to move the documentation directory to a different location. Similarly, use the -applicationsroot option if you want to move the Application Libraries root directory applications from its default location under the COMSOL Multiphysics installation root. Relocating the documentation and Application Libraries root directories can be useful for administering Application Library Update; see The Application Library Update Window.
Shared-Memory Options
Use the option -np to control the number of cores used. The default is to use all available cores (processing units).
Use the option -numasets to control the number of Non-uniform memory access (NUMA) node sets that the COMSOL software should take into account. This is usually the number of processor sockets that the hardware is using. If you only set the -np option, the number of sockets is determined automatically so that sufficient number of sockets are used by default.
You can also specify the number of cores and sockets as a preference on the Multicore and Cluster Computing page in the Preferences dialog box. To specify those numbers manually, select the Number of cores and Number of sockets check boxes to enter a number in the associated text fields. By default, all cores are used and the number of sockets are set automatically. If you lower the number of cores, it is good practice to also lower the number of sockets.
Sometimes you might want to experiment to find the options that work best for your configuration.
BLAS Options
BLAS is a set of functions for basic linear algebra operations. A large portion of the computational engine in COMSOL Multiphysics relies on BLAS. COMSOL Multiphysics provides for the following BLAS related options:
Table 21-16: COMSOL BLAS Options
Use a BLAS library specified using the option -blaspath or the environment variable COMSOL_BLAS_PATH.
Both MKL and ACML are distributed with COMSOL Multiphysics.
If you want to use a different BLAS library than the default, make sure that COMSOL Multiphysics can find the library. The simplest way for COMSOL Multiphysics to find a library is to put it in /lib/ARCH, where ARCH is the architecture (glnx86 or glnxa64), or somewhere in the standard search path. You must also provide the path to any sublibraries needed by the library. You can also set the search path to point to the directory where the library is installed. To do so, use the environment variable LD_LIBRARY_PATH. Your library must support both the standard FORTRAN LAPACK interface and the standard FORTRAN BLAS interface. If your LAPACK and BLAS interface consists of several libraries, use the path to the LAPACK library.
GCC Options
By default COMSOL Multiphysics uses the GCC libraries installed on the system. If COMSOL Multiphysics is unable to start, the software uses the GCC libraries shipped with COMSOL Multiphysics. To force COMSOL Multiphysics to use the shipped GCC libraries, use the -forcecomsolgcc option. The option -forcegcc is mainly intended for use together with the LiveLink™ for MATLAB®; use it if you are unable to make function callbacks to MATLAB.
COMSOL Commands
In additions to the options in Table 21-14, the standalone COMSOL command supports the following option.
COMSOL Multiphysics Server Commands
Use a COMSOL Multiphysics server command to start a COMSOL process ready to process computational requests. A COMSOL Multiphysics server listens for TCP/IP connections from COMSOL Multiphysics clients. A COMSOL Desktop can become a COMSOL Multiphysics client by connecting to a COMSOL Multiphysics server. The LiveLink™ for MATLAB® also needs to connect to a COMSOL Multiphysics server.
The syntax for the COMSOL Multiphysics server command is
comsol [<options>] mphserver [<target arguments>]
The following target arguments are available for a COMSOL Multiphysics server command.
-user <user>
-port <port>
Ask for login information. info means that only missing information is asked for. force resets the password. never requires that the login information is available. auto automatically creates a new username and password.
Accessing the COMSOL Multiphysics Server Computer
To access the computer running the COMSOL Multiphysics server, simply log in on the server computer by using ssh or a similar command, then enter the comsol mphserver command.
Login Information
When you start a COMSOL Multiphysics server for the first time, you are asked for a username and password. Select a username and a password, which COMSOL then uses in communications between the COMSOL Multiphysics client and the server. You must also specify a matching username and password in the Connect to Server dialog box. The software writes this login information in the subdirectory .comsol/v52a/login.properties in your home directory.
Client-Server Security Issues
COMSOL Multiphysics can operate in a client-server mode where COMSOL Multiphysics runs as a separate client and a server. The COMSOL software uses a TCP/IP connection to send data between the server and the client.
Always make sure that untrusted users cannot access the COMSOL login information. Protect the file .comsol/v52a/login.properties in your home directory. This is important when using the COMSOL Multiphysics client-server configuration. Alternatively, start the COMSOL Multiphysics server with the -passwd nostore option, and clear Remember Password when connecting to the server. This ensures that your login information is not stored on file.
Once you start a COMSOL Multiphysics server, a person with access to your login information could potentially connect to your COMSOL Multiphysics server. When a COMSOL Multiphysics client connects or disconnects from a remote computer, the COMSOL Multiphysics server displays a message. The connection from the client to the server is made with the TCP protocol.
The server and client are mutually authenticated using a challenge handshake authentication protocol, which means that login information cannot be easily obtained by someone eavesdropping on the network communication. The TCP connection between the client and the server is otherwise not encrypted. If you require encryption of the TCP connection, you can use third-party software based on protocols such as SSH or IPSEC.
To enhance security, you can limit the address range that can access the COMSOL Multiphysics server, both in your firewall and by changing the COMSOL Multiphysics server configuration. To limit the allowed address range in the server, edit the file <COMSOL Installation Directory>/bin/conf/server.xml and find the lines:
<!-- To restrict access to the COMSOL server you can uncomment the block below.
and follow the instructions. The default port for the COMSOL Multiphysics server is 2036. You can change this by using the option -port <port> when launching COMSOL and COMSOL Multiphysics server.
Documentation Security Issues
To serve the COMSOL Desktop with documentation, COMSOL Multiphysics opens a separate documentation server on the client computer when you open the documentation.
To enhance security, you can limit the address range that can access the documentation server, both in your firewall and by changing the documentation server configuration. To limit the allowed address range in the server, edit the file <COMSOL Installation Directory>/doc/help/conf/server.xml and find the lines:
<!-- To restrict access to the documentation server you can uncomment the block below.
and follow the instructions. The default port for the documentation server is 8090. You can change this by using the option -docport <docport> when launching COMSOL.
COMSOL Multiphysics Client Commands
Use a COMSOL Multiphysics client command to start a COMSOL Desktop with the Connect to Server dialog box open.
The syntax for the COMSOL Multiphysics client command is
comsol [<options>] mphclient [<target arguments>]
The following target arguments are available for a COMSOL Multiphysics client command:
-port <port>
-server <server name>
-open <file>
COMSOL Batch Commands
Use the COMSOL batch command to run COMSOL jobs without a GUI. You can run both Model MPH files and model files for Java with the COMSOL batch command. Model files for Java need to be compiled before running.
The syntax for the COMSOL batch command is
comsol [<options>] batch [<target arguments>]
Its detailed target arguments are:
-inputfile <file name>
-outputfile <file name>
-job <job tag>
-study <study tag>
-pname <parameter name>
-plist <parameter value>
-pindex <parameter indices>
-batchlog <file name>
-checklicense <filename>
-dev <filename>
Example
To use the COMSOL batch mode to solve a model, run the following command:
comsol batch -inputfile in.mph -outputfile out.mph -study std1
This command starts COMSOL Multiphysics in batch mode, solves the model in the Model MPH-file with the given file name using the active solver settings in the model, and stores the solution in the out.mph.
The -study option directs COMSOL Multiphysics to run a certain study. The study is identified by its tag. In the COMSOL Desktop, select Show Name and Tag under Model Builder Node Label to see the tags of the jobs under Study within curly braces in the Model Builder. In the model object, determine the tags of the jobs by the command model.study().tags(). You can determine the name of each study by model.study(<tag>).name() using one of the job tags.
The -job option works similar to the -study option. It directs COMSOL Multiphysics to start a certain job. The job is identified by its tag. In the model object, determine the tags of the jobs by the command model.batch().tags(). You can determine the name of each job by model.batch(<tag>).name() using one of the job tags.
The COMSOL Compile Command
The comsol compile command compiles a model file for Java for use by the COMSOL batch command or for loading class files into the GUI. The syntax for the comsol compile command is
comsol [<options>] compile [<target arguments>] <file>.java
The Java file is mandatory. The following optional target arguments are available:
-jdkroot <path>
-classpathadd <classpath>
COMSOL Cluster Commands
Use the comsol command with the option -nn <no. of nodes> to run COMSOL on clusters.
The syntax for the COMSOL cluster command is
comsol -nn <no. of nodes> [<options>] [<target>] [<target arguments>]
The following cluster commands are available:
comsol -nn <nn> batch
comsol -nn <nn> server
The preferred way of starting COMSOL cluster jobs is from the Study node in the COMSOL Desktop. If you need to start COMSOL cluster jobs from the command line, the preferred way is to use the comsol -nn <nn> batch command because the comsol -nn <nn> mphserver and comsol -nn <nn> commands require TCP/IP access from your client computer to the cluster node where COMSOL runs.
Running on Linux
COMSOL Multiphysics uses Hydra by default to initialize the MPI environment. Hydra is more scalable than MPD and it does not require any additional commands to launch.
To launch COMSOL Multiphysics with Hydra, use the command line
comsol -nn <number of compute nodes> -f <filename>
The file <filename> should contain the hostnames of the compute nodes that you intend to use. You can find out the hostname of each node from the hostname command. Each node should be listed on a separate line in the file. You can also list the IP address of each node. The file can contain more compute nodes than you intend to use.
You can set the remote node access mechanism that is used for connecting using the switch -mpibootstrap. The valid options are ssh, rsh, fork, slurm, ll, lsf, sge, and jmi. This is important if the cluster only supports a different remote node access mechanism than ssh because ssh is the default protocol used.
Use the switch -mpibootstrapexec to set the path to the remote node access mechanism such as /usr/bin/ssh.
The option -mpidebug sets the output level from MPI. The default is level 4.
You can control the network fabrics used for communication with the option -mpifabrics fabric1:fabric2 where fabric1 is one of shm, dapl, tcp, tmi, or ofa, and fabric2 is one of dapl, tcp, tmi, or ofa. Use this option if you are having trouble with the default fabrics used.
Use -mpienablex to enable Xlib forwarding. Xlib forwarding is off by default.
Previously there was a shorthand for performing the COMSOL MPI environment initialization and starting COMSOL Multiphysics. The -clustersimple option is still supported but is equivalent to the Hydra command by default; for example,
comsol -nn 4 -clustersimple
You should usually run COMSOL Multiphysics in batch mode. Use the command
comsol -clustersimple batch -inputfile input.mph -outputfile output.mph
It allows the Intel MPI library to automatically detect the number of nodes that were scheduled to the program. Restricting the number of processes with the -nn switch allows COMSOL Multiphysics to combine MPI with multithreading. This is the most efficient way to run COMSOL Multiphysics.
Using the MPD Launcher
In order to start MPI, have a file named .mpd.conf in your home directory to which you alone have access. This file should contain the single line
secretword = <your secret word here>
On Intel MPI, shipped with COMSOL Multiphysics, the .mpd.conf file is optional.
Below, the details of the individual cluster commands are described.
Before you start COMSOL Multiphysics, you must initialize the MPI environment. A so-called multiprocessing daemon (MPD) must run on each computer node that you intend to use. To start MPD on several computer nodes, enter
comsol -nn <number of compute nodes> mpd boot -f <filename>
The file <filename> should contain the hostnames of the compute nodes that you intend to use. You can find out the hostname of each node from the Linux command hostname. Each node should be listed on a separate line in the file. You can also list the IP address of each node. The file can contain more compute nodes than you actually intend to use. As an alternative to using the -f <filename> option, you can put the list of compute nodes in a file named mpd.hosts in your home directory. You can set the protocol that is used for connecting using the switch -mpirsh. The valid options are rsh and ssh. This is important if the cluster only supports ssh because rsh is the default protocol used. Make sure that all nodes were booted by listing them with the command
comsol mpd trace
Start distributed COMSOL with the -nn option. For example, enter
comsol -nn <number of computational nodes> -mpd mphserver
to start a COMSOL Multiphysics server running on a specific number of computational nodes. The number of computational nodes can exceed the number of compute nodes. Use the -nnhost option if you want to force several computational nodes on a compute node. Avoid starting more computational nodes than the total number of cores that you have available on a compute node. When you have finished using distributed COMSOL, you should take down all the MPDs. Enter the command
comsol mpd allexit
to stop all MPDs. To obtain more information about the comsol mpd commands, add the -h option to the commands, for example, comsol mpd boot -h.
Start MPD on a single computer with the command
comsol mpd mpd &
This is useful when running all computational nodes on a single multiprocessor computer or when you have difficulties attaching computational nodes because of firewalls. In the second case you can start an MPD on each node and attach them by specifying the main port and host. Use
comsol mpd trace -l
and
comsol mpd mpd --port <the port number reported> --host <the hostname reported>
You can also start COMSOL Multiphysics with the -clustersimple option. This option automatically starts and terminates the MPD daemon. It uses the mpd.hosts file in your home directory to determine what computational nodes to use.
Starting Distributed COMSOL — Linux Examples
Make sure that COMSOL Multiphysics is able to start on all nodes where you intend to run it.
A simplified version is used when the -clustersimple switch is set or the Hydra launcher is used. An example follows. Start four computational nodes on hosts listed in the file hosts using distributed COMSOL and simplified start:
comsol -nn 4 -clustersimple -f hosts alternatively
comsol -nn 4 -clustersimple -f hosts mphserver alternatively
comsol -nn 4 -clustersimple -f hosts batch -inputfile in.mph -outputfile out.mph
where -clustersimple is optional for Hydra.
MPD Examples
If you use MPD, start an MPD on a single computer. Then start distributed COMSOL on two computational nodes (on the same host) each using three processors, and finally stop the MPD:
comsol mpd mpd &
comsol -nn 2 -np 3 -mpd alternatively
comsol -nn 2 -np 3 -mpd mphserver alternatively
comsol -nn 2 -np 3 -mpd batch -inputfile in.mph -outputfile out.mph
comsol mpd allexit
The example above could be used if you have a very small model with a very large amount of parametric steps, where using mpd on a single computer might be beneficial.
Start three MPDs on the compute nodes with hostnames defined in the file myhosts. Each line in the file should specify the host address or IP-address of a node. Make sure the MPDs were correctly booted. Then start a distributed COMSOL Multiphysics server on three computational nodes, and finally stop the MPDs. First make sure that you can connect to all the computers with ssh without having to use your password (see the manual pages for ssh). Also make sure that all computers have access to the same COMSOL installation and that they are using the same Linux version. There are two options for starting a session. One more detailed and one shorthand version. An example of the detailed version:
comsol -nn 4 mpd boot -f myhosts
comsol mpd trace
comsol -nn 4 -mpd alternatively
comsol -nn 4 -mpd mphserver alternatively
comsol -nn 4 -mpd batch -inputfile in.mph -outputfile out.mph
comsol mpd allexit
MPI Options
There are several implementations of MPI. COMSOL Multiphysics is shipped with the Intel MPI library but also supports most MPI implementations based on MPICH2. It is recommended that you use the default Intel MPI library. For running COMSOL Multiphysics on a computer that has MPICH2 installed, the COMSOL software also has a compatibility mode that you can activate by adding the option -mpi mpich2. When using this option, both the variables PATH and LD_LIBRARY_PATH must include your MPI implementation. It is also possible to use other MPI libraries based on MPICH2 using the option -mpipath <path to shared library> and -mpiroot <path to root of mpi library installation>. Table 21-14 lists the MPI related options, -mpi, -mpipath, -scalapack, and -scalapackpath. Additionally, the COMSOL MPI arguments are configurable inside the COMSOL start script. To configure COMSOL to work with a job scheduler through the Cluster Computing study, you can set the options
-Dcs.precmd=<Command line>
-Dcs.postcmd=<Command line>
in the comsol.ini file. This adds commands prior to the comsol command and after the comsol command. You can add {nn} or {perhost} to any of these pre- or postcommands. This configures the Cluster Computing study to use the number of nodes and number of nodes on each host from the corresponding settings for the Cluster Computing study. For more information, see Cluster Computing.
Troubleshooting Distributed COMSOL and MPI
The Hydra launcher is the main MPI environment. The syntax for Hydra commands is
comsol [<options>] hydra [<Hydra command>] [<target arguments>]
Use the -h switch for more information about each command, typing, for example, comsol -h hydra cleanup.
COMSOL Multiphysics ships with the Intel MPI library but should be compatible with most MPICH2 compatible MPI libraries. To download the latest version of Intel MPI library runtime visit http://software.intel.com/en-us/intel-mpi-library. To run COMSOL Multiphysics with another version of Intel MPI or other MPI library, set -mpiroot to the root path of the MPI library. In case the downloaded library is not compatible with the version COMSOL uses (this should usually not be the case), also set -mpipath to the dynamically loaded library that should be used. The default of the Intel MPI library is to use ssh as communication protocol. If you require another communication protocol, use the option -mpibootstrap <protocol>. If you are using a scheduler, the Intel MPI library can often detect the environments it is running from using the -clustersimple switch, and you do not need to set up a hosts file.
If you are using a PBS or Torque scheduler, add -mpiarg -rmk -mpiarg pbs to the command line in order for Intel MPI to interpret the environment correctly. The Intel MPI library automatically tries to detect the best option for communication and uses InfiniBand if it detects it. To verify that COMSOL is using InfiniBand, check the output from the startup of COMSOL:, it should not mention TCP transfer mode.
In some cases it helps if you combine the option with the environment variable PSM_SHAREDCONTEXTS_MAX set to 1. You can control the fabrics used for communication with the option -mpifabrics fabric1:fabric2, where fabric1 is equal to fabric2 or fabric1 is shm.
If COMSOL Multiphysics aborts during start, make sure that all nodes can access the license manager and that COMSOL Multiphysics can be started on each node when not running distributed. Sometimes there is additional information in the log files located in $HOME/.comsol/v52a/configuration/comsol/*.log. If this does not help, start the MPI test program to make sure that the MPI library is working as it should using the following command:
comsol -nn <number of nodes> -f <host file> hydra mpitest
For more verbose information about the startup process when using Hydra, use -mpiarg -verbose, or set -mpidebug to a value greater than the default 4.
The MPD daemon can be used in several ways to troubleshoot problems with the comsol MPI environment. The syntax for MPD commands is
comsol [<options>] mpd [<MPD command>] [<target arguments>]
Table 21-24: COMSOL MPD COMMANDS
Use -h switch for more information about each command.
When using MPD, use the comsol mpd check command to display important information. For more verbose information about the startup process from the MPD daemon, use the -v and -d switches, set the environment variable, or set -mpidebug to a value greater than the default 4. If the MPD is booted and COMSOL Multiphysics is not starting, make sure that the MPI environment is working by running the comsol mpd mpitest command, for instance.
COMSOL MATLAB Command
Use the COMSOL matlab command to access the COMSOL API through MATLAB®. Enter:
comsol mphserver matlab [<options>]
which launches a COMSOL Multiphysics server in a console window, starts MATLAB, and connects MATLAB to the COMSOL Multiphysics server.
The following options are available for the comsol mphserver matlab command:
-mlroot <path>
-host <hostname>
-port <hostname>