tag-gettingstarted:
A simple tutorial on how to build and run the serial and parallel versions of
MFEM together with GLVis. For more details, see the
INSTALL file and
make help.
In addition to the native build system described below, MFEM packages are also available in the following package managers:
MFEM can also be installed as part of
A pre-built version of MFEM is also available in a container form, see our AWS tutorial and the mfem/containers repo.
Download MFEM and GLVis
Below we assume that we are working with versions mfem-4.5 and glvis-4.2.
Put everything in the same directory:
~> ls
glvis-4.2.tgz mfem-4.5.tgzBuild the serial version of MFEM:
~> tar -zxvf mfem-4.5.tgz
~> cd mfem-4.5
~/mfem-4.5> make serial -j
~/mfem-4.5> cd ..Build GLVis:
~> tar -zxvf glvis-4.2.tgz
~> cd glvis-4.2
~/glvis-4.2> make MFEM_DIR=../mfem-4.5 -j
~/glvis-4.2> cd ..That's it! The MFEM library can be found in mfem-4.5/libmfem.a, while the
glvis executable will be in the glvis-4.2 directory.
Note: as of version 4.0, GLVis has additional dependencies that need to be installed first, see its building documentation.
To start a GLVis server, open a new terminal and type
~> cd glvis-4.2
~/glvis-4.2> ./glvisThe serial examples can be built with:
~> cd mfem-4.5/examples
~/mfem-4.5/examples> make -jAll serial examples and miniapps can be built with:
~> cd mfem-4.5
~/mfem-4.5> make all -jDownload hypre and METIS from
Note: We recommend MFEM's mirror of metis-4.0.3 and metis-5.1.0 above because the
METIS webpage,
is often down and we don't support yet the new
GitHub repo.
Below we assume that we are working with hypre-2.26.0 and metis-4.0.3
(see below for METIS version 5 and later). We also assume that the serial version
of MFEM and GLVis have been built as described above.
Put everything in the same directory:
~> ls
glvis-4.2/ hypre-2.26.0.tar.gz metis-4.0.3.tar.gz mfem-4.5/Build hypre:
~> tar -zxvf hypre-2.26.0.tar.gz
~> cd hypre-2.26.0/src/
~/hypre-2.26.0/src> ./configure --disable-fortran
~/hypre-2.26.0/src> make -j
~/hypre-2.26.0/src> cd ../..
~> ln -s hypre-2.26.0 hypreBuild METIS:
~> tar -zxvf metis-4.0.3.tar.gz
~> cd metis-4.0.3
~/metis-4.0.3> make OPTFLAGS=-Wno-error=implicit-function-declaration
~/metis-4.0.3> cd ..
~> ln -s metis-4.0.3 metis-4.0(If you are using METIS 5, see the instructions below.)
Build the parallel version of MFEM:
~> cd mfem-4.5
~/mfem-4.5> make parallel -j
~/mfem-4.5> cd ..Note that if hypre or METIS are in different locations, or you have different
versions of these libraries, you will need to update the corresponding paths in
the
config/defaults.mk
file, or create you own config/user.mk, as described in the
INSTALL file.
The parallel examples can be built with:
~> cd mfem-4.5/examples
~/mfem-4.5/examples> make -jThe serial examples can also be built with the parallel version of the library, e.g.
~/mfem-4.5/examples> make ex1 ex2All parallel examples and miniapps can be built with:
~> cd mfem-4.5
~/mfem-4.5> make all -jOne can also use the parallel library to optionally (re-)build GLVis:
~> cd glvis-4.2
~/glvis-4.2> make clean
~/glvis-4.2> make MFEM_DIR=../mfem-4.5 -jThis, however, is generally not recommended, since the additional MPI thread can interfere with the other GLVis threads.
Build METIS 5:
~> tar zvxf metis-5.1.0.tar.gz
~> cd metis-5.1.0
~/metis-5.1.0> make BUILDDIR=lib config
~/metis-5.1.0> make BUILDDIR=lib
~/metis-5.1.0> cp lib/libmetis/libmetis.a libBuild the parallel version of MFEM, setting the options MFEM_USE_METIS_5 and
METIS_DIR, e.g.:
~> cd mfem-4.5
~/mfem-4.5> make parallel -j MFEM_USE_METIS_5=YES METIS_DIR=@MFEM_DIR@/../metis-5.1.0To build the CUDA version of MFEM, one needs to specify the CUDA compute capability, with the CUDA_ARCH flag. In the examples below we use CUDA_ARCH=sm_70 to build the MFEM serial and parallel versions for compute capability 7.0 (V100).
Build the serial CUDA version of MFEM:
~/mfem> make cuda CUDA_ARCH=sm_70 -jBuild the parallel CUDA version of MFEM:
~/mfem> make pcuda CUDA_ARCH=sm_70 -jTo use hypre with CUDA support in MFEM, follow the instructions above but configure it with the following command, specifying the CUDA compute capability:
~/hypre-2.26.0/src> ./configure --with-cuda --with-gpu-arch="70" --disable-fortranTo build the HIP version of MFEM, one needs to specify the HIP architecture, with the HIP_ARCH flag. In the examples below we use HIP_ARCH=gfx908 to build the MFEM serial and parallel versions for gfx908 (MI100).
Build the serial HIP version of MFEM:
~/mfem> make hip HIP_ARCH=gfx908 -jBuild the parallel HIP version of MFEM:
~/mfem> make phip HIP_ARCH=gfx908 -jTo use hypre with HIP support in MFEM, follow the instructions above but configure it with the following command, specifying the HIP architecture:
~/hypre-2.26.0/src> ./configure --with-hip --with-gpu-arch="gfx908" --disable-fortranIf Spack is already available on your system and is visible in your PATH, you can install the MFEM software simply with:
spack install mfemTo enable package testing during the build process, use instead:
spack install -v --test=all mfemIf you don't have Spack, you can download it and install MFEM with the following commands:
git clone https://github.com/spack/spack.git
cd spack
./bin/spack install -v mfem