Running NONMEM

NONMEM runs can be invoked using the command line/shell script nmfe (NONMEM Front End). The script is appended with release version, e.g. nmfe75 for NONMEM v7.5. The basic use requires two arguments, model file and report file:

1
2
  nmfe75.bat model.ctl model.res # Windows
  nmfe75 model.ctl model.res # Linux/Unix

The run will output status, information, and messages on screen, to re-direct/save them, one may use

1
2
  nmfe75 model.ctl model.res >stdout.txt
  nmfe75 mycontrol.ctl myresults.res -background>console.txt

Some common additional options are listed below.

  • -rundir. The user may enter a run directory that is different from the directory in which the script is launched:

    1
    
      -rundir=c:\my_favorite_dir

    One must have all user dependent input files, control stream file, msf files, and data files, are available in that run directory.

  • -nmexec. The user may also enter an alternative name for the constructed executable. For example,

    1
    
      -nmexec=nonmem2

    specifies an alternative executable name nonmem2, than the default nonmem.exe (windows) or nonmem (Linux).

  • -xmloff stops the XML output file from being created.
  • -flushtime=x requests file updating (flushing) to occur not more than every x seconds. For example,

    1
    
      -xmloff -flushtime=10.0

    may increase the simulation speed. File flushes for the MSF system are not affected, and continue to be updated every PRINT iterations during estimation. The default setting of flushtime is 1 second, suitable for most problems, but you can change this as needed (fractional seconds are also allowed). If you prefer file updates occurring as frequently as possible, you can set flushtime to 0.0, but this could cause considerable slowing of execution for small problems and data sets.

  • Beginning in NM73, an additional feature of the execution script file is that the path to the fortran compiler system and MPI system that is appropriate for NONMEM may be retrieved from a script file that could have the following environment variables defined:

    1
    2
    3
    4
    
      compilerpath
      mpibinpath
      mpilibpath
      mpilibname

    Comments in these files are provided for instructions about each of these environment variables. These paths will be temporarily added to the front of the PATH environment variable, so that the appropriate compiler or MPI system is called to service NONMEM. In the past, conflicts with other installed fortran compilers from other applications would prevent the appropriate compiler from being used for the NONMEM system. This location file method allows NONMEM to be forced to look in a particular location.

  • -locfile specifies the location file (nmloc.bat or nmloc by convention. See util/nmlocoriginal.* as templates). For example

    1
    
      nmfe75 myfile.ctl myfile.res -locfile=nmloc.bat

    If –locfile is not specified, the nmfe7x script looks in the present working directory for nmloc.bat (windows) or nmloc (linux). If this file is not found, it looks in the top directory of the NONMEM installed directory. Thus, the file nmloc.bat (Windows) or nmloc (Linux) in the top nonmem installed directory serves as the default location file, and may be modified, or used as a template and placed in the working directory or specified in the –locfile option on the command line. If a particular environment variable in the above list is not found or is not defined, then nmfe7x will behave as in earlier versions, and rely on the presently existing PATH for finding the compiler and MPI system. The nmfe7x script will display a statement as to what path it will use.

The following applies to the experimental library release. See NONMEM Installation Guide for traditional installation instructions.

Use precompiled NONMEM library (NM761)

NONMEM is also available as pre-compiled executibles and libraries. This experimental features requires cmake and ninja build tools. User can choose according to OS and gfortran compiler version when downloading NONMEM.

Toolchain

Windows

Use WinLibs

The easiest way to use NONMEM on Windows is through WinLibs. NONMEM Windows release folder contains the winlibs package. Alternatively, user can download the library for GCC here. After obtaining the package, simply unpack it at your desired destination, then add it to Windows' PATH. That is, assume the library is at C:\path\to\winlibs, add path C:\path\to\winlibs\mingw64\bin to Windows PATH. This can be done in Windows cmd (per session)

1
  set PATH=C:\path\to\winlibs\mingw64\bin;%PATH%

or (permanently)

1
  setx PATH "%PATH%;C:\path\to\winlibs\mingw64\bin"

The NONMEM Windows release folder also contains Microsoft MPI (MSMPI) installer msmpisetup.exe should you choose to utilize MSMPI for parallel runs. You will also need to add it to the PATH. By default the installer will put mpiexec.exe to C:\Program Files\Microsoft MPI\Bin, thus one needs to do

