Jukka Aho be076d968a docs(book): Add concise type-stability rationale for field storage
Create 299-line focused design rationale explaining why type stability is essential
for CPU/GPU/MPI performance, without mandating specific storage patterns.

Executive summary (lines 16-26):
- v0.5.1 Dict{String,Any}: 9-92× performance degradation
- Type-unstable code CANNOT run on GPUs
- Significant MPI communication overhead
- Document does NOT prescribe storage location
- Demonstrates why type stability at access points is essential
- Key: Storage pattern matters less than type inference

Problem analysis (lines 28-67):
- Type instability definition: Runtime dispatch when type unknown at compile time
- Why it matters: 10-100× slower CPU, GPU compilation fails, MPI serialization
- Measured impact table: 9-92× speedup, 0 allocations with type stability
- Critical: Zero allocations required for GPU kernels

Design requirements (lines 69-136):
1. Type stability at access points (compiler must infer types)
   - Fields could be element-local, global arrays, or arguments
   - Access pattern must be type-stable regardless
2. Zero allocations in hot paths (GPU/MPI requirement)
   - Assembly loop must allocate nothing
3. Contiguous memory layout (GPU/MPI optimization)
   - CUDA transfers contiguous arrays directly
4. Immutable where possible (safe parallelism)
   - Thread-safe reads without locks

Demonstrated solutions (lines 138-201) - EXAMPLES, not mandates:
1. NamedTuple container: Simple, type-stable, immutable
2. Struct with typed fields: Explicit, self-documenting
3. Passed as arguments: Maximum type stability, explicit dependencies
- All three achieve type stability
- Choice depends on use case, not performance

GPU and MPI rationale (lines 203-237):
- GPU execution: CUDA requires all code type-stable
- Mock demonstration in benchmarks/gpu_mpi_mock.jl
- MPI communication: Typed arrays use fast memcpy vs slow serialization
- Type stability enables identical code for CPU/GPU

Recommendations (lines 239-256):
- Use type-stable access patterns (REQUIRED)
- Prefer immutable data structures (threading/GPU)
- Pre-allocate caches (zero allocations)
- Use contiguous arrays (GPU/MPI transfer)
- Profile with @btime (verify zero allocations)
- Does NOT mandate: Storage location, container type, dynamic vs static

Validation (lines 258-275):
- benchmarks/field_storage_comparison.jl: 9-92× CPU speedup
- benchmarks/gpu_mpi_mock.jl: GPU/MPI patterns
- benchmarks/VALIDATION_RESULTS.md: Summary table

Conclusion (lines 277-299):
- Type stability is fundamental requirement, not implementation detail
- Enables: High CPU performance, GPU execution, efficient MPI, safe threading
- v1.0 must ensure type stability at access points
- Storage pattern is secondary concern (memory, cache, API)
- Next steps: Review, benchmark, choose pattern, implement, validate CUDA

Key difference from v1: Shorter (299 vs 1114 lines), focused on WHY not HOW,
explicitly states storage pattern is flexible, emphasizes GPU/MPI requirements.

Platform: Julia 1.12.1, November 9, 2025
Series: The JuliaFEM Book, Chapter 5
Status: Design rationale with validated measurements
2025-11-09 11:10:37 +02:00
2018-10-27 19:55:26 +03:00
2018-09-06 13:34:26 +03:00
2025-11-08 11:10:34 +02:00

JuliaFEM.jl - an open source solver for both industrial and academia usage

logo

DOI License Gitter Build Status Coverage Status Stable documentation Latest documentation Issues

The JuliaFEM project develops open-source software for reliable, scalable, distributed Finite Element Method.

The JuliaFEM software library is a framework that allows for the distributed processing of large Finite Element Models across clusters of computers using simple programming models. It is designed to scale up from single servers to thousands of machines, each offering local computation and storage. The basic design principle is: everything is nonlinear. All physics models are nonlinear from which the linearization are made as a special cases.

At the moment, users can perform the following analyses with JuliaFEM: elasticity, thermal, eigenvalue, contact mechanics, and quasi-static solutions. Typical examples in industrial applications include non-linear solid mechanics, contact mechanics, finite strains, and fluid structure interaction problems. For visualization, JuliaFEM uses ParaView which prefers XDMF file format using XML to store light data and HDF to store large data-sets, which is more or less the open-source standard.

Vision

On one hand, the vision of the JuliaFEM includes the opportunity for massive parallelization using multiple computers with MPI and threading as well as cloud computing resources in Amazon, Azure and Google Cloud services together with a company internal server. And on the other hand, the real application complexity including the simulation model complexity as well as geometric complexity. Not to forget that the reuse of the existing material models as well as the whole simulation models are considered crucial features of the JuliaFEM package.

Recreating the wheel again is definitely not anybody's goal, and thus we try to use and embrace good practices and formats as much as possible. We have implemented Abaqus / CalculiX input-file format support and maybe will in the future extend to other FEM solver formats. Using modern development environments encourages the user towards fast development time and high productivity. For developing and creating new ideas and tutorials, we have used Jupyter notebooks to make easy-to-use handouts.

The user interface for JuliaFEM is Jupyter Notebook, and Julia language itself is a real programming language. This makes it possible to use JuliaFEM as a part of a bigger solution cycle, including for example data mining, automatic geometry modifications, mesh generation, solution, and post-processing and enabling efficient optimization loops.

Installing JuliaFEM

Inside Julia REPL, type:

Pkg.add("JuliaFEM")

Initial road map

JuliaFEM current status: project planning

Version Number of degree of freedom Number of cores
0.1.0 1 000 000 10
0.2.0 10 000 000 100
1.0.0 100 000 000 1 000
2.0.0 1 000 000 000 10 000
3.0.0 10 000 000 000 100 000

We strongly believe in the test driven development as well as building on top of previous work. Thus all the new code in this project should be 100% tested. Also other people have wisdom in style as well:

The Zen of Python:

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Errors should never pass silently.

Citing

If you like using our package, please consider citing our article

@article{frondelius2017juliafem,
  title={Julia{FEM} - open source solver for both industrial and academia usage},
  volume={50}, 
  url={https://rakenteidenmekaniikka.journal.fi/article/view/64224},
  DOI={10.23998/rm.64224},
  number={3},
  journal={Rakenteiden Mekaniikka},
  author={Frondelius, Tero and Aho, Jukka},
  year={2017},
  pages={229-233}
}

Contributing

We welcome contributions! JuliaFEM encourages good practices, starting from unit testing and continuing to full integration testing across platforms.

Interested in contributing? Please read:

Key requirements:

  • Type-stable code (performance critical)
  • Tests included with all changes
  • Follow coding standards (use u, v, w not ξ, η, ζ)
  • Clean commit messages

Questions? Open a GitHub Discussion or issue - we're happy to help!

S
Description
Languages
Julia 98%
Python 1.7%
Shell 0.3%