AMReX Documentation

repository·development·Indexed 21 days ago

https://github.com/amrex-codes/amrex

A high-performance software framework for massively parallel block-structured adaptive mesh refinement (AMR) applications, primarily used for solving partial differential equations in scientific simulations. AMReX supports C++ and Fortran interfaces, GPU acceleration via CUDA, HIP, and SYCL, and various parallelization models including MPI and OpenMP. It provides capabilities for hyperbolic, parabolic, and elliptic solvers, as well as support for particles and embedded boundary descriptions.

Tokens
114.8K
Snippets
278
Records
445
Agent score
72%

What's inside AMReX

  1. Overview of AMReX framework capabilities

    development

    AMReX is a C++ software framework designed for developing block-structured adaptive mesh refinement (AMR) algorithms. It is used to solve systems of partial differential equations (PDEs) with complex boundary conditions on current and emerging architectures (CPUs and GPUs).

    Key capabilities include:

    • Adaptive Mesh Refinement (AMR): Reduces computational cost and memory footprint by using a non-uniform mesh hierarchy.
    • Multi-language Support: Core data structures and operations are in C++, but a Fortran-interface allows applications to be written entirely in Fortran.
    • Interoperability: Provides interfaces to popular scientific libraries such as SUNDIALS, PETSc, and hypre.
    • Complex Geometries: Supports the cut cell / embedded boundary approach for discretizing complex shapes using face apertures, normals, and volume fractions.
    • Parallelism: Uses an MPI+X strategy. On CPUs, it typically uses MPI + OpenMP. On GPUs, it uses MPI + CUDA, while also supporting OpenACC and OpenMP for offloading subroutines.
  2. Overview of AMReX features and capabilities

    development

    AMReX is a software framework for massively parallel block-structured adaptive mesh refinement (AMR) applications, specifically designed for solving partial differential equations (PDEs) on hierarchical adaptive grids.

    Key capabilities include:

    • Multi-language support: C++ and Fortran interfaces.
    • Data types: Support for cell-centered, face-centered, edge-centered, and nodal data.
    • PDE Solves: Support for hyperbolic, parabolic, and elliptic solvers.
    • Time-stepping: Optional subcycling in time for time-dependent PDEs.
    • Physics features: Support for particles and embedded boundary descriptions for irregular geometry.
    • Parallelization: Supports flat MPI, OpenMP, hybrid MPI/OpenMP, or MPI/MPI.
    • GPU Acceleration: Backends available for CUDA (NVIDIA), HIP (AMD), or SYCL (Intel).
    • I/O and Visualization: Parallel I/O with support for the Plotfile format, compatible with Amrvis, VisIt, ParaView, and yt.
    • Profiling: Built-in profiling tools for performance analysis.
  3. Overview of AmrCore functionality

    development

    The amrex/Src/AmrCore directory provides the core components for Adaptive Mesh Refinement (AMR) in AMReX. It handles the fundamental data structures and operations required for multi-level grid simulations, including:

    • Grid Management: Storing grid layout information and mapping processor distributions at each refinement level.
    • Grid Creation: Functions to create grids at various levels, including support for tagging operations.
    • Data Operations: Operators for interpolation (prolongation) and restriction between different refinement levels.
    • Flux Management: Flux registers for storing and manipulating fluxes at coarse-fine interfaces.
    • Particle Support: Integration for particles within an AMR framework.

    Note: While amrex/Src/Amr/ contains additional classes for managing time-stepping, it is possible to implement fully adaptive, subcycling-in-time simulations using only the AmrCore components.

  4. Overview of Discrete Fourier Transform support in AMReX

    development

    AMReX provides support for parallel discrete Fourier transforms (FFT). The underlying implementation is backend-dependent, utilizing specific libraries based on your build configuration:

    • CUDA builds: Uses cuFFT.
    • HIP builds: Uses rocFFT.
    • SYCL builds: Uses oneMKL.
    • CPU builds: Uses FFTW.

    In addition to general FFT support, AMReX provides specialized FFT-based Poisson solvers.

  5. Overview of AMReX Linear Solvers

    development

    AMReX provides a variety of linear solvers capable of handling single-level and composite solves across multiple AMR levels. Solvers can be configured for solutions defined on cell centers, edges, or nodes, and support embedded boundaries (EB) for complex geometries.

    Supported Solver Types

    • Geometric Multigrid: The default solution technique.
    • Iterative Solvers: Includes BiCGStab and GMRES.
    • External Library Interfaces: Interfaces are provided for HYPRE and PETSc.
    • FFT Solvers: Support for solving Poisson equations using Fast Fourier Transforms (FFT).
    • Tensor Solves: Used for calculating viscous terms in compressible Navier-Stokes equations (available for cell-centered velocity only).
    • Curl-Curl Operator: Supports solutions defined on cell edges.
  6. GPU Support and Requirements in AMReX

    development

    AMReX provides GPU support by targeting native vendor languages for different hardware architectures. Depending on your hardware, you will need to use one of the following language ecosystems:

    • NVIDIA GPUs: Requires CUDA (Compute Capability $\ge$ 6, CUDA $\ge$ 12.2).
    • AMD GPUs: Requires HIP/ROCm (ROCm $\ge$ 6).
    • Intel GPUs: Requires SYCL (AMReX officially supports the latest publicly released version of the oneAPI compiler).

    Additionally, users may use OpenMP and/or OpenACC in their applications if desired.

    Note: Current documentation focuses primarily on CUDA and HIP; SYCL documentation is forthcoming.

  7. Offload work to the GPU using AMReX

    development

    AMReX supports offloading work to the GPU via several backends: CUDA, HIP, SYCL, OpenACC, or OpenMP.

    Portable C++ Launchers (CUDA, HIP, SYCL)

    AMReX provides portable C++ function calls or macros that launch user-defined lambda functions.

    • Without CUDA/HIP/SYCL: The lambda runs on the CPU.
    • With CUDA/HIP/SYCL: The launch function automatically calculates blocks/threads, selects the appropriate stream or queue, and defines the work chunk for each thread.

    Pragma-based Offloading (OpenACC, OpenMP)

    Users can add appropriate pragmas to work loops and functions. These work with AMReX's internal CUDA-based memory management to ensure data is available on the GPU when the offloaded function executes.

    Best Practices

    AMReX recommends writing primary floating-point operation kernels using the Array4 object syntax. This provides a multi-dimensional array syntax (similar to Fortran) that maintains high performance.

  8. Visualize AMReX plotfiles with Amrvis, VisIt, ParaView, or yt

    development

    AMReX plotfiles can be visualized using several different tools depending on your data type and preference:

    • Amrvis: The standard tool used within the AMReX community. It is specifically designed for highly efficient visualization of block-structured hierarchical AMR data.
    • VisIt: A general-purpose scientific visualization tool compatible with AMReX plotfiles.
    • ParaView: A general-purpose visualization tool. Note that ParaView is specifically recommended for viewing particle data.
    • yt: A Python-based tool for analyzing and visualizing volumetric data, compatible with AMReX plotfiles.
  9. Choose an AMReX build system

    development

    AMReX supports three primary build approaches depending on how you want to integrate it into your application:

    1. GNU Make (Integrated): The most common approach for developers. There is no separate installation step; your application adopts AMReX's build system and compiles AMReX alongside your own code.
    2. GNU Make (Library): Build and install AMReX as a standalone library. Your application uses its own build system and links to AMReX as an external dependency.
    3. CMake: Build AMReX using the CMake build system.

    Alternatively, you can install AMReX using the Spack package manager.

  10. Overview of AMReX GPU Support

    development

    AMReX provides performance portability across multiple GPU architectures using native programming languages: CUDA (NVIDIA), HIP (AMD), and SYCL (Intel).

    Key Concepts

    • MPI+X Model: AMReX uses an MPI+X approach. On GPUs, X is CUDA, HIP, or SYCL. Unlike CPU execution where tiling is used, GPU tiling is disabled by default to reduce kernel launch overhead. Instead, kernels are typically launched at the Box level, mapping one or more cells to each GPU thread.
    • Work Distribution: GPU kernels are usually launched via ParallelFor looping constructs using GPU extended lambdas. These constructs launch kernels with a large number of threads, where each thread processes a small number of cells.
    • Parallelism via Streams: AMReX utilizes GPU streams to maximize usage. Each iteration of an MFIter loop is placed on a separate stream, allowing independent iterations to run concurrently while maintaining execution order within a single stream.
    • Memory Management: AMReX can use GPU managed memory to automatically handle data movement for mesh and particle data. While useful for initial porting, explicit host/device data migration is recommended for peak performance. Note that FArrayBox and MultiFab do not use managed memory by default.
    • Performance Best Practice: Keep mesh and particle data on the GPU for as long as possible to minimize CPU-GPU transfer overhead. Only move data back to the CPU for I/O operations.
    • Language Support: GPU support is available for C++. The Fortran interface does not currently support GPU offloading; porting Fortran code to C++ is recommended for GPU applications.
  11. Overview of SUNDIALS solvers supported by AMReX

    development

    AMReX provides interfaces to the SUNDIALS (SUite of Nonlinear and DIfferential/Algebraic equation Solvers) suite. The following six solvers are supported:

    • CVODE: For initial value problems for ODE systems.
    • CVODES: Solves ODE systems and includes sensitivity analysis.
    • ARKODE: Solves initial ODE problems using Runge-Kutta methods.
    • IDA: Solves initial value problems for differential-algebraic equation (DAE) systems.
    • IDAS: Solves differential-algebraic equation systems and includes sensitivity analysis.
    • KINSOL: Solves nonlinear algebraic systems.