# MFEM: finite element discretization library for scientific computing

> MFEM is a modular parallel C++ library that translates finite element problem descriptions into linear algebra objects, scaling from laptop to supercomputer. GPU acceleration was added in v4.0 via CUDA, HIP, OCCA, RAJA and OpenMP, but build instructions are in a separate INSTALL file, not the README.

**mfem/mfem** — Lightweight, general, scalable C++ library for finite element methods

- Repository: https://github.com/mfem/mfem
- Website: http://mfem.org
- Stars: 2,261 · Forks: 659
- Language: C++
- License: BSD-3-Clause
- Published: 2026-10-11 · Updated: 2026-10-11 · Language: en
- Canonical page: https://hysenlabs.com/projects/mfem-mfem

## FE discretization to linear algebra: the translation layer MFEM provides

MFEM's central abstraction is expressed directly in the README: a problem described in finite element terms enters the library and comes out as linear algebra vectors, global sparse matrices or matrix-free operators. The README calls this the finite element to linear algebra translator role. That framing is exact. MFEM does not solve physics problems by itself; it assembles the mathematical objects that solvers act on.

The analogy the README uses is instructive: MFEM provides building blocks for developing finite element algorithms in a manner similar to that of MATLAB for linear algebra methods. A team that has a weak form of a PDE can express it through MFEM's bilinear, linear and nonlinear forms, set the boundary conditions, and assemble the resulting system without writing the assembly loops by hand.

Mesh support covers the standard element types used in scientific computing: triangular, quadrilateral, tetrahedral and hexahedral elements in both 2D and 3D, as well as surface and topologically periodic meshes. High-order mesh elements with curved boundaries are supported through arbitrary element transformations. Both local conforming and non-conforming adaptive mesh refinement (AMR) are included.

The library is modular by design. Its repository top-level directories reveal the structure: fem/ for the finite element layer, linalg/ for the linear algebra layer, mesh/ for mesh operations, and general/ for common infrastructure. Each directory corresponds to a layer a caller can use directly.

## Building from source: INSTALL file and make help

Build instructions for MFEM are in the INSTALL file at the repository root, not in the README. The README points there directly: "For building instructions, see the file INSTALL, or type 'make help'." Running the following from the repository root lists the available build targets and configuration options.

```bash
make help
```

Docker images are maintained in a separate repository at mfem/containers on GitHub, which is an option for teams that want to skip the build step entirely.

The canonical starting point for learning the API after building is the examples and miniapps section of the MFEM website at https://mfem.org/examples. The repository itself contains an examples/ directory with C++ source files numbered from ex0.cpp up through ex19p.cpp. Those numbered examples serve as the official tutorials for the library.

For citation, the project carries a DOI (10.11578/dc.20171025.1248) and LLNL release number LLNL-CODE-806117, indicating its origin at Lawrence Livermore National Laboratory and membership in the RADIUSS open source initiative, which explains the broad platform target list.

## Five finite element space types and six discretization approaches

MFEM's breadth in FE spaces is what makes it more general than most domain-specific simulation codes. It supports 5 types of high-order finite element spaces: H1-conforming, discontinuous (L2), H(div)-conforming, H(curl)-conforming and NURBS, all available in 2D and 3D.

Those spaces correspond to different continuity requirements across element boundaries. H1 is the standard conforming space for problems like heat transfer or solid mechanics. L2 is the discontinuous space used in DG methods. H(div) and H(curl) are the spaces needed for Maxwell's equations and mixed formulations of fluid flow.

On the discretization side, 6 approaches are supported: Galerkin methods, mixed finite elements, Discontinuous Galerkin (DG), isogeometric analysis, hybridization and Discontinuous Petrov-Galerkin (DPG). Each of those targets a different class of problems and mathematical structure. DPG in particular is less commonly included in FEM libraries.

The combination means MFEM can cover a wide range of physical problems without requiring a separate library for each space type. A mixed formulation for incompressible flow, a DG method for hyperbolic conservation laws, and an H(curl) problem for electromagnetics can all be implemented in the same codebase.

## Paired serial and parallel examples show the minimal code change between the two

A detail visible in the examples/ file listing is that every example comes in two versions. ex1.cpp is the serial implementation; ex1p.cpp is the MPI-parallel version. That pairing continues through the numbering: ex10.cpp and ex10p.cpp, ex14.cpp and ex14p.cpp, ex15.cpp and ex15p.cpp, and so on through ex19.cpp and ex19p.cpp.

MFEM-based applications require minimal changes to switch from a serial to a highly-performant MPI-parallel version, according to the project documentation. The paired examples are the concrete demonstration of that claim. Comparing the serial and parallel versions of any example shows what changes in practice: the mesh type, the finite element space and the solver choice map to their parallel equivalents, but the structure of the assembly and the form of the weak problem do not change.

This design has a practical consequence for research workflows. A method can be prototyped on a serial workstation and then parallelized by making a bounded set of targeted changes, rather than a complete rewrite. The serial examples are also useful as documentation of what each physical problem setup involves.

ex0.cpp is listed as the simplest entry point, and the examples directory contains an ex18.hpp header that is shared between ex18.cpp and ex18p.cpp, indicating that some shared logic is explicitly factored out.

