Files
JuliaFEM.jl/demos
Jukka Aho d39a5cd22f feat(demos): Add GPU and MPI real hardware demonstration script
New 322-line demonstration script proving type-stable data flows to GPU and MPI:

Part 1: Type-stable data structures (lines 54-77)
- Creates nodes, connectivity, displacement as typed arrays
- Material properties E, ν as Float64
- All structures explicitly typed (Matrix{Float64}, not Dict)

Part 2: MPI communication (lines 79-123)
- Rank 0 sends 24KB displacement data to rank 1
- Transfers material properties
- Validates data integrity with checksum
- Uses MPI.Send/Recv with typed buffers

Part 3: GPU kernel execution (lines 125-192)
- Defines assemble_element_kernel! for CUDA
- Type-stable kernel: Float64, Int32, no allocations
- Transfers data to GPU (CuArray)
- Launches kernel with thread blocks
- Validates results against expected values

Part 4: Combined GPU+MPI workflow (lines 194-271)
- Rank 0 computes on GPU
- Transfers results via MPI to rank 1
- End-to-end validation

Summary section (lines 273-322):
- Reports hardware used (GPU model, MPI ranks)
- Key insights: type stability required for GPU, enables fast MPI
- Conclusion: type-stable fields are foundation for modern FEM

Requirements: MPI (required), CUDA (optional, detects and uses if available)
Run: mpiexec -np 2 julia --project=. demos/gpu_mpi_demo.jl
2025-11-09 10:48:54 +02:00
..

JuliaFEM Technology Demonstrations

This directory contains demonstrations of key technologies and architectural decisions for JuliaFEM v1.0.

Overview

These demos validate that type-stable field storage enables modern high-performance computing patterns: GPU execution, MPI communication, and Krylov iterative solvers.

Demonstrations

1. GPU and MPI Communication (gpu_mpi_demo.jl)

Purpose: Prove that type-stable data structures flow efficiently to GPU and MPI.

What it demonstrates:

  • Real CUDA GPU kernel execution
  • MPI data transfer between processes
  • Combined GPU+MPI workflow

Run:

mpiexec -np 2 julia --project=. demos/gpu_mpi_demo.jl

Documentation: README_GPU_MPI.md

2. Multi-GPU MPI Krylov Solver (krylov_mpi_gpu_demo.jl)

Purpose: Complete distributed FEM solver workflow with nodal assembly.

What it demonstrates:

  • Nodal assembly pattern (row-by-row matrix construction)
  • Distributed matrix-vector products
  • Conjugate Gradient solver with MPI
  • Multi-GPU execution
  • Solution verification (10×10 SPD system)

Run:

mpiexec -np 2 julia --project=. demos/krylov_mpi_gpu_demo.jl

Documentation: README_KRYLOV_DEMO.md

Results:

  • Converges in 9 iterations
  • Relative error: 7.73 × 10⁻¹⁴
  • Validates complete distributed solving workflow

Requirements

Required

  • Julia 1.9+
  • MPI installation (e.g., OpenMPI, MPICH)
  • MPI.jl package

Optional (for GPU demos)

  • CUDA-capable GPU
  • CUDA.jl package

If CUDA is not available, demos will fall back to CPU execution while still demonstrating the distributed computing patterns.

Key Insights

Type Stability is Not Optional

These demos prove that type-stable field storage is required (not just "nice to have") for:

Feature Why Type Stability Required
GPU execution CUDA kernels cannot compile with abstract types
Fast MPI Typed buffers avoid serialization overhead
Krylov solvers Matrix-free operators need concrete types
CPU performance 9-92× speedup measured (see CPU benchmarks)

Nodal Assembly Pattern

The Krylov demo shows row-by-row matrix construction (get_row() abstraction), which:

  • Aligns naturally with contact mechanics (nodal constraints)
  • Enables domain decomposition (each rank owns nodes)
  • Supports matrix-free solving (never form global matrix)
  • Scales to large problems (O(N) memory vs O(N²))

Architectural Validation

These demos validate the design decisions for JuliaFEM v1.0:

v0.5.1 (2019):

  • Dict-based fields → Type instability
  • Element assembly → Global matrix
  • Direct solvers → O(N³) time, O(N²) memory
  • Single-threaded CPU

v1.0 (target, validated here):

  • Type-stable fields → GPU/MPI capable
  • Nodal assembly → Distributed construction
  • Krylov solvers → O(N·iter) time, O(N) memory
  • Multi-GPU + MPI

References

  • CPU benchmarks: See benchmarks/field_storage_comparison.jl for 9-92× speedup measurements
  • Design documentation: See docs/book/zero_allocation_fields_v2.md for architectural rationale
  • Session notes: See llm/sessions/2025-11-09_gpu_mpi_validation.md for development history

Contributing

These demos are educational and meant to be:

  • Clear: Understand what's being demonstrated
  • Minimal: No unnecessary complexity
  • Runnable: Work on typical hardware (fall back to CPU if needed)
  • Validated: Compare against exact solutions

When adding new demos, follow this pattern and document thoroughly.