1
  set PATH=C:\Program Files\Microsoft MPI\Bin;%PATH%

The NONMEM Windows release folder also contains Microsoft MPI SDK installer msmpisdk.msi. This is not strictly needed for MSMPI runs but for future reference.

Use MSYS2

Follow steps below should you wish to setup MSYS2 and MinGW toolchain manually.

  1. Follow https://www.mingw-w64.org/getting-started/msys2/ to install MSYS2 and C/C++ compiler.
  2. Open MSYS2 MinGW64 command line and install the Fortran compiler and Microsoft MPI

    1
    2
    
      pacman -S mingw-w64-x86_64-gcc-fortran
      pacman -S mingw-w64-x86_64-msmpi
  3. Install cmake and ninja-build

    1
    2
    
      pacman -S mingw-w64-x86_64-cmake
      pacman -S mingw-w64-x86_64-ninja

Linux

NONMEM has been tested on Ubuntu distributions. To install GNU compilers and build tools, do

1
2
3
4
5
  sudo apt update
  sudo apt install gcc
  sudo apt install gfortran
  sudo apt install cmake
  sudo apt install ninja-build

MacOS

NONMEM has been tested on MacOS (Apple Silicon). To install GNU compilers, one can either use Xcode (assume Xcode installed)

1
  xcode-select --install

or homebrew

1
  brew install gcc

To install build toolchain, do

1
2
  brew install cmake
  brew install ninja

Build and run

To use the pre-compiled NONMEM, follow the common "configure-build-install" process.

  1. Create a build directory at, say /path/to/build,

    1
    
      mkdir /path/to/build && cd /path/to/build
  2. Assume NONMEM is located at /path/to/nonmem, to build a model at /path/to/model/model-name.ctl, in the build directory, do

    1
    2
    3
    4
    5
    6
    
      # configure
      cmake /path/to/nonmem -B. -GNinja -Dmodel=/path/to/model/model-name.ctl
      # build
      cmake --build . -j4		# -j4: use 4 threads to build faster
      # install
      cmake --install .

    One can use additional cmake options to customize build. For example, to use a specific compiler, say, gcc-15, one can do

    1
    
      cmake ../nonmem -B. -GNinja -Dmodel=/path/to/model/model-name.ctl -DCMAKE_Fortran_COMPILER=gfortran-15 -DCMAKE_C_COMPILER=gcc-15

    After installation, an executible with the same name as the model (in the above example it will be "model-name.exe" for Windows, and "model-name" for other OS) is available at path /path/to/model/.

  3. To run the model, do

    1
    2
    3
    4
    5
    
      cd /path/to/model/
      # Windows
      model-name.exe model-name.ctl output -licfile=/path/to/license/nonmem.lic
      # Linux & MacOS
      ./model-name model-name.ctl output -licfile=/path/to/license/nonmem.lic

    Previously mentioned executible options apply.

Custom build script

User can simplify the workflow by using nonmem/util/nmf2.sh (Linux/MacOS) or nonmem/util/nmf2.bat (Windows) scripts. These are thin wrappers of the above cmake procedures. One can look up the options by running script without arguments:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
C:\path\to\build>nmf2.bat
Usage: nmf2.bat model_file [options]...

Options:

-licfile=: specify license path. If not set nm_dir is used.
-background: run in the background.
-prdefault: use default arrays sizes.
-tprdefault: test if '-prdefault' is applicable. If so, run with it.
-maxlim=0|1|2|3: LIM size levels for array sizes.
-nodes=: number of cores in MPI run. If given the run will assume '-parafile=LOCALNODE'.
-xmloff: turn off xml file output.
-parafprint=: iteration intervals between printing in parallel runs.
-simparon: parallelize simulations in addition to estimations.
-flushtime=: lower limit of output file update interval (seconds).
-dde: augment control stream file for delay differential equation models.
-do2test: check control stream for analytical 2nd derivatives.
-nobuild: do not build executable.
-mpi_home=: home dir of MPI library. Used by cmake to locate MPI.

To use the script, copy it from nonmem/util to your build path, and set the build_dir (cmake build path, default to current path), nm_dir (NONMEM path), and lfile (NONMEM license path) by editing the file. To build and run a model, do

1
nmf2.bat \path\to\model.ctl \path\to\output_result.res

Parallel run with MPI

See MPI run entry regarding MPI build and parallel runs.