Home Knowledge Base Parallel Stencil Computation

Parallel Stencil Computation is the high-performance computing pattern for algorithms where each output element is computed from a fixed neighborhood (stencil) of input elements — the core computational pattern in finite difference methods for PDEs, image processing kernels, cellular automata, and lattice physics simulations. Stencil computations are memory-bandwidth bound and require carefully designed tiling and communication strategies to achieve high efficiency on multi-core CPUs, GPUs, and distributed clusters.

What Is a Stencil?

Arithmetic Intensity of Stencil Computations

GPU Stencil Implementation

__global__ void stencil_3d_7pt(float* out, const float* in, int N) {
    int i = blockIdx.x*blockDim.x + threadIdx.x;
    int j = blockIdx.y*blockDim.y + threadIdx.y;
    int k = blockIdx.z*blockDim.z + threadIdx.z;
    if (i>0 && i<N-1 && j>0 && j<N-1 && k>0 && k<N-1) {
        out[IDX(i,j,k)] = in[IDX(i-1,j,k)] + in[IDX(i+1,j,k)]
                        + in[IDX(i,j-1,k)] + in[IDX(i,j+1,k)]
                        + in[IDX(i,j,k-1)] + in[IDX(i,j,k+1)]
                        - 6.0f * in[IDX(i,j,k)];
    }
}

Shared Memory Tiling (GPU)

Wavefront Parallelism

Diamond Tiling

Stencil Applications

ApplicationStencil TypeDomain Size
Weather simulation (WRF)3D 7-point1000×1000×50 grid points
Seismic RTM3D 25-point high order500³ points
DNS turbulence simulation3D spectral + physical4096³ points
Image bilateral filter2D variable4K×4K pixels
Lattice QCD4D U(1) stencil64⁴ lattice sites
Cardiac electrophysiology3D reaction-diffusionHeart mesh

Distributed Stencil with MPI

Parallel stencil computation is the fundamental computational pattern of physics-based simulation — from predicting next week's weather to simulating nuclear reactors to rendering realistic fluid effects in movies, stencil computations on distributed parallel hardware are the mathematical machinery that transforms differential equations into numerical solutions, making parallel stencil optimization one of the most impactful skills in scientific high-performance computing.

parallel stencil computationstencil parallelwavefront parallelismdiamond tilingstencil kernelfinite difference stencil

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.