## MPI parallelism throughout the library, with integrated hypre solvers

MPI-based parallelism is not a wrapper around the serial code; it runs throughout the library. The distinction matters because it means parallel meshes, parallel FE spaces and parallel solvers are native objects, not adapted serial ones. A parallel simulation can take advantage of the integrated linear solvers from the hypre library without additional integration work.

For problems that do not require external packages, the library includes simple smoothers and Krylov solvers: PCG, MINRES and GMRES. Beyond those, sequential sparse direct solvers from the SuiteSparse library, the Newton method for nonlinear problems, LOBPCG for eigenproblems, and several explicit and implicit Runge-Kutta time integrators round out the built-in solver set.

For larger or more specialized solver needs, the external package layer connects to PETSc, SUNDIALS and libCEED, giving access to additional preconditioners, time integrators and nonlinear solvers. That integration provides access to additional preconditioners, time integrators and nonlinear solvers beyond what the built-in solver set covers.

What that support layer does not cover is automatic load balancing or mesh partitioning beyond what the underlying parallel mesh infrastructure provides. The calling code owns the decision about how the problem is distributed.

## GPU acceleration from v4.0: CUDA, HIP, OCCA, RAJA and OpenMP

GPU support arrived in version 4.0. The programming model options listed in the README are CUDA, HIP, OCCA, RAJA and OpenMP. That breadth is notable: CUDA covers NVIDIA hardware, HIP covers AMD and NVIDIA, OCCA and RAJA are portability layers that target multiple backends, and OpenMP covers CPU threading as well as some GPU models.

The intent is that the same MFEM-based code can run on different hardware without architecture-specific rewrites. That is consistent with the serial-to-parallel design principle: minimal changes in the source, significant changes in performance under the hood.

What the README does not document at the summary level is which specific FE operations are GPU-accelerated and which are not. The INSTALL file is the place to look for platform-specific build flags for the GPU backends, and the examples directory shows whether GPU-enabled examples exist for a given problem type.

The combination of MPI and GPU support means MFEM targets the full range of modern HPC hardware, from multicore workstations to GPU clusters. Whether a given code path actually uses the GPU depends on how the calling code builds and configures the library.

## What MFEM does not provide: physics interfaces, Python bindings and high-level solvers

MFEM is a discretization library, not a physics simulation framework. It assembles and represents mathematical objects; the caller decides what equations those objects represent and how to solve the resulting systems. There is no built-in Navier-Stokes solver, no radiation transport model, and no geometry-specific preprocessing. A team that needs those capabilities uses MFEM as a substrate beneath a physics code, not instead of one.

Python bindings are not mentioned in the README. The repository contains C++ source only, and the build system is a Makefile and CMakeLists.txt. A team that needs FEM in a Python environment either wraps MFEM via cffi or pybind11 themselves, or uses a Python-native FEM library such as FEniCSx.

FEniCSx is the comparison point worth naming here. FEniCSx solves the domain-specific language layer that MFEM leaves to the caller: it provides a Python API, a UFL form language for expressing weak forms symbolically, and a high-level interface that hides the assembly loop entirely. MFEM's trade is the opposite: full control over the assembly, access to more FE space types, and broader hardware support, at the cost of more C++ to write.

Available under BSD-3-Clause, the most recent release is v4.10, published on 2026-09-01.

## Conclusion

MFEM is the right tool for computational scientists and researchers in FEM who need a C++ library that handles discretization, assembly and parallel scaling without reimplementing those primitives. It is not the right layer for teams that want a high-level physics simulation interface in a language other than C++, since no Python or other non-C++ binding is documented in the README. Before adopting, read the INSTALL file for platform-specific build steps, run make help to see the available build options, and confirm your MPI and GPU toolchains match what the INSTALL file lists.

## FAQ

### What is MFEM?

MFEM is a modular parallel C++ library for finite element methods. It translates problems described in finite element terms into linear algebra objects such as sparse matrices or matrix-free operators, and supports MPI-based parallelism and GPU acceleration.

### How do I build MFEM?

Build instructions are in the INSTALL file at the repository root. Running make help from the repository root lists available build targets and configuration options. Docker images are maintained in the mfem/containers repository for teams that want to skip the build step.

### Does MFEM support GPU acceleration?

GPU acceleration was added in version 4.0 and supports CUDA, HIP, OCCA, RAJA and OpenMP. Platform-specific build flags for the GPU backends are documented in the INSTALL file.

### What mesh types does MFEM support?

MFEM supports triangular, quadrilateral, tetrahedral and hexahedral meshes, as well as surface and topologically periodic meshes, in both 2D and 3D. Local conforming and non-conforming adaptive mesh refinement (AMR) are also included.

### Does MFEM have Python bindings?

Python bindings are not mentioned in the README. The repository contains C++ source files, and the build system is a Makefile and CMakeLists.txt. A Python-native alternative is FEniCSx.

## Sources

- [License: BSD-3-Clause](https://github.com/mfem/mfem/blob/master/LICENSE)
- [mfem/mfem on GitHub](https://github.com/mfem/mfem)
- [Project website](http://mfem.org)
- [README](https://github.com/mfem/mfem/blob/master/README.md)
- [Releases](https://github.com/mfem/mfem/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/mfem-mfem
