diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..70c4bc7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Patches apply byte for byte: no line-ending conversion on checkout. +*.patch -text diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6baf69d..1ad0d8d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,15 +24,18 @@ jobs: include: - name: macOS (Apple Silicon) os: macos-14 + solver: macos package: dist:mac artifact: release/*.dmg - name: Windows (x64) os: windows-latest + solver: windows package: package:win artifact: release/*.exe - name: Linux (x64) # The oldest supported runner, so the app runs on older glibc. os: ubuntu-22.04 + solver: linux package: package:linux artifact: release/*.AppImage env: @@ -53,30 +56,22 @@ jobs: with: python-version: "3.10" - # CalculiX 2.23 on every platform: the Homebrew tap on macOS (as for - # local builds), conda-forge on Windows and Linux. - - name: Install CalculiX (macOS) - if: runner.os == 'macOS' - run: brew install costerwi/calculix/calculix-ccx - - - name: Install CalculiX (Windows, Linux) - if: runner.os != 'macOS' + # CalculiX 2.23 built from source on every platform, with threaded + # SPOOLES and PARDISO (Apple Accelerate on macOS; on Windows and Linux, + # Intel oneMKL's in sprung-solve, a separate program built beside it), + # from a conda-forge environment. + - name: Set up the solver build environment uses: mamba-org/setup-micromamba@v2 with: - environment-name: calculix - # OpenBLAS: MKL, the Windows default, loads its kernels at run - # time, so they cannot be found and bundled from the imports. - create-args: calculix=2.23 libblas=*=*openblas + environment-name: sprung-solver + environment-file: native/calculix/solver-env-${{ matrix.solver }}.yml init-shell: none cache-environment: true - - name: Locate CalculiX (Windows, Linux) - if: runner.os != 'macOS' + - name: Build CalculiX run: | - env="$MAMBA_ROOT_PREFIX/envs/calculix" - if [ "$RUNNER_OS" = Windows ]; then ccx="$env/Library/bin/ccx.exe"; else ccx="$env/bin/ccx"; fi - test -f "$ccx" - echo "SPRUNG_FEA_CCX=$ccx" >> "$GITHUB_ENV" + if [ "$RUNNER_OS" = Windows ]; then python -m pip install pefile; fi + python scripts/build-solver.py --prefix "$MAMBA_ROOT_PREFIX/envs/sprung-solver" - name: Install Linux build tools if: runner.os == 'Linux' @@ -93,9 +88,16 @@ jobs: if [ "$RUNNER_OS" = Windows ]; then py=.venv/Scripts/python.exe; else py=.venv/bin/python; fi "$py" -m pip install pyinstaller==6.22.3 + - name: Compare the direct solvers + run: | + if [ "$RUNNER_OS" = Windows ]; then py=.venv/Scripts/python.exe; else py=.venv/bin/python; fi + "$py" -m unittest -v tests.test_solvers + - name: Package run: npm run ${{ matrix.package }} + # The packaged app as shipped: its own sprung-solve and MKL, none + # installed on the computer. - name: Solve with the packaged engine run: npm run test:packaged diff --git a/.gitignore b/.gitignore index 1d0951e..6ba9149 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ output/ .DS_Store runtime/ +/solver/ *.tsbuildinfo .cad-venv/ diff --git a/IMPLEMENTATION.md b/IMPLEMENTATION.md index de303e6..4b27066 100644 --- a/IMPLEMENTATION.md +++ b/IMPLEMENTATION.md @@ -146,7 +146,7 @@ A static study with `largeDeformation: true` runs `*STEP, NLGEOM` with automatic ### Natural frequencies -A natural frequency study (`analysis: "frequency"`, `modes`: 1–50, default 6) runs `*FREQUENCY` with SPOOLES and ARPACK; the study's equation-solver choice applies to static studies only. Loads are optional. When the study has any, Solve asks whether to include them, and the answer travels with the solve request as `preload` rather than in the study. Included loads need supports that hold the part; a linear `*STATIC` step under them, with no output, precedes `*STEP, PERTURBATION` `*FREQUENCY`, so the modes include the stress stiffness they leave (tension and spin raise frequencies, compression lowers them; a negative eigenvalue means the loads exceed buckling and is reported). Spin softening and gyroscopic effects are not modeled. An engine test checks f² ≈ f₀²(1 − P/Pcr) for an axially loaded cantilever. Supports are optional: the engine counts the rigid motions the supports leave free (the same rank check as static validation) and, for a free or partly held part, requests that many extra modes with a negative shift, since the stiffness matrix is singular. Those first modes are labelled rigid motions at 0 Hz and excluded from key results. +A natural frequency study (`analysis: "frequency"`, `modes`: 1–50, default 6) runs `*FREQUENCY` with the direct solver and ARPACK; the study's equation-solver choice applies to static studies only. Loads are optional. When the study has any, Solve asks whether to include them, and the answer travels with the solve request as `preload` rather than in the study. Included loads need supports that hold the part; a linear `*STATIC` step under them, with no output, precedes `*STEP, PERTURBATION` `*FREQUENCY`, so the modes include the stress stiffness they leave (tension and spin raise frequencies, compression lowers them; a negative eigenvalue means the loads exceed buckling and is reported). Spin softening and gyroscopic effects are not modeled. An engine test checks f² ≈ f₀²(1 − P/Pcr) for an axially loaded cantilever. Supports are optional: the engine counts the rigid motions the supports leave free (the same rank check as static validation) and, for a free or partly held part, requests that many extra modes with a negative shift, since the stiffness matrix is singular. Those first modes are labelled rigid motions at 0 Hz and excluded from key results. Frequencies come from the `.dat` eigenvalue table; effective modal mass per direction is reported as a fraction of CalculiX's total effective mass, which counts only mass that can move (mass on supported nodes is left out). Each mode shape is scaled to a 1 mm peak displacement and its von Mises stress alike, so modal stress reads in MPa per mm of peak motion; yield margin is not offered. The key result for mesh convergence is the first elastic frequency. @@ -184,11 +184,42 @@ The study chooses the linear equation solver, written to the deck as `*STATIC, S | Study value | CalculiX solver | Use | |---|---|---| -| `spooles` (default) | `SPOOLES` | Direct sparse factorization. Most robust, equilibrium to round-off; memory grows quickly with model size | +| `direct` (default) | `PARDISO` (Apple Accelerate, or Intel oneMKL in `sprung-solve`) or `SPOOLES` | Direct sparse factorization. Most robust, equilibrium to round-off; memory grows quickly with model size | | `iterative-cholesky` | `ITERATIVE CHOLESKY` | Conjugate gradients with incomplete-Cholesky preconditioning. Much less memory | | `iterative-scaling` | `ITERATIVE SCALING` | Conjugate gradients with diagonal scaling. Least memory; most iterations | -PARDISO and PaStiX are not offered: the bundled CalculiX build does not link them. CalculiX returns the last conjugate-gradient iterate without an error when it stops short of its tolerance, so the worker reads the final residual and limit from the log and rejects an unconverged solve. Iterative results match the direct solver within about 10⁻⁴ of peak displacement with diagonal scaling, and within 10⁻³ with incomplete Cholesky (which on some meshes stops about 10% earlier), and 0.1% of peak stress on the test beam, and equilibrium closes to about 0.1% (with incomplete Cholesky, which uses a looser CalculiX tolerance and sometimes stops early, up to about 1%; a result above 0.5% warns and suggests the direct solver). The result records the solver and iteration count, shown in the console's Checks tab. Studies saved before solver choice use SPOOLES. Threads are a per-machine preference, not part of the study, because they do not change results: **Auto** (default) uses the performance cores (all logical cores where the platform does not distinguish them), **1** uses a single thread, and **All** uses every logical core. The renderer stores the choice locally and sends it with each mesh or solve request (`?threads=N`, validated against the core count reported by `GET /api/health`). The worker applies it to Gmsh meshing and to CalculiX stiffness assembly, SPOOLES factorization and stress recovery (`CCX_NPROC_STIFFNESS`, `CCX_NPROC_EQUATION_SOLVER`, `CCX_NPROC_RESULTS`). OpenMP stays at one thread (`OMP_NUM_THREADS=1`, `NUMBER_OF_CPUS=1`): in repeated identical solves, CalculiX's own thread controls at up to 8 threads gave bit-identical displacement, stress and nodal forces, but OpenMP above one thread combined with any of them made stress and reactions vary between runs, once reporting an 866 N reaction for a 1000 N load. Earlier versions pinned every stage to one thread because of that interaction. CalculiX's iterative solvers iterate on one thread regardless. Gmsh meshes can differ slightly between runs with more than one thread; with one thread they are repeatable. The result records the thread count, shown in the Checks tab. +The direct solver is the fastest exact one the bundled CalculiX has (`calculix.direct_solver`): PARDISO, then SPOOLES. `scripts/build-solver.py` builds CalculiX 2.23 with both on Apple silicon, Linux x64 and Windows x64, from one conda-forge environment per platform (`native/calculix/solver-env-*.yml`): + +- **PARDISO on macOS** is Apple Accelerate. `native/calculix/accelerate_pardiso.c` answers CalculiX's PARDISO calls (the MKL routine `pardiso_`: analyze and factor, solve, release) with Accelerate's sparse solvers: supernodal Cholesky with METIS nested-dissection ordering, LDLT with threshold partial pivoting when Cholesky finds the matrix indefinite (shifted eigenvalue problems, buckling), and LU with threshold partial pivoting for nonsymmetric matrices (frictional contact, coupled temperature–displacement; QR before macOS 15.5). The ordering and symbolic analysis take about half of a factorization and run serially, so they are kept for the last matrix structure: nonlinear steps, which refactor the same structure every iteration, reuse them (the contact, plasticity and large-deformation tests run 1.6 times faster). Accelerate ships with macOS, so nothing is added to the bundle. +- **PARDISO on Windows and Linux** is Intel oneMKL's, run by `sprung-solve`, a separate program. CalculiX is GPL-2.0-only and MKL is proprietary, so MKL is never linked into CalculiX (`THIRD_PARTY_NOTICES.md`). `sprung-solve` (`native/sprung-solve`, MIT) links MKL statically and solves systems sent through its standard input. The protocol (`docs/solver-protocol.md`) uses 0-based compressed sparse rows and 64-bit indices. `native/calculix/pardiso_client.c` is CalculiX's `pardiso_`: on the first call it starts `sprung-solve --serve`, found in `SPRUNG_FEA_SOLVE` or at `sprung-solve/sprung-solve` beside `ccx`, and then sends each factorization and solve through the pipe. + - **Lifetime.** The helper ends with CalculiX, even mid-factorization: on Linux through the parent-death signal, on Windows through a job object. + - **Structure reuse.** It keeps PARDISO's analysis while a factorization's structure stays the same, as Accelerate's interface does, so a nonlinear step's iterations only refactor. + - **Refinement.** PARDISO refines a solve only after it has perturbed pivots (`iparm[7]=0`), not on every solve, which is the default `pardisoinit` and CalculiX itself choose. Refining in working precision ruins nearly singular systems. The frequency analysis of an unsupported part factors K − M, whose six rigid-body directions sit about ten orders of magnitude below the elastic ones, and refined solves there turned the first elastic mode into a seventh spurious rigid one. CalculiX linked to MKL directly has the same problem. `tests/test_solvers.py` compares a free part's modes across solvers. + - **Libraries and threads.** On Linux it is built by GCC against MKL's GNU OpenMP threading. On Windows it is built by Microsoft's compiler (MKL's static libraries are made for it, not MinGW) against LLVM's OpenMP (`libiomp5md.dll`), as conda-forge's MKL is. MKL takes its thread count from `MKL_NUM_THREADS`. + - **Offered only when it works.** `calculix.find_helper` runs `sprung-solve --version`, which solves a small indefinite system. PARDISO is offered only when that works, so a missing or broken helper, or a processor MKL does not run on, leaves SPOOLES. The engine passes the helper it checked to CalculiX in `SPRUNG_FEA_SOLVE`. + - **Cost.** Sending a system through the pipe costs a fraction of a second even at 400,000 equations; the pipe moves about 2 GB/s. + - **Size.** The statically linked helper is about 105 MB, about 15 MB compressed. Shipping MKL's shared libraries instead would add 300 to 400 MB. + - **Without MKL.** `build-solver.py --without-mkl` builds no helper, and the solver then has SPOOLES only. +- **SPOOLES**, threaded with the patches below, is always there. + +Every analysis uses the direct solver except a static study that chooses an iterative one. Eigenvalue analyses (frequency, buckling, harmonic) factor shifted, often indefinite matrices, which both PARDISOs pivot for. `SPRUNG_FEA_DIRECT_SOLVER=pardiso` or `spooles` forces one solver for comparisons. Studies saved with `spooles`, the direct solver's name before it had backends, read as `direct`. CalculiX's PaStiX interface is not built: it needs a fork of PaStiX, and PaStiX is LGPL-3.0, which cannot be combined with GPL-2.0-only CalculiX. + +All direct solvers agree with a single-threaded SPOOLES solve to the six digits the results file keeps, and in eigenvalues to 10⁻⁶. ARPACK iterates each eigenvalue to its own tolerance; Accelerate typically agrees to 10⁻⁷. `tests/test_solvers.py` checks this on every platform in CI, along with the fallback to SPOOLES and `sprung-solve` on its own. + +Static beam solves on a 4-core Linux machine (Xeon, 2.8 GHz): + +| Equations | Threaded SPOOLES | PARDISO through `sprung-solve` | +|---|---|---| +| 136,000 | 12.7 s | 5.7 s | +| 417,000 | 94 s | 27 s | + +An earlier build that loaded MKL inside CalculiX took 6.0 s on the 136,000-equation model, so the pipe adds no measurable time. + +CalculiX returns the last conjugate-gradient iterate without an error when it stops short of its tolerance, so the worker reads the final residual and limit from the log and rejects an unconverged solve. Iterative results match the direct solver within about 10⁻⁴ of peak displacement with diagonal scaling, and within 10⁻³ with incomplete Cholesky (which on some meshes stops about 10% earlier), and 0.1% of peak stress on the test beam, and equilibrium closes to about 0.1% (with incomplete Cholesky, which uses a looser CalculiX tolerance and sometimes stops early, up to about 1%; a result above 0.5% warns and suggests the direct solver). The result records the solver and iteration count, shown in the console's Checks tab. + +Threads are a per-machine preference, not part of the study, because they change results only by round-off: **Auto** (default) uses the performance cores (all logical cores where the platform does not distinguish them), **1** uses a single thread, and **All** uses every logical core. The renderer stores the choice locally and sends it with each mesh or solve request (`?threads=N`, validated against the core count reported by `GET /api/health`). The worker applies it to Gmsh meshing and to CalculiX: `NUMBER_OF_CPUS`, which caps every CalculiX stage, and `CCX_NPROC_STIFFNESS` and `CCX_NPROC_RESULTS` for stiffness assembly and stress recovery; `VECLIB_MAXIMUM_THREADS` for Accelerate and `MKL_NUM_THREADS` for MKL (which `sprung-solve` receives with each system); and `CCX_NPROC_EQUATION_SOLVER` for SPOOLES, only where SPOOLES is thread-safe. OpenBLAS stays at one thread (`OPENBLAS_NUM_THREADS=1`). SPOOLES 2.2 as released hands work between threads through unsynchronized loads and stores; on Apple silicon, which reorders them, threaded factorizations silently lose updates, and in repeated identical solves of a 366,000-equation bracket, 4 to 7 of every 8 threaded runs were wrong, with displacement off by up to 84% of its peak and stress by up to 13 times its peak (an earlier report: an 866 N reaction for a 1000 N load). The patches in `native/calculix/spooles-patches`, from conda-forge's spooles feedstock (build 1006), order those hand-offs with acquire/release atomics; with them every threaded run matched the serial solve bit for bit. `calculix.capabilities` threads SPOOLES only for builds that carry the fixes: those with a `ccx.json` beside the executable saying so (written by `build-solver.py` and `bundle-runtime.py`), and conda-forge `calculix` build 5 or later, whose recipe requires the fixed spooles. A Homebrew CalculiX gets threaded assembly and stress recovery but serial SPOOLES. Earlier builds set `NUMBER_OF_CPUS=1`, which left every stage serial although the `CCX_NPROC_*` variables asked for more. OpenMP stays at one thread (`OMP_NUM_THREADS=1`). CalculiX's iterative solvers iterate on one thread regardless. Gmsh meshes can differ slightly between runs with more than one thread; with one thread they are repeatable. The result records the thread count, shown in the Checks tab. + +A solve reuses the mesh in the document when it was made from the same STEP (by hash), element size, bolt cuts and mesher settings (`mesh.key.json`, `cad.MESHER`), so changing loads, supports, materials or the analysis type does not remesh. Meshing and the preview mesh share it. The worker retains the input deck, mesh, FRD output, DAT output, and solver log. The FRD reader returns every result frame (consecutive blocks with the same step number and value: one load step, mode, increment, or frequency) and rejects incomplete fields. @@ -271,13 +302,14 @@ Development document data lives in `.sprung-fea/`. Packaged desktop document dat ```sh npm ci npm run setup -brew install costerwi/calculix/calculix-ccx +brew install gcc arpack +npm run build:solver npm run dev:desktop ``` `npm run setup` creates the Python engine environment (`.venv`) and downloads the pinned VTK.wasm runtime (13 MB, checksum-verified) into `public/vtk-wasm/`. The 3D view needs WebGL 2. -For a browser development session, use `npm run dev` and visit http://127.0.0.1:5173. After `npm run build`, `npm start` opens the desktop application with its own local service. `SPRUNG_FEA_PYTHON` overrides the development worker interpreter, and `SPRUNG_FEA_CCX` selects a solver executable when CalculiX is installed elsewhere. `SPRUNG_FEA_CHROMIUM` overrides the browser executable used by end-to-end tests. +For a browser development session, use `npm run dev` and visit http://127.0.0.1:5173. After `npm run build`, `npm start` opens the desktop application with its own local service. `SPRUNG_FEA_PYTHON` overrides the development worker interpreter, and `SPRUNG_FEA_CCX` selects a solver executable when CalculiX is installed elsewhere. `npm run build:solver` builds CalculiX into `solver/` (a few minutes), where the engine finds it first. It needs the conda-forge environment for the platform, created with micromamba (or mamba, or conda) and then active, or passed as `--prefix`: `micromamba create -n sprung-solver -f native/calculix/solver-env-macos.yml` (or `-linux`, `-windows`); macOS also needs the Xcode command line tools, and Windows needs Git Bash's `patch`. A Homebrew `costerwi/calculix/calculix-ccx` also works, with only a serial SPOOLES. `SPRUNG_FEA_CHROMIUM` overrides the browser executable used by end-to-end tests. ### Standalone Mac app @@ -298,11 +330,11 @@ npm run package:win # or: npm run package:linux npm run test:packaged # solves with only the packaged engine and solver ``` -These bundle the CalculiX found by `SPRUNG_FEA_CCX` (or on `PATH`) together with its shared libraries; CI uses conda-forge `calculix=2.23` (`micromamba create -n calculix calculix=2.23`). Linux packaging needs `patchelf`. Windows produces `release/Sprung-FEA-Setup-.exe`, a one-click installer that installs for the current user without administrator rights. Linux produces `release/Sprung-FEA--x86_64.AppImage`, which runs without installation. Builds are unsigned. +These bundle the CalculiX in `solver/` (`npm run build:solver`), else the one found by `SPRUNG_FEA_CCX` (or on `PATH`), together with its shared libraries (`scripts/solverlibs.py`). On Windows and Linux, `sprung-solve` and the OpenMP runtime it needs go into their own folder, `runtime/solver/sprung-solve`, with its MIT license and Intel's license and third-party notices. Linux packaging needs `patchelf`. Windows produces `release/Sprung-FEA-Setup-.exe`, a one-click installer that installs for the current user without administrator rights. Linux produces `release/Sprung-FEA--x86_64.AppImage`, which runs without installation. Builds are unsigned. ### Continuous integration -[.github/workflows/build.yml](.github/workflows/build.yml) builds the macOS DMG, Windows installer and Linux AppImage on every push and pull request, runs a static and a frequency solve with each packaged engine, and uploads the installers as workflow artifacts. The README's download instructions point users to these artifacts until tagged releases exist. +[.github/workflows/build.yml](.github/workflows/build.yml) builds the macOS DMG, Windows installer and Linux AppImage on every push and pull request. Each job builds CalculiX and `sprung-solve` from source and compares the direct solvers (`tests/test_solvers.py`). It then packages the app and runs a static and a frequency solve with the packaged engine. Both must use PARDISO, from what ships in the app, with no MKL installed on the runner. Finally it uploads the installers as workflow artifacts. The README's download instructions point users to these artifacts until tagged releases exist. ### README media diff --git a/README.md b/README.md index ec85863..008b439 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Stress, vibration and heat analysis for mechanical parts, on your own computer. Open a STEP file, pick a material, click the faces that hold the part and the faces that carry load, and solve. Sprung FEA meshes the geometry, runs the open-source CalculiX solver locally, and shows you where the part is stressed, how far it moves, how it vibrates and how hot it gets. -It is free software (GPL-3.0) for macOS, Windows and Linux. +It runs on macOS, Windows and Linux. Its source code is free software (GPL-3.0-or-later). The downloadable builds also include separately licensed components (see [License](#license)). ![Setting up a study: open the bracket, choose aluminum, click the two bolt holes as fixed supports, put 500 N on the base, and solve](docs/media/setup.gif) @@ -109,4 +109,10 @@ Development setup, packaging, tests and the internals are in [IMPLEMENTATION.md] ## License -GPL-3.0-or-later. See [LICENSE](LICENSE). Third-party components and their licenses are listed in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). +The Sprung FEA source code is GPL-3.0-or-later (see [LICENSE](LICENSE)), except the small `sprung-solve` program in `native/sprung-solve`, which is MIT. + +The prebuilt downloads include separately licensed third-party components, each under its own license: +- CalculiX, the solver, is GPL-2.0-only and runs as a separate program. +- The Windows and Linux builds include Intel oneMKL, a proprietary library under the Intel Simplified Software License. It sits inside `sprung-solve`, a separate program that runs the fast PARDISO solver for CalculiX. + +All components, their licenses and how they fit together are listed in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md), and the license texts ship with the app. diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index adb0548..70caad8 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -1,10 +1,18 @@ # Third-party software -Sprung FEA is GPL-3.0-or-later. Its original interface and integration code are in this repository. No SolidWorks code, assets, or proprietary UI components are used. Official SolidWorks documentation informed the workflow research recorded in `docs/interaction-design.md`. +The Sprung FEA source code in this repository is GPL-3.0-or-later, except `native/sprung-solve`, which is MIT. Prebuilt distributions (the macOS DMG, Windows installer and Linux AppImage) are mixed-license: they bundle separately licensed third-party components, each under its own license, listed below. Most are free and open-source software. The Linux and Windows builds also contain Intel oneMKL, which is proprietary, distributed in binary form under the Intel Simplified Software License. + +The distribution contains separate programs that communicate only through files, command-line arguments and pipes, each in its own process: + +- **The Sprung FEA application** (Electron interface, local service and Python engine): GPL-3.0-or-later. +- **CalculiX CrunchiX (`ccx`)**: GPL-2.0-only, as CalculiX itself is (below). The engine writes a CalculiX input file, runs `ccx` on it, and reads its result files. Only libraries whose licenses are compatible with GPL-2.0 are linked into `ccx`. +- **`sprung-solve`** (Linux and Windows): MIT source, linked statically with Intel oneMKL. It solves sparse linear systems sent to it through a pipe, by the documented protocol in `docs/solver-protocol.md`, and it can also be run on its own. `ccx` sends its PARDISO solves there and falls back to its built-in SPOOLES solver when `sprung-solve` is absent. Neither MKL nor `sprung-solve` is linked into `ccx` or into the Sprung FEA application. Packaged builds keep it in its own folder (`runtime/solver/sprung-solve`), with its MIT license, Intel's license, and Intel's third-party notices. + +No SolidWorks code, assets, or proprietary UI components are used. Official SolidWorks documentation informed the workflow research recorded in `docs/interaction-design.md`. | Component | Purpose | License | Upstream/source | |---|---|---|---| -| CalculiX CrunchiX 2.23 | Structural solver | GPL-2.0-or-later | https://www.dhondt.de/ and https://github.com/Dhondtguido/CalculiX | +| CalculiX CrunchiX 2.23 | Structural solver, a separate program (`ccx`) | GPL-2.0-only: its source files are licensed under "the GNU General Public License as published by the Free Software Foundation (version 2)", without "or any later version" (a few headers allow later versions) | https://www.dhondt.de/ and https://github.com/Dhondtguido/CalculiX | | Gmsh 4.15.2 | STEP/OpenCASCADE import and meshing | GPL-2.0-or-later with exception | https://gmsh.info and https://gitlab.onelab.info/gmsh/gmsh | | OpenCASCADE (within Gmsh) | CAD kernel | LGPL-2.1 with exception | https://dev.opencascade.org/ | | NumPy 2.2.6 | Mesh and result calculations | BSD-3-Clause; bundled notices included | https://github.com/numpy/numpy | @@ -19,14 +27,30 @@ Sprung FEA is GPL-3.0-or-later. Its original interface and integration code are | Vite | Frontend build and development | MIT | https://github.com/vitejs/vite | | Express / Multer | Local service and file import | MIT | https://github.com/expressjs | | Inter / JetBrains Mono | Bundled offline fonts | SIL OFL-1.1 | https://github.com/rsms/inter and https://github.com/JetBrains/JetBrainsMono | +| SPOOLES 2.2 | CalculiX direct solver (statically linked) | Public domain | https://www.netlib.org/linalg/spooles/ | +| conda-forge spooles-feedstock patches (build 1006) | SPOOLES threading fixes, in `native/calculix/spooles-patches` | BSD-3-Clause | https://github.com/conda-forge/spooles-feedstock | +| Apple Accelerate | Sparse direct solver behind CalculiX's PARDISO interface on macOS | macOS system library (GPL-2.0's system library exception), not redistributed | https://developer.apple.com/documentation/accelerate/sparse_solvers | +| sprung-solve | Separate program that runs CalculiX's PARDISO solves on Linux and Windows | MIT (`licenses/sprung-solve.txt`) | `native/sprung-solve` in this repository | +| Intel oneMKL 2026 | PARDISO sparse direct solver, linked statically into `sprung-solve` only (Linux and Windows builds) | Intel Simplified Software License (October 2022), `licenses/Intel-oneMKL.txt`; proprietary, binary only; its third-party notices are in `licenses/Intel-oneMKL-third-party-programs.txt` | https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html (conda-forge `mkl-static`) | | ARPACK-NG | CalculiX linear algebra dependency | BSD-3-Clause | https://github.com/opencollab/arpack-ng | | OpenBLAS | Linear algebra | BSD-3-Clause | https://github.com/OpenMathLib/OpenBLAS | | GCC runtime | Fortran, OpenMP, quadmath | GPL-3.0 with GCC Runtime Library Exception where applicable; LGPL for quadmath | https://gcc.gnu.org/ | -| Open MPI / PMIx / hwloc / libevent | Transitive native dependencies | BSD licenses; see individual notices | https://www.open-mpi.org/ and https://libevent.org/ | -| LLVM OpenMP | Transitive native dependency | Apache-2.0 with LLVM exception | https://llvm.org/ | +| LLVM OpenMP | OpenMP runtime: CalculiX's on macOS; MKL's threads in `sprung-solve` on Windows (as `libiomp5md.dll`) | Apache-2.0 with LLVM exception | https://llvm.org/ | The VTK.wasm runtime is Kitware's unmodified prebuilt package `vtk-wasm32-emscripten` 9.7.20260927 from the VTK package registry (https://gitlab.kitware.com/vtk/vtk/-/packages), SHA-256 `63252b799e8c44dfb149f329c94f9f6715c78b654292f18cce067c9d080a2e92`. `scripts/fetch-vtk-wasm.mjs` downloads and verifies it; it is not committed to this repository. -The native solver is the existing Homebrew build, with dynamic-library install names changed only to use adjacent bundled libraries. The build recipe is `costerwi/homebrew-calculix` commit `57711a3e00dec3128664260a9f58e69fbe874dca`, source archive SHA-256 `9c88385c10fb04f5dc6c4e98027a51bebdd8aee3920e05190d6c1dd08357d6e7`. The recipe incorporates SPOOLES 2.2, https://www.netlib.org/linalg/spooles/. The Gmsh wheel includes its upstream CAD/mesher implementation unchanged. Windows and Linux builds bundle the unmodified conda-forge `calculix` 2.23 package (https://github.com/conda-forge/calculix-feedstock) and the conda-forge ARPACK, BLAS/LAPACK and GCC runtime libraries it links; on Linux only their library search path is changed, to the solver's own folder. Windows builds also include the MinGW-w64 winpthreads runtime (MIT-style license, https://www.mingw-w64.org/). +The solver is built on every platform by `scripts/build-solver.py` from the CalculiX 2.23 source archive (SHA-256 `9c88385c10fb04f5dc6c4e98027a51bebdd8aee3920e05190d6c1dd08357d6e7`) and SPOOLES 2.2 (SHA-256 `a84559a0e987a1e423055ef4fdf3035d55b65bbe4bf915efaa1a35bef7f8c5dd`), with compilers and libraries from conda-forge (`native/calculix/solver-env-*.yml`). The build checks CalculiX's license notices and stops if they are no longer the GPL version 2 ones described here. Its modifications to CalculiX are all in this repository: + +- the SPOOLES patches in `native/calculix/spooles-patches`; +- two small compile fixes: a void function's return value (also fixed in Homebrew's `costerwi/homebrew-calculix` formula), and a Windows-only call outside any function that only affected the old msvcrt; +- `native/calculix/accelerate_pardiso.c`, which answers CalculiX's PARDISO calls with Apple Accelerate on macOS; +- `native/calculix/pardiso_client.c`, which hands them to `sprung-solve` on Linux and Windows; +- `native/calculix/mkl_service.h`, which stands in for MKL's header so that CalculiX compiles without MKL. + +These additions are GPL-2.0-or-later. CalculiX's PaStiX interface is not built. `ccx` links the unmodified conda-forge ARPACK, OpenBLAS and GCC (or, on macOS, LLVM OpenMP) runtime libraries. + +`sprung-solve` is built by the same script from `native/sprung-solve` and the unmodified static libraries of Intel oneMKL (conda-forge `mkl-static`), with GCC and GNU OpenMP on Linux, and on Windows with Microsoft's C compiler and LLVM OpenMP. Intel's license permits redistributing MKL without modification, provided its copyright notice and terms are reproduced; they ship beside `sprung-solve` and in `licenses/`. + +Bundling changes only the libraries' search paths (Linux) or install names (macOS), to each program's own folder. Windows builds also include the MinGW-w64 winpthreads runtime (MIT-style license, https://www.mingw-w64.org/), and Microsoft's Visual C++ runtime library `vcruntime140.dll`, which conda-forge's OpenBLAS and `sprung-solve` need, under Microsoft's terms for redistributable Visual C++ runtime files. The Gmsh wheel includes its upstream CAD/mesher implementation unchanged. -License texts in `licenses/` are included in packaged builds. Electron additionally includes Chromium's own third-party notices. Build scripts collect the installed native and JavaScript dependency notices. This repository currently produces a local developer build; a public binary release must also provide corresponding source for GPL/LGPL components and their build modifications, alongside the binary distribution. Upstream source URLs alone are not a replacement for that source distribution. +License texts in `licenses/` are included in packaged builds. Electron additionally includes Chromium's own third-party notices. Build scripts collect the installed native and JavaScript dependency notices. This repository currently produces a local developer build. A public binary release must also provide the corresponding source for the GPL and LGPL components and their build modifications, alongside the binary distribution. Intel oneMKL has no source to provide; it is not a GPL component. Upstream source URLs alone are not a replacement for that source distribution. diff --git a/docs/solidworks-fea-gap-audit.md b/docs/solidworks-fea-gap-audit.md new file mode 100644 index 0000000..ea41c23 --- /dev/null +++ b/docs/solidworks-fea-gap-audit.md @@ -0,0 +1,175 @@ +# Sprung FEA versus SOLIDWORKS Simulation + +Assessment date: 5 October 2026. Evaluated the current working tree, including uncommitted contact/bolt changes, on top of `49cd375`. This is a product capability assessment, not a certification, benchmark against a running SOLIDWORKS installation, or estimate of engineering work remaining. + +## Completion estimate + +| Comparison scope | Estimated coverage | Interpretation | +|---|---:|---| +| SOLIDWORKS Simulation Standard | **50–60%, midpoint 55%** | Substantial static capability; missing fatigue, motion, many connectors, and study-management depth. Features from higher tiers do not replace these gaps. | +| SOLIDWORKS Simulation Professional | **45–55%, midpoint 50%** | Modal, buckling, thermal and limited submodeling are present; optimization, topology, drop testing, pressure-vessel workflows and assembly breadth are missing. | +| SOLIDWORKS Simulation Premium | **35–45%, midpoint 40%** | Nonlinear static and harmonic response provide some advanced coverage; broader dynamic analyses, nonlinear materials and composites are missing. | +| Everyday homogeneous solid-part static workflow | **75–85%, midpoint 80%** | Import, supports, common loads, solve, inspect, refine and save are well covered. This intentionally excludes shells, beams, complex joints and the other missing study families. | + +The reference is **desktop SOLIDWORKS Simulation**, including its CAD integration. This does not include the entire SOLIDWORKS CAD feature set, Flow Simulation, Plastics, or the wider Abaqus-based SIMULIA portfolio. SOLIDWORKS differentiates Standard, Professional and Premium by supported study families; see the [official product overview](https://www.solidworks.com/product/solidworks-simulation) and [2026 desktop feature matrix](https://www.solidworks.com/sites/default/filesd10/26docs06/solidworks-simulation-feature-matrix.pdf). + +These percentages are judgment-based ranges. They measure usable breadth and depth, rather than counting menu entries or solver keywords. A narrow implementation gets partial credit, and capabilities of CalculiX or Gmsh that the application does not expose get no credit. They do not mean that 40% of development effort is complete or that numerical accuracy is 40% of SOLIDWORKS. + +An illustrative weighting behind the Premium estimate is: + +| Area | Weight | Current coverage within area | Weighted contribution | +|---|---:|---:|---:| +| CAD association and model preparation | 10 | 30% | 3.00 | +| Element formulations and meshing | 15 | 40% | 6.00 | +| Material models | 10 | 35% | 3.50 | +| Loads and constraints | 10 | 70% | 7.00 | +| Assembly contact and connectors | 15 | 35% | 5.25 | +| Analysis families and controls | 20 | 40% | 8.00 | +| Results and engineering diagnostics | 10 | 60% | 6.00 | +| Study management, automation and communication | 10 | 20% | 2.00 | +| **Total** | **100** | | **40.75 / 100** | + +The category scores are expert estimates, not independently measured constants. Different customer workloads would justify different weights. Standard and Professional ranges are separate estimates for their narrower scopes; the application’s higher-tier capabilities are listed separately below. + +## Working capability inventory + +| Area | Implemented behavior | Scope limits | +|---|---|---| +| Static | Linear elasticity; large deformation; isotropic plasticity from bilinear or tabulated hardening; loading/unloading frames and permanent set | Limited material families and fixed load-control procedure | +| Modal | Free and restrained modes, rigid-motion identification, stress stiffening from optional mechanical preload, effective mass, animation, point masses | 1–50 modes; no transfer of a solved nonlinear contact/bolt state | +| Buckling | Linear eigenvalue factors and shapes; overload and yield-before-buckling warnings | No dedicated imperfection/postbuckling workflow | +| Thermal | Steady and transient conduction, fixed temperature, total heat input, global heat generation, convection, radiation to ambient, heat-flux magnitude | Uniform initial temperature; conditions switch on at time zero; no thermal interface resistance | +| Thermal stress | Coupled temperature/displacement solve, thermal expansion with stress-free temperature, mechanical loading, time frames | Linear elastic mechanical response; no full contact/plastic/large-deformation coupling | +| Harmonic | Modal response to sinusoidal loads or equivalent base acceleration; damping ratio; stress/displacement amplitude curves | Uniform modal damping, fixed sampling strategy, at most 40 frequencies with stored nodal fields | +| Assembly | Multiple STEP solids, bonded shared interfaces, material per body, per-connected-group restraint checks | Flattened body representation, no full assembly hierarchy or revision association | +| Contact and bolts | Initially touching interfaces can separate/slide, frictional or frictionless penalty contact, solid-bolt pretension, torque-to-preload helper, bolt-force charts and contact-force/state/pressure results | Static only; contact settings grouped by body pair; solid bolt geometry required | +| Supports and loads | Fixed, directional, normal/frictionless and cylindrical supports; force, pressure, gravity, remote force, moment, bearing load, centrifugal rotation; point mass | Face selection; limited reference frames and distribution options | +| Mesh | Curvature-aware quadratic tetrahedra, size presets/custom size, preview, minimum signed quality, direct/iterative static solver choice, thread controls | One solid formulation and one exposed mesh-sizing workflow | +| Convergence | Repeated global refinement with tolerance, charts, conditional Richardson estimate and likely-singularity detection | Global size reduction rather than local error-driven adaptation | +| Submodel | Finer boxed single-part region driven by parent displacement; stress and cut-boundary comparison | Linear local formulation; restrictions on split remote/bearing/moment loads and point masses | +| Results | von Mises, largest/smallest principal stress, maximum shear, equivalent/principal strain, displacement, yield margin, plastic strain, temperatures, flux, contact pressure | Averaged nodal fields; narrower result selection than SOLIDWORKS | +| Viewer | Probe interpolated or extreme-node values, axis-aligned section with forces/moments, iso-surface, threshold, deformation and animation, mesh edges, standard views, perspective/orthographic | No arbitrary section orientation, persistent probe sets or editable contour scale | +| Usability | SI/US conversion, draft editors, face search, naming/edit/delete, undo/redo, shortcuts, cancellation, themes, autosave recovery, embedded-geometry projects, saved results | One active study, one recovery copy; incomplete result presentation/artifact persistence | +| Export | Surface CSV, viewport PNG, enlarged chart CSV/PNG, CalculiX deck, FRD and log | No generated engineering report or complete portable solver archive | + +Implementation evidence: [analysis registry and static/modal/buckling implementations](../engine/analyses.py), [thermal](../engine/thermal.py), [harmonic](../engine/harmonic.py), [contact](../engine/contact.py), [CAD and mesh](../engine/cad.py), [submodel](../engine/submodel.py), [convergence](../engine/convergence.py), [domain types](../src/types.ts), [inspector](../src/Inspector.tsx), [viewer](../src/scene.ts), [application state](../src/App.tsx), and [chart exports](../src/Chart.tsx). + +## Missing features and incomplete depth + +The following lists inventory missing application behavior. Some operations can be approximated manually or by exporting/editing a CalculiX deck; that is not application feature parity. Entries concerning native geometry tools refer to their role in preparing or maintaining a simulation, not a request to build a complete CAD modeler. + +**Attribution qualification:** the major analysis families and linked SOLIDWORKS functions are confirmed reference capabilities. The long tail also includes proposed product improvements for Sprung FEA, such as a general job queue, comprehensive portable solver archives and broader nonlinear thermomechanical handoffs. These should not be read as a claim that every listed behavior is a native Premium feature, or that every feature works in every study/element/contact combination. The coverage estimate is a rough weighted product assessment, not an exact count of confirmed SOLIDWORKS checkboxes. + +### Analysis and optimization + +- **Fatigue:** S–N data, constant/variable-amplitude events, imported load histories, cycle counting, damage and life plots, mean-stress corrections and cumulative damage. Existing plastic unloading is not fatigue. SOLIDWORKS documents the event/history/S–N workflow in [Performing Fatigue Analysis](https://help.solidworks.com/2023/english/SolidWorks/cworks/t_Performing_Fatigue_Analysis.htm). +- **Structural time history:** modal transient dynamics, time-dependent mechanical loads and base excitation, velocity/acceleration output and damping controls. Transient temperature frames do not supply this capability. +- **Other dynamics:** random vibration/PSD, response spectrum and nonlinear transient dynamics. Harmonic response covers one part of the desktop dynamic suite; see the [official analysis-family overview](https://www.solidworks.com/lp/3d-simulation). +- **Drop tests and impact:** drop orientation, target/contact setup, impact response and time-dependent result inspection. +- **Motion:** rigid-body mechanisms, mates, motors and time/event-driven motion; transfer of motion-generated loads to stress analysis. +- **Parametric design studies:** parameter tables, batch evaluation, goals/constraints, scenario ranking and optimization. +- **Topology optimization:** minimum-material design, preserved regions, design constraints, manufacturing restrictions and optimized-geometry output. SOLIDWORKS describes these controls in its [topology workflow](https://blogs.solidworks.com/products/solidworks/best-setups-for-manufacturing-controls-in-topology-study/). +- **Pressure-vessel studies:** combinations of solved stress states, stress classification/linearization and vessel-specific assessment. Applying pressure and integrating section forces does not implement this study type. +- **Nonlinear controls:** prescribed-displacement driving, user-defined load sequences, fixture activation/release, configurable increments/convergence, force/displacement/arc-length control and restart workflows. Large-deformation capability alone does not establish robust postbuckling/snap-through support. +- **Analysis combinations:** supported handoff of a nonlinear contact/bolt solution into modal/dynamic studies, and nonlinear thermomechanical contact/plasticity workflows. + +### Elements, geometry and meshing + +- Shells, midsurface extraction, shell thickness/offset/orientation, top/bottom and through-thickness results. +- Beams/trusses, section libraries, weldment idealization, beam joints/releases and beam force/moment diagrams. +- Mixed solid/shell/beam models and their connection rules. +- Plane stress, plane strain and axisymmetric simplification. +- Selectable linear/quadratic element quality and formulation choices beyond C3D10. +- **Local mesh controls** on a face, edge, vertex, component or region within the original global mesh. A separate boxed submodel is different. SOLIDWORKS exposes entity-specific size and transition ratio through [mesh controls](https://help.solidworks.com/2024/english/SolidWorks/cworks/t_Applying_Mesh_Control_to_Mixed_Types.htm?id=7767cf4ff3d04bf785a329cdaa6bcefc). +- Error-driven adaptive refinement; the current convergence tool reduces global mesh size. Adaptive availability should be assessed for the particular SOLIDWORKS release/mesher rather than treated as a timeless license promise. +- Mesh-quality distributions and plots, aspect-ratio/Jacobian views, bad-element localization and actionable mesh-failure diagnostics. Current minimum signed quality is useful but much narrower; see [SOLIDWORKS mesh options](https://help.solidworks.com/2024/english/SolidWorks/cworks/IDC_HELP_PREFERENCE_MESH.htm?id=26.10.5.3). +- Choice of meshing strategies and transition/minimum-size/curvature tolerances. +- CAD repair, small-feature suppression, simulation-specific defeaturing and split-face tools for applying loads to part of a CAD face. +- Native CAD/configuration association, load/support selection remapping after geometry revisions, and unresolved-selection review. +- Direct native SOLIDWORKS/Parasolid/IGES intake. The public application currently accepts STEP solids; the presence of OpenCASCADE does not expose all of its file readers. +- Preservation of CAD component names, nested assembly hierarchy, instance identity and study-specific exclusions. + +### Materials and thermal depth + +- Orthotropic/anisotropic elasticity and conductivity, material orientation and laminate composites. +- Composite ply stacks, ply results and composite failure criteria. +- Hyperelastic rubber models, nonlinear elastic materials, viscoelasticity and creep; broader plasticity/hardening choices. The existing model is isotropic hardening. SOLIDWORKS lists its nonlinear material families in [Nonlinear Static Analysis Overview](https://help.solidworks.com/2023/english/SolidWorks/cworks/c_nonlinear_static_analysis_overview.htm). +- A substantial searchable material database and saved reusable custom-material library; currently four presets plus study-local edits. +- Material-data import, provenance and reusable curve datasets. +- Temperature tables for properties beyond the existing modulus/conductivity/expansion subset, including temperature-dependent heat capacity and strength. +- Thermal contact resistance/conductance, imperfect interfaces and imported pressure/temperature fields from external analyses. +- Surface-to-surface radiation and enclosure/view-factor treatment; ambient radiation is already implemented. Compare [SOLIDWORKS surface-to-surface radiation](https://help.solidworks.com/2024/English/SolidWorks/Cworks/t_Defining_Surface_to_Surface_Radiation.htm). +- Thermal conditions varying with time or position, nonuniform initial temperatures, body-specific heat sources and finer control of output/time increments. + +### Contact, connectors, supports and loads + +- Contact across initial clearances, independently meshed nonmatching interfaces, user-selected face-to-face contact sets and contact scoped more finely than a body pair. +- Shrink/interference fits, virtual walls, self-contact and broader contact-search/adjustment controls. +- Idealized bolt connectors without meshing a solid bolt, automatic fastener conversion, thread tensile-area/proof-strength setup and connector safety checks. Current solid-bolt pretension is valuable but solves a different setup problem. Compare [automatic fastener conversion](https://help.solidworks.com/2023/english/SolidWorks/cworks/c_wn2014_automatic_conversion_fasteners.htm?format=P&value=). +- Pins, bearing connectors with stiffness, user-defined springs/dampers, elastic foundations, weld connectors, rigid links, linkage rods, general springs and cables. A bearing pressure load is not a bearing connector; internal contact stabilization springs are not user-defined spring connectors. See the [connector summary](https://help.solidworks.com/2020/English/SolidWorks/cworks/c_Summary_of_Connectors.htm) and [2026 matrix](https://www.solidworks.com/sites/default/filesd10/26docs06/solidworks-simulation-feature-matrix.pdf). +- Prescribed nonzero translations/rotations, dedicated symmetry/cyclic-symmetry constraints and general reference-coordinate fixtures. A planar frictionless fixture can represent the normal restraint in some solid symmetry models, but there is no dedicated symmetry workflow. Compare [cyclic symmetry](https://help.solidworks.com/2025/English/SolidWorks/cworks/c_creating_valid_sections_circular_symmetry.htm?id=d50c63eeea104f1eb57030c741c5cf7c). +- Edge/vertex selection for applicable loads and constraints, reusable local coordinate systems, and reference-axis/plane selection for load directions. +- Nonuniform/hydrostatic or equation-driven pressure/force fields and imported load maps. Current pressure is uniform per selected face set; remote/moment/bearing loads have their own predefined distributions. +- Rigid versus distributed remote coupling choices, general remote constraints and point-mass rotational inertia tensors. +- Load combinations, envelopes and a load-case manager. Multiple loads currently act together within one study. +- Inertial relief for otherwise free static models. Free-body modes in a frequency analysis do not provide inertial relief. + +### Results and smaller usability gaps + +- Individual stress/shear/strain components and the middle principal value as selectable contours; displacement components as contours; principal direction/tensor and heat-flux vector plots. +- Element/energy-error results and controls for averaging at boundaries. Current results are derived from averaged nodal tensors. SOLIDWORKS provides separate [node/element result treatment](https://help.solidworks.com/2020/english/SolidWorks/cworks/c_Node_Values_versus_Element_Values.htm?id=27.19.0.13.1). +- Multiple failure criteria and separate tensile/compressive limits. The current safety plot is a von-Mises-based yield ratio; plotting Tresca stress does not add a Tresca-based safety calculation. See the [factor-of-safety options](https://help.solidworks.com/2021/english/SolidWorks/cworks/IDH_HELP_DESIGNCHECK.htm?id=8fc4d024f4954e8aa58496661476fe2b). +- **Per-body yield margins and warnings:** current display and summary use `study.material.yield`, even with per-body materials. This is a concrete correctness gap for heterogeneous assemblies, not just a missing UI preference (`src/App.tsx:984`, `engine/analyses.py:307`). +- Reactions split by support/body/selected entity and a fuller free-body result workflow. Current aggregate reactions and section forces are partial coverage. +- Saved multiple probes, probe tables, edge/path plots, point histories, result sensors and alert thresholds. +- Arbitrarily oriented sections using a plane/normal/reference entity; current section normals are X/Y/Z. Compare [section plots](https://help.solidworks.com/2019/english/SolidWorks/cworks/t_Creating_Section_Plots.htm?id=e18975a5a9f04f369f896979a7ee4cd0). +- Editable contour limits, discrete bands, alternate/colorblind palettes, legend positioning/formatting and common scales across frames/studies. Current frame-dependent autoscaling makes comparisons less convenient. SOLIDWORKS exposes [color-chart settings](https://help.solidworks.com/2023/english/SolidWorks/cworks/idh_help_preference_color_chart.htm) and a [colorblind option](https://help.solidworks.com/2015/english/WhatsNew/wn2015_viewing_sim_results_colorblind.htm?id=23.9). +- User-specified deformation multiplier, original/deformed overlays, saved named views, plot definitions and persisted presentation state. +- Body hide/show/isolate, transparency, exploding an assembly and selection of obscured interfaces. +- Named selection sets, box/lasso selection, select-through and richer face filtering/grouping. +- Duplicate/suppress conditions and bulk editing; named study templates. +- Multiple named studies per geometry, copying definitions between studies, configuration association, side-by-side comparison and iteration trend tracking. Switching analysis preserves much of the setup, but replaces the active study. See [copying definitions between studies](https://help.solidworks.com/2025/english/SolidWorks/Cworks/c_Drag_and_Drop_Functionality.htm). +- Batch solve/queue management, retained run history and a supported user-facing scripting/automation interface. The internal HTTP/worker interfaces are a starting point, not a finished automation product. +- Live nonlinear intermediate-result inspection, richer residual/contact-convergence diagnostics, configurable result sampling and restart/recovery of solver jobs. +- Automatic engineering reports with assumptions, inputs, mesh, results, warnings and convergence evidence; interactive review/sharing such as eDrawings. +- Full volumetric/multiframe export through the UI and animation-video export. Existing surface and chart CSV/PNG exports should receive credit. +- Portable archives retaining solver inputs/logs and submodel results. Saved whole-part results work, but solver artifacts require another solve after opening; region results are not embedded. +- Multiple recent projects/recovery histories rather than the current single autosave entry. +- Predictive memory/DOF budgeting and richer progress/resource feedback before large jobs. STEP intake is limited to 50 MB; the viewer uses a 32-bit WASM heap. These are scale constraints, not reasons to claim all large models fail. + +## What goes beyond SOLIDWORKS? + +### Clear product advantages + +1. **Native macOS execution**, including Apple Silicon, with packaging configured for Windows and Linux. Desktop SOLIDWORKS client requirements are Windows-based; the macOS product listed separately is eDrawings. The strongest demonstrated platform claim here is the existing Apple Silicon acceptance evidence; this assessment does not establish fresh Windows/Linux acceptance. See [SOLIDWORKS system requirements](https://www.solidworks.com/support/system-requirements) and the repository [build workflow](../.github/workflows/build.yml). +2. **GPL-licensed source and no Simulation license-tier gating.** Users can inspect, modify and redistribute under the license. The SOLIDWORKS tiered commercial offering is described in its [product overview](https://www.solidworks.com/product/solidworks-simulation). +3. **A standalone, CAD-independent application** with inspectable CalculiX inputs/results/logs and an editable source pipeline. This supports customization without needing SOLIDWORKS CAD. Importing neutral CAD files itself is not unique. + +### Distinctive implementations, without an exclusivity claim + +- The convergence workflow combines separate quantity verdicts, conditional Richardson extrapolation and a plain-language likely-singularity warning. +- A boxed submodel reports explicit cut-boundary agreement with the parent solution. +- The UI places section force/moment integration near visual section controls and labels deformation magnification plainly. +- Geometry/setup/results fit into a portable project, with conservative invalidation when the physical setup changes. +- A focused interface and bundled local runtime can reduce setup complexity for occasional users; this is a design advantage hypothesis, not a measured usability finding. + +SOLIDWORKS also has convergence/hot-spot diagnostics, submodeling, section results, local solving, undo, unit conversion, probes, animation and automation APIs. Those should not be presented as unique physics or automatically superior features. No code/source evidence in this audit establishes better speed, accuracy or robustness than SOLIDWORKS Simulation Premium. + +Relative to **Standard's license scope**, the project offers modal, buckling, thermal, harmonic and nonlinear-material workflows normally associated with higher SOLIDWORKS tiers. That is valuable accessible breadth, while those same capabilities remain partial parity against Premium. + +## Highest-value next steps + +1. Fix heterogeneous-body yield assessment and constrain/validate nonlinear-parent submodel use; refresh validation documentation to match current code. +2. Add named studies, duplication/suppression, load cases, body isolation, saved probes and editable/shared contour limits. +3. Add local mesh controls, quality localization, richer material reuse and automatic reports. These improve most existing studies. +4. For assembly parity, add gaps/nonmatching contact, prescribed displacement, simplified bolts and pin/spring/weld connectors. +5. Choose the next physics family by customer work: shells/beams for thin structures and frames; fatigue for repeated loading; random/time-history dynamics for vibration; design/topology optimization for weight reduction. + +Feature completion and engineering confidence are separate. The repository has meaningful analytic and equilibrium tests, including real solver executions, but its recorded validation lacks independent commercial-solver comparison, physical correlation and a representative customer CAD corpus. The validation page also predates several currently implemented analysis families; its old exclusions should not be mistaken for current feature absence. + +## Verification performed for this assessment + +- TypeScript project compilation passed. +- `npm test`: all 7 tests passed after allowing the local test server to bind outside the sandbox. The initial restricted run passed the pure tests and failed two service tests because loopback binding was unavailable. +- Full existing engine suite: **86 tests passed in 384 seconds**, including real Gmsh/CalculiX executions for assemblies, contact/bolts, convergence, static, modal, buckling, harmonic, thermal, plasticity, supports/loads and submodeling. Gmsh/PETSc emitted nonfatal hostname-access diagnostics under the sandbox; the test assertions completed successfully. +- Browser and packaged application tests were inspected as evidence of coverage but were not rerun for this assessment. No commercial SOLIDWORKS solve or comparative timing benchmark was performed. diff --git a/docs/solver-protocol.md b/docs/solver-protocol.md new file mode 100644 index 0000000..ad68ddd --- /dev/null +++ b/docs/solver-protocol.md @@ -0,0 +1,59 @@ +# The sprung-solve protocol + +`sprung-solve` (`native/sprung-solve`, MIT license) is a stand-alone program that solves sparse linear systems with Intel oneMKL's PARDISO. On Linux and Windows, Sprung FEA's CalculiX build sends its PARDISO solves to it (`native/calculix/pardiso_client.c`). It runs as a separate process with its own address space, and it is linked with MKL, which CalculiX is not. Any program can use it the same way, or run it from the command line: + +``` +sprung-solve --serve # the protocol below, on standard input and output +sprung-solve --version # checks that PARDISO solves here; prints "sprung-solve 1: " +sprung-solve A.mtx [b.mtx] # solves a Matrix Market system and prints x, one value per line +``` + +`A.mtx` is a square coordinate matrix, real or integer, general or symmetric. Symmetric files list the lower triangle, as Matrix Market does, and duplicate entries add up. `b.mtx` is an array with one column. Without it, b is all ones. + +## Transport + +With `--serve`, the client writes requests to the program's standard input and reads replies from its standard output, one reply per request, in order. Standard error carries diagnostics only. The program exits when its input closes. On Linux it also exits when its parent process does, even in the middle of a factorization. CalculiX's client on Windows puts it in a job object that closes with CalculiX, which has the same effect. + +Every value is little-endian: `u32`/`i32` take 4 bytes, `u64`/`i64` 8 bytes, and `f64` is an IEEE double. Nothing is padded. The constants are in `native/sprung-solve/protocol.h`. + +## Requests + +Every request starts with a 16-byte header: + +| Field | Type | Meaning | +|---|---|---| +| magic | u32 | `0x53525053` ("SPRS") | +| op | u32 | 0 HELLO, 1 FACTOR, 2 SOLVE, 3 RELEASE | +| handle | u64 | chosen by the client; names one factorization | + +A client can keep any number of factorizations at once, each under its own handle. CalculiX uses the address of its PARDISO handle array. + +| Request | Payload after the header | +|---|---| +| HELLO | `u32 version` (1) | +| FACTOR | `u32 kind`, `u32 threads`, `i64 n`, `i64 nnz`, `i64 row_start[n+1]`, `i64 column[nnz]`, `f64 value[nnz]` | +| SOLVE | `i64 n`, `i64 nrhs`, `f64 b[n*nrhs]` (one right-hand side after another) | +| RELEASE | nothing | + +FACTOR takes the matrix in compressed sparse rows: 0-based, with `row_start[0] = 0`, `row_start[n] = nnz`, and the columns of each row strictly ascending. `kind` is one of: + +- `0` symmetric: only the upper triangle, and every diagonal entry, even a zero one. PARDISO factors it as symmetric indefinite, so shifted systems such as those of eigenvalue analyses are fine. +- `1` structurally symmetric: every entry. +- `2` unsymmetric: every entry. + +`threads` is the number of threads to factor and solve on. Zero leaves the choice to MKL, which reads `MKL_NUM_THREADS`. + +A FACTOR on a handle that already holds a factorization replaces it. When the kind and the structure (`row_start`, `column`) are unchanged, PARDISO's analysis (ordering and symbolic factorization) is kept and only the numeric factorization is redone. This is how a nonlinear step's iterations refactor. + +## Replies + +Every reply is `i32 status`, `u32 length`, and then `length` bytes of UTF-8 text with no terminator. + +- **Status 0** means the request was done. The text is the solver's name after HELLO (for example, "Intel oneMKL 2026.1 PARDISO") and empty otherwise. A successful SOLVE then sends `f64 x[n*nrhs]`. +- **Any other status** means the request failed and nothing else follows. The text says what went wrong. Negative statuses after FACTOR or SOLVE are PARDISO's own error codes; for example, -4 means a zero pivot, so the system is singular. A failed FACTOR leaves the handle empty. + +A request that cannot be read (wrong magic, an unknown op, input ending in the middle) ends the program with a message on standard error. The client sees its output close. + +## Versions + +HELLO must come first. A program that does not speak the requested version answers with a nonzero status. Version 1 is the one described here. diff --git a/docs/validation.md b/docs/validation.md index 5b8b956..7b6b10f 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -41,7 +41,7 @@ Two further pressure references test curved loading: 1. CalculiX fixed-width numerical input rejected an unformatted density exponent. Deck scalars now use bounded significant-digit formatting. 2. Quadratic force loading must integrate face shape functions; equal force per surface node would bias the response. Force distribution conserves its requested total over multiple selected faces. 3. CalculiX RF output contains both support reactions and applied nodal loads. Equivalent force/pressure/gravity contributions are removed when computing support reactions, including overlap at supported nodes. -4. This machine's multi-threaded SPOOLES factorization intermittently returned materially different responses for identical input. All solver, assembly, result, and BLAS stages are now pinned to one thread. Repeated identical-input solves pass, and the setting is carried into the bundled engine. +4. This machine's multi-threaded SPOOLES factorization intermittently returned materially different responses for identical input. SPOOLES 2.2 hands work between threads without memory ordering, which Apple silicon exposes. The bundled solver now carries conda-forge's SPOOLES threading fixes and uses Apple Accelerate as its direct solver on macOS; assembly, stress recovery and the direct solver run on all threads, and threaded solves match a single-threaded SPOOLES solve to round-off (`tests/test_solvers.py`). 5. Narrow viewports originally cropped geometry; camera fitting now accounts for both viewport dimensions. 6. Zero-resultant bore pressure exposed an unsuitable force-balance denominator. The residual now uses the absolute equivalent nodal loading as its scale when loads cancel. 7. Project save was intercepted by a generic job route; the route now passes save requests through to serialization, with acceptance coverage. diff --git a/engine/analyses.py b/engine/analyses.py index bc680f7..ff79586 100644 --- a/engine/analyses.py +++ b/engine/analyses.py @@ -26,8 +26,11 @@ def von_mises(s): - xx,yy,zz,xy,yz,zx=s[:6] - return math.sqrt(max(0,((xx-yy)**2+(yy-zz)**2+(zz-xx)**2)/2+3*(xy*xy+yz*yz+zx*zx))) + """Von Mises stress of one stress tensor (SXX, SYY, SZZ, SXY, SYZ, SZX), + or of each row of an array of them.""" + s=np.asarray(s,float) + xx,yy,zz,xy,yz,zx=(s[...,i] for i in range(6)) + return np.sqrt(np.maximum(0,((xx-yy)**2+(yy-zz)**2+(zz-xx)**2)/2+3*(xy*xy+yz*yz+zx*zx))) def stress_fields(tensors): @@ -38,7 +41,7 @@ def stress_fields(tensors): xx,yy,zz,xy,yz,zx=t.T matrix=np.stack([np.stack([xx,xy,zx],-1),np.stack([xy,yy,yz],-1),np.stack([zx,yz,zz],-1)],-2) principal=np.linalg.eigvalsh(matrix) - return {'vonMises':np.array([von_mises(s) for s in t]),'principalMax':principal[:,2], + return {'vonMises':von_mises(t),'principalMax':principal[:,2], 'principalMin':principal[:,0],'shear':(principal[:,2]-principal[:,0])/2} @@ -69,9 +72,10 @@ def measures(frame, ids): def nodal(frame, label, ids, count, what): """Values of one FRD field at the mesh's nodes, first `count` components.""" data=frame['fields'].get(label) - if not data or any(n not in data for n in ids): + rows=data.at(ids) if data else None + if rows is None or rows.shape[1]yield_strength: warnings.append('Stress exceeds the material yield strength. The elastic model cannot predict permanent deformation: turn on Plasticity in the Analysis settings.') - if calculix.solver_of(study)!='spooles' and balance>.005 and not follower: + if calculix.solver_of(study)!='direct' and balance>.005 and not follower: # CalculiX's incomplete-Cholesky solver occasionally stops early. warnings.append(f'The iterative solver stopped with a {balance*100:.2g}% force balance error. Use the direct solver for a tighter answer.') if large: @@ -482,13 +494,14 @@ def deck(self, folder, study, mesh): lines+=calculix.section_lines(model,study) if held: lines+=calculix.boundary_lines(held) lines+=calculix.mass_lines(model,masses,[rbe3(model,m['faces'],m['point']) for m in masses],held) + direct=self.solver(study)[0] if preload: # No output from the static step: every frame is a mode. - lines+=['*STEP','*STATIC, SOLVER=SPOOLES']+calculix.load_lines(build_loads(study,model))+['*END STEP', - '*STEP, PERTURBATION','*FREQUENCY, SOLVER=SPOOLES',str(count)] + lines+=['*STEP','*STATIC, SOLVER='+direct]+calculix.load_lines(build_loads(study,model))+['*END STEP', + '*STEP, PERTURBATION','*FREQUENCY, SOLVER='+direct,str(count)] else: # A free part needs a negative shift: its stiffness is singular. - lines+=['*STEP','*FREQUENCY, SOLVER=SPOOLES',f'{count+rigid}, -1' if rigid else str(count)] + lines+=['*STEP','*FREQUENCY, SOLVER='+direct,f'{count+rigid}, -1' if rigid else str(count)] lines+=['*NODE FILE','U','*EL FILE','S','*END STEP'] (folder/'analysis.inp').write_text('\n'.join(lines)+'\n') return {'rigid':rigid,'preload':preload} @@ -504,7 +517,7 @@ def results(self, folder, study, model, frames, context): view=[];info=[];frequencies=[];fractions=[];unstable=False for k,frame in enumerate(frames): shape,stress=normalized(nodal(frame,'DISP',ids,3,'mode shape'), - np.array([von_mises(s) for s in nodal(frame,'STRESS',ids,6,'mode shape')])) + von_mises(nodal(frame,'STRESS',ids,6,'mode shape'))) value=eig[k][1] hz=max(0.,value[2]) if value[0]>0 else 0. unstable|=preload and value[0]<0 @@ -560,7 +573,7 @@ def deck(self, folder, study, mesh): loading=build_loads(study,model,m['density']*1e-12) lines=calculix.mesh_lines(model,'linear buckling study') lines+=calculix.section_lines(model,study)+calculix.boundary_lines(fixed) - lines+=['*STEP','*BUCKLE, SOLVER=SPOOLES',str(count)] + lines+=['*STEP','*BUCKLE, SOLVER='+self.solver(study)[0],str(count)] lines+=calculix.load_lines(loading) lines+=['*NODE FILE','U','*EL FILE','S','*END STEP'] (folder/'analysis.inp').write_text('\n'.join(lines)+'\n') @@ -573,7 +586,7 @@ def results(self, folder, study, model, frames, context): base,modes=frames[0],frames[1:] if not factors or len(modes)=5} + return {} + + def find_ccx(): candidates=[os.environ.get('SPRUNG_FEA_CCX'),shutil.which('ccx'),shutil.which('ccx_2.23'), '/opt/homebrew/opt/calculix-ccx/bin/ccx_2.23','/usr/local/opt/calculix-ccx/bin/ccx_2.23'] @@ -49,18 +141,21 @@ def read_log(path): def run(folder, name='analysis'): """Runs CalculiX on folder/name.inp. Returns the iterative-solver summary, or None for direct solves; raises with the log tail on failure.""" - # Assembly, SPOOLES factorization and stress recovery use CalculiX's own - # thread controls, which gave bit-identical results over 20 repeated - # solves at 8 threads. OpenMP must stay at one thread: OMP_NUM_THREADS or - # NUMBER_OF_CPUS above 1 together with any CCX_NPROC above 1 made stress - # and reactions vary between identical runs, sometimes grossly (a 1000 N - # reaction reported as 866 N). CalculiX's iterative solvers iterate on - # one thread regardless. + # CalculiX threads stiffness assembly, the direct solver and stress + # recovery itself; NUMBER_OF_CPUS caps all three, and at 1 left every + # stage serial. Assembly and stress recovery give the same answer to + # round-off at any thread count. SPOOLES is threaded only where it is + # safe (capabilities). Accelerate follows VECLIB_MAXIMUM_THREADS, and MKL + # (in sprung-solve) MKL_NUM_THREADS. OpenMP stays at one thread. + # CalculiX's iterative solvers iterate on one thread regardless. n=str(threads()) + equations=n if capabilities().get('threadSafeSpooles') else '1' env={k:v for k,v in os.environ.items() if not k.startswith('CCX_NPROC')} - env.update(OMP_NUM_THREADS='1',NUMBER_OF_CPUS='1',OPENBLAS_NUM_THREADS='1', + env.update(OMP_NUM_THREADS='1',NUMBER_OF_CPUS=n,OPENBLAS_NUM_THREADS='1',VECLIB_MAXIMUM_THREADS=n,MKL_NUM_THREADS=n, GFORTRAN_UNBUFFERED_PRECONNECTED='1', - CCX_NPROC_RESULTS=n,CCX_NPROC_STIFFNESS=n,CCX_NPROC_EQUATION_SOLVER=n) + CCX_NPROC_RESULTS=n,CCX_NPROC_STIFFNESS=n,CCX_NPROC_EQUATION_SOLVER=equations) + env.pop('SPRUNG_FEA_SOLVE',None) + if find_helper(): env['SPRUNG_FEA_SOLVE']=find_helper() # No time limit: large models can solve for a long time, and the user can # cancel the job. log_path=folder/'solver.log' @@ -112,7 +207,7 @@ def run(folder, name='analysis'): process.terminate();process.wait() error,tail,iterative=read_log(log_path) if process.returncode != 0 or error or not (folder/f'{name}.frd').exists(): - raise ValueError(failure(tail)+'\n'+tail[-2500:]) + raise ValueError(failure(tail)+stopped(process.returncode,error)+'\n'+tail[-2500:]) # CalculiX returns its last iterate without an error when conjugate # gradients stop short of the tolerance, so check the final residual. if iterative and not iterative['error']<=iterative['limit']: @@ -120,6 +215,18 @@ def run(folder, name='analysis'): return iterative +def stopped(code, error): + """How CalculiX ended when it stopped without reporting an error itself: + a crash (a signal, or a Windows exception code) rather than a model + CalculiX could not solve.""" + if error or not code: return '' + if code<0: + try: how='signal '+signal.Signals(-code).name + except ValueError: how=f'signal {-code}' + else: how=f'exit code {code:#x}' if code>0xffff else f'exit code {code}' + return f' CalculiX stopped unexpectedly ({how}).' + + def failure(tail): """A plain explanation of the most common CalculiX failures.""" if 'increment size smaller than minimum' in tail or 'too many cutbacks' in tail: @@ -133,33 +240,83 @@ def failure(tail): FIELDS={'DISP','DISPI','PDISP','STRESS','STRESSI','TOSTRAIN','FORC','NDTEMP','PE','FLUX','RFL','ERROR','CONTACT'} +class NodalField: + """One FRD result block: node ids and a row of values per node. It reads + like the {node: values} mapping it stands for; `at` gathers many nodes' + rows at once.""" + def __init__(self, ids, values): + self.ids=ids;self.values=values + self.row=np.full(int(ids.max())+1 if len(ids) else 0,-1,np.int64) + self.row[ids]=np.arange(len(ids)) + + def index(self, node): + return self.row[node] if 0<=node=0 + def __getitem__(self, node): + i=self.index(node) + if i<0: raise KeyError(node) + return self.values[i] + def get(self, node, default=None): + i=self.index(node) + return self.values[i] if i>=0 else default + + def at(self, nodes): + """Rows of the given nodes, or None if any is missing.""" + nodes=np.asarray(nodes,np.int64) + if len(nodes) and (nodes.min()<0 or nodes.max()>=len(self.row)): return None + rows=self.row[nodes] + return None if (rows<0).any() else self.values[rows] + + +def read_block(lines): + """A result block's ' -1' lines: an 11-character node field (after the + record key), then 12-character values. Continuation lines (' -2') of + fields with more than six values are not read.""" + rows=[l for l in lines if l.startswith(b' -1')] + if not rows: return NodalField(np.zeros(0,np.int64),np.zeros((0,0))) + width=len(rows[0]) + count=(width-13)//12 + if all(len(r)==width for r in rows): + table=np.frombuffer(b''.join(rows),np.uint8).reshape(len(rows),width) + ids=table[:,3:13].copy().view('S10').ravel().astype(np.int64) + values=table[:,13:13+12*count].copy().view('S12').reshape(len(rows),count).astype(float) + else: + ids=np.array([int(r[3:13]) for r in rows],np.int64) + count=min((len(r.rstrip(b'\r'))-13)//12 for r in rows) + values=np.array([[float(r[13+12*i:25+12*i]) for i in range(count)] for r in rows]).reshape(len(rows),count) + return NodalField(ids,values) + + def parse_frd(path, keep=FIELDS): """Result frames of a CalculiX .frd file, in order. A frame is one increment, mode, or frequency: consecutive blocks with the same step number and value. Each frame holds {'step', 'value', 'meta', 'fields'}; - fields map an FRD label to {node: [values]}. Fixed-width parsing: an - 11-character node field, then 12-character values.""" - frames=[];meta={};active=None;key=None;width=0 - with open(path) as frd: - for line in frd: - if line.startswith(' 1P'): - parts=line[6:].split() - if parts: meta[parts[0]]=parts[1:] - elif line.startswith(' 100C'): - value=float(line[12:24]);step=int(line[58:63] or 0) - if not frames or (frames[-1]['step'],frames[-1]['value'])!=(step,value): - frames.append({'step':step,'value':value,'meta':meta,'fields':{}}) - meta={} - elif line.startswith(' -4'): - label=line[5:13].strip() - active=frames[-1]['fields'].setdefault(label,{}) if label in keep and frames else None - width=int(line[13:18]) - elif line.startswith(' -3'): - active=None - elif active is not None and line.startswith(' -1'): - node=int(line[3:13]) - n=(len(line.rstrip('\n'))-13)//12 - active[node]=[float(line[13+12*i:25+12*i]) for i in range(n)] + fields map an FRD label to a NodalField, which reads like {node: + values}. Result blocks are converted whole, not line by line.""" + data=Path(path).read_bytes() + frames=[];meta={};pos=0;size=len(data) + while poseij',dN,points)))/24 for _,dN in TET_SHAPES],axis=1) def tetra_weights(points): @@ -91,10 +99,38 @@ def __init__(self, mesh): self.nodes=dict(zip(self.ids,coords)) self.coords=coords self._faces=None + self._index=None + + def index(self, nodes): + """Rows of node ids in coords.""" + if self._index is None: + self._index=np.full(max(self.ids)+1,-1,np.int64) + self._index[self.ids]=np.arange(len(self.ids)) + return self._index[np.asarray(nodes,np.int64)] + + def element_points(self): + """Node coordinates of every element: (elements, 10, 3).""" + return self.coords[self.index(self.mesh['elements'])] def volumes(self): """Volume of each element in mm³, by the four-point rule.""" - return np.array([sum(w for _,_,w in tetra_points(np.array([self.nodes[n] for n in c]))) for c in self.mesh['elements']]) + return tetra_jacobians(self.element_points()).sum(axis=1) + + def integrate_elements(self, load, scale): + """Equivalent nodal values of a load per unit volume, by the + four-point rule: load(positions (elements, 3)) gives (elements, k) + values at each quadrature point, `scale` multiplies each element's. + Returns (nodes, k) in coords order.""" + points=self.element_points();rows=self.index(self.mesh['elements']) + weights=tetra_jacobians(points)*np.asarray(scale,float)[:,None] + out=None + for q,(N,_) in enumerate(TET_SHAPES): + values=np.asarray(load(np.einsum('n,enj->ej',N,points)),float) + values=values.reshape(len(points),-1)*weights[:,q:q+1] + if out is None: out=np.zeros((len(self.coords),values.shape[1])) + for k in range(values.shape[1]): + out[:,k]+=np.bincount(rows.ravel(),(values[:,k:k+1]*N).ravel(),len(self.coords)) + return out def volume(self): return float(self.volumes().sum()) @@ -143,10 +179,12 @@ def element_faces(self): if self._faces is None: self._faces={} tet_faces=[(0,1,2),(0,3,1),(1,3,2),(2,3,0)] - for eid,c in zip(self.mesh['elementIds'],self.mesh['elements']): - center=np.mean([self.nodes[int(n)] for n in c[:4]],axis=0) - for num,ids in enumerate(tet_faces,1): - self._faces[tuple(sorted(c[i] for i in ids))]=(eid,num,center) + elements=np.asarray(self.mesh['elements'],np.int64) + centers=self.element_points()[:,:4].mean(axis=1) + ids=self.mesh['elementIds'] + for num,corners in enumerate(tet_faces,1): + keys=map(tuple,np.sort(elements[:,corners],axis=1).tolist()) + self._faces.update(zip(keys,zip(ids,[num]*len(ids),centers))) return self._faces def face_quadrature(self, faces): @@ -395,17 +433,16 @@ def free_motions(held, model, nodes): """Rigid motions (0 to 6) that the blocked directions on `nodes` leave. Blocking direction d at offset r removes the motions with d·(t + ω × r) = d·t + ω·(r × d) = 0.""" - coords=np.array([model.nodes[n] for n in nodes]) + coords=model.coords[model.index(sorted(nodes))] center=coords.mean(axis=0);scale=max(np.ptp(coords,axis=0)) - rows=[] blocked=[(n,np.eye(3)[a]) for n,a in held.dofs]+[(n,d) for n,ds in held.directions.items() for d in ds] - for node,d in blocked: - if node not in nodes: continue - r=(model.nodes[node]-center)/scale - rows.append([*d,*np.cross(r,d)]) + blocked=[(n,d) for n,d in blocked if n in nodes] + if not blocked: return 6 + d=np.array([d for _,d in blocked],float) + r=(model.coords[model.index([n for n,_ in blocked])]-center)/scale # A motion resisted only at round-off (fitted cylinder axes are exact to # about 1e-6) is free. - return int(6-(np.linalg.matrix_rank(np.asarray(rows),tol=1e-6) if rows else 0)) + return int(6-np.linalg.matrix_rank(np.hstack([d,np.cross(r,d)]),tol=1e-6)) def rigid_motions(fixed, model): @@ -587,14 +624,16 @@ def build_loads(study, model, density=None): for (n,a),v in loading.nodal.items(): force=np.zeros(3);force[a]=v;loading.add_applied(n,force) if np.any(loading.gravity) or loading.rotation: - if loading.rotation: omega,origin,axis=loading.rotation - for c,density in zip(model.mesh['elements'],densities): - for N,x,w in tetra_points(np.array([model.nodes[n] for n in c])): - body=loading.gravity.copy() - if loading.rotation: - r=x-origin;r-=np.dot(r,axis)*axis - body+=omega**2*r - for n,Ni in zip(c,N): loading.add_applied(n,Ni*w*density*body) + def body(x): + out=np.broadcast_to(loading.gravity,x.shape).copy() + if loading.rotation: + omega,origin,axis=loading.rotation + r=x-origin;r-=np.outer(r@axis,axis) + out+=omega**2*r + return out + forces=model.integrate_elements(body,densities) + for n in np.flatnonzero(np.abs(forces).sum(axis=1)): + loading.add_applied(model.ids[n],forces[n]) return loading diff --git a/engine/submodel.py b/engine/submodel.py index 703a5ad..184eda3 100644 --- a/engine/submodel.py +++ b/engine/submodel.py @@ -188,7 +188,7 @@ def submodel(folder, study, region): if fixed: lines+=calculix.boundary_lines(fixed) lines+=['*NSET, NSET=CUT']+calculix.rows(driven) lines+=['*SUBMODEL, TYPE=NODE, INPUT=global.frd','CUT'] - lines+=['*STEP','*STATIC, SOLVER='+calculix.SOLVERS[calculix.solver_of(study)][0], + lines+=['*STEP','*STATIC, SOLVER='+calculix.solver(study)[0], '*BOUNDARY, SUBMODEL, STEP=1','CUT, 1, 3'] lines+=calculix.load_lines(loading) lines+=['*NODE FILE','U','*EL FILE','S, E','*END STEP'] @@ -239,7 +239,7 @@ def submodel(folder, study, region): {'label':'Cut-face stress difference (95th percentile), share of peak','values':[difference*100],'unit':'%'}, {'label':'Region faces: cut, original','values':[len(cut_faces),len(faces)-len(cut_faces)],'unit':'','digits':0}], 'keys':[{'id':'maxStress','label':'Peak stress','unit':'MPa','value':peak,'peak':True}], - 'solver':'CalculiX, '+calculix.SOLVERS[calculix.solver_of(study)][1], + 'solver':'CalculiX, '+calculix.solver(study)[1], 'iterations':iterative['iterations'] if iterative else None,'threads':threads(), 'meshSize':mesh['size'],'nodeCount':mesh['nodeCount'],'elementCount':mesh['elementCount'], 'displacements':displacements.tolist(),'stress':stress.tolist(),'movement':movement.tolist()} diff --git a/engine/thermal.py b/engine/thermal.py index bb1c92b..621ce92 100644 --- a/engine/thermal.py +++ b/engine/thermal.py @@ -10,7 +10,7 @@ import numpy as np import calculix from model import (Model, finite, check_faces, check_table, fixed_dofs, rigid_motions, check_loads, - check_masses, build_loads, triangle_weights, triangle_shape, tetra_points, + check_masses, build_loads, triangle_weights, triangle_shape, QUAD, BODY_LOADS) from analyses import (Analysis, nodal, von_mises, mass_check, static_checks, measures, STRESS_FIELDS) @@ -171,12 +171,13 @@ def initial_lines(model, temperature): def step_lines(procedure, loads, outputs, timing): """The solution steps: one steady step, or the stages of a transient over the duration with the loads applied from time zero.""" + solver=calculix.direct_solver()[0] if timing is None: - return ['*STEP',procedure+', STEADY STATE','1., 1.']+loads+[l for o in outputs for l in o]+['*END STEP'] + return ['*STEP',procedure+', STEADY STATE, SOLVER='+solver,'1., 1.']+loads+[l for o in outputs for l in o]+['*END STEP'] duration=timing[0];lines=[];start=0. for k,(fraction,count,every) in enumerate(STAGES): end=fraction*duration;period=end-start - lines+=['*STEP, INC=1000',procedure+', DIRECT',f'{calculix.number(period/count)}, {calculix.number(period)}'] + lines+=['*STEP, INC=1000',procedure+', DIRECT, SOLVER='+solver,f'{calculix.number(period/count)}, {calculix.number(period)}'] if k==0: lines+=loads for keyword,names in outputs: lines+=[f'{keyword}, FREQUENCY={every}',names] lines+=['*END STEP'];start=end @@ -197,9 +198,8 @@ def add(n,q): applied[n]=applied.get(n,0.)+q gains=[heat.heat_in] if heat.heat_in>0 else [];losses=[-heat.heat_in] if heat.heat_in<0 else [] if heat.generation: - for c in model.mesh['elements']: - for N,_,w in tetra_points(np.array([model.nodes[n] for n in c])): - for n,Ni in zip(c,N): add(n,Ni*w*heat.generation) + q=model.integrate_elements(lambda x:np.ones(len(x)),np.full(len(model.mesh['elements']),heat.generation))[:,0] + for n in np.flatnonzero(q): add(model.ids[n],q[n]) # Heat into the part per unit area at a surface temperature T. exchanges=[(tri,lambda T,a=ambient,h=h:h*(a-T)) for tri,ambient,h in heat.film_faces] exchanges+=[(tri,lambda T,a=ambient,e=e:e*STEFAN_BOLTZMANN*((a-ABSOLUTE_ZERO)**4-(T-ABSOLUTE_ZERO)**4)) diff --git a/licenses/Intel-oneMKL-third-party-programs.txt b/licenses/Intel-oneMKL-third-party-programs.txt new file mode 100644 index 0000000..9a3c482 --- /dev/null +++ b/licenses/Intel-oneMKL-third-party-programs.txt @@ -0,0 +1,907 @@ +Intel(R) oneAPI Math Kernel Library (oneMKL) Third Party Programs File + +This file is the "third-party-programs.txt" file specified in the associated Intel end user license agreement for the Intel software you are licensing. + +Third party programs and their corresponding required notices and/or license terms are listed below. + +===================================================================================== +1. HPCG: High Performance Conjugate Gradient Benchmark: + Copyright (c) 2013-2019, hpcg-benchmark + All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of hpcg nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=====================================================================================--- +2. Mersenne Twister with improved initialization: + Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +=====================================================================================--- +3. SFMT: + Copyright (c) 2006,2007-2014 Mutsuo Saito, Makoto Matsumoto and Hiroshima University. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials provided with the distribution. +* Neither the name of the Hiroshima University nor the names of its contributors may be used to endorse or promote products +derived from this software without specific prior written +permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +=====================================================================================--- +4. Sobol sequence generator: + Copyright (c) 2008, Frances Y. Kuo and Stephen Joe, All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the University of New South Wales and the University of Waikato and its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + =====================================================================================-- +5. The FEAST Eigenvalue Solver: + Copyright (c) 2009-2012, The Regents of the University of Massachusetts, Amherst. Developed by E. Polizzi. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +=====================================================================================--- +6. Intel(R) Instrumentation and Tracing Technology API: + Copyright(c) 2019, Intel Corporation, All rights reserved. + + LAPACK95 + Copyright (c) 2000, Netlib + All rights reserved. + + XBLAS + Copyright (c) 2008-2009 The University of California Berkeley. All rights reserved. + + xbyak: + Copyright (c) 2007 MITSUNARI Shigeo + All rights reserved. + + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, his list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +* Neither the name of Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +=====================================================================================--- +7. Intel Open Source Technology Center Safe String Library: + strcat_s.c + October 2008, Bo Berry + Copyright (c) 2008-2011 by Cisco Systems, Inc. All rights reserved. + + level-zero: + Copyright (c) 2019 Intel Corporation + + Microsoft MPI + Copyright (c) Microsoft Corporation. All rights reserved. + + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +===================================================================================== +8. KhronosGroup/OpenCL-Headers + + + oneAPI Math Library (oneMath) + Copyright (c) Intel Corporation + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + +===================================================================================== +9. HPL - High-Performance Linpack Benchmark: + HPL - 2.3 - December 2, 2018 + Antoine P. Petitet + University of Tennessee, Knoxville + Innovative Computing Laboratory + (C) Copyright 2000-2008 All Rights Reserved + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: + This product includes software developed at the University of Tennessee, Knoxville, Innovative Computing Laboratory. + + 4. The name of the University, the name of the Laboratory, or the names of its contributors may not be used to endorse or promote products derived from this software without specific written permission. + + -- Disclaimer: + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +===================================================================================== +10. Intel(R) oneAPI Threading Building Blocks: + Copyright 2005-2019 Intel Corporation. All Rights Reserved. + + Intel(R) MPI Library: + Copyright (C) 2009 Intel Corporation + + Intel(R) OpenMP* Runtime: + Copyright 1985-2019 Intel Corporation. All Rights Reserved. + + +Intel Simplified Software License (Version October 2022) + +Use and Redistribution. You may use and redistribute the software, which is provided in binary form only, (the "Software"), without modification, provided the following conditions are met: + +* Redistributions must reproduce the above copyright notice and these terms of use in the Software and in the documentation and/or other materials provided with the distribution. +* Neither the name of Intel nor the names of its suppliers may be used to endorse or promote products derived from this Software without specific prior written permission. +* No reverse engineering, decompilation, or disassembly of the Software is permitted, nor any modification or alteration of the Software or its operation at any time, including during execution. + +No other licenses. Except as provided in the preceding section, Intel grants no licenses or other rights by implication, estoppel or otherwise to, patent, copyright, trademark, trade name, service mark or other intellectual property licenses or rights of Intel. + +Third party software. "Third Party Software" means the files (if any) listed in the "third-party-software.txt" or other similarly-named text file that may be included with the Software. Third Party Software, even if included with the distribution of the Software, may be governed by separate license terms, including without limitation, third party license terms, open source software notices and terms, and/or other Intel software license terms. These separate license terms solely govern Your use of the Third Party Software. + +DISCLAIMER. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED. THIS SOFTWARE IS NOT INTENDED FOR USE IN SYSTEMS OR APPLICATIONS WHERE FAILURE OF THE SOFTWARE MAY CAUSE PERSONAL INJURY OR DEATH AND YOU AGREE THAT YOU ARE FULLY RESPONSIBLE FOR ANY CLAIMS, COSTS, DAMAGES, EXPENSES, AND ATTORNEYS FEES ARISING OUT OF ANY SUCH USE, EVEN IF ANY CLAIM ALLEGES THAT INTEL WAS NEGLIGENT REGARDING THE DESIGN OR MANUFACTURE OF THE SOFTWARE. + +LIMITATION OF LIABILITY. IN NO EVENT WILL INTEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +No support. Intel may make changes to the Software, at any time without notice, and is not obligated to support, update or provide training for the Software. + +Termination. Your right to use the Software is terminated in the event of your breach of this license. + +Feedback. Should you provide Intel with comments, modifications, corrections, enhancements or other input ("Feedback") related to the Software, Intel will be free to use, disclose, reproduce, license or otherwise distribute or exploit the Feedback in its sole discretion without any obligations or restrictions of any kind, including without limitation, intellectual property rights or licensing obligations. + +Compliance with laws. You agree to comply with all relevant laws and regulations governing your use, transfer, import or export (or prohibition thereof) of the Software. + +Governing law. All disputes will be governed by the laws of the United States of America and the State of Delaware without reference to conflict of law principles and subject to the exclusive jurisdiction of the state or federal courts sitting in the State of Delaware, and each party agrees that it submits to the personal jurisdiction and venue of those courts and waives any objections. THE UNITED NATIONS CONVENTION ON CONTRACTS FOR THE INTERNATIONAL SALE OF GOODS (1980) IS SPECIFICALLY EXCLUDED AND WILL NOT APPLY TO THE SOFTWARE. + + +=====================================================================================--- + +11. Microsoft HPC Pack Software Development Kit (SDK) + Copyright Microsoft Corp. + + Terms for Microsoft "Distributable Code." +1. License. This software package from Intel (the "Software Package") contains code from Microsoft (the "Distributable Code"). You are provided a non-transferable, non-exclusive, non-sublicensable, limited right and license only to use and redistribute the Distributable Code as part of this Software Package. You are not allowed to copy, modify, remove the Distributable Code from the Software Package or redistribute the Distributable Code on a stand-alone basis. +2. Restrictions. The Distributable Code is licensed, not sold. You are only provided the above rights to use the Distributable Code. Intel and Microsoft reserve all other rights. Unless applicable law gives you more rights, you may use the Distributable Code only as expressly permitted in these terms. In using the Distributable Code, you must comply with any technical limitations in the Distributable Code that only allow you to use it in certain ways. You may not: +* work around any technical limitations in the Distributable Code; +* reverse engineer, decompile or disassemble the software, or otherwise attempt to derive the source code for the Distributable Code, except and to the extent required by third party licensing terms governing use of certain open source components that may be included in the Distributable Code; +* remove, minimize, block or modify any notices of Intel, Microsoft or its suppliers in the Distributable Code; +* use the Distributable Code in any way that is against the law; or +* share, publish, rent or lease the software, or provide the Distributable Code as a stand-alone offering for others to use. +3. NO WARRANTY. THE DISTRIBUTABLE CODE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. +4. LIMITATION ON AND EXCLUSION OF DAMAGES. YOU CAN RECOVER FROM INTEL, MICROSOFT OR THEIR SUPPLIERS ONLY DIRECT DAMAGES UP TO $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL DAMAGES. +This limitation applies to (a) anything related to the Distributable Code; and (b) claims for breach of contract, breach of warranty, guarantee or condition, strict liability, negligence, or other tort to the extent permitted by applicable law. It also applies even if Intel or Microsoft knew or should have known about the possibility of the damages. The above limitation or exclusion may not apply to you because your state or country may not allow the exclusion or limitation of incidental, consequential or other damages. +5. Export Restrictions. You must comply with all domestic and international export laws and regulations that apply to the software, which include restrictions on destinations, end users, and end use. For further information on export restrictions, visit www.microsoft.com/exporting. + + +=====================================================================================--- +12. spiralgen + +1. Copyright Notice + +Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp. All rights reserved. + +2. License + + +2.1. This is your license from Intel Corp. under its intellectual property rights. You may have additional license terms from the party that provided you this software, covering your right to use that party's intellectual property rights. + +2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a copy of the source code appearing in this file ("Covered Code") an irrevocable, perpetual, worldwide license under Intel's copyrights in the base code distributed originally by Intel ("Original Intel Code") to copy, make derivatives, distribute, use and display any portion of the Covered Code in any form, with the right to sublicense such rights; and + +2.3. Intel grants Licensee a non-exclusive and non-transferable patent license (with the right to sublicense), under only those claims of Intel patents that are infringed by the Original Intel Code, to make, use, sell, offer to sell, and import the Covered Code and derivative works thereof solely to the minimum extent necessary to exercise the above copyright license, and in no event shall the patent license extend to any additions to or modifications of the Original Intel Code. No other license or right is granted directly or by implication, estoppel or otherwise; + +The above copyright and patent license is granted only if the following conditions are met: + +3. Conditions + + +3.1. Redistribution of Source with Rights to Further Distribute Source. Redistribution of source code of any substantial portion of the Covered Code or modification with rights to further distribute source must include the above Copyright Notice, the above License, this list of Conditions, and the following Disclaimer and Export Compliance provision. In addition, Licensee must cause all Covered Code to which Licensee contributes to contain a file documenting the changes Licensee made to create that Covered Code and the date of any change. Licensee must include in that file the documentation of any changes made by any predecessor Licensee. Licensee must include a prominent statement that the modification is derived, directly or indirectly, from Original Intel Code. + +3.2. Redistribution of Source with no Rights to Further Distribute Source. Redistribution of source code of any substantial portion of the Covered Code or modification without rights to further distribute source must include the following Disclaimer and Export Compliance provision in the documentation and/or other materials provided with distribution. In addition, Licensee may not authorize further sublicense of source of any portion of the Covered Code, and must include terms to the effect that the license from Licensee to its licensee is limited to the intellectual property embodied in the software Licensee provides to its licensee, and not to intellectual property embodied in modifications its licensee may make. + +3.3. Redistribution of Executable. Redistribution in executable form of any substantial portion of the Covered Code or modification must reproduce the above Copyright Notice, and the following Disclaimer and Export Compliance provision in the documentation and/or other materials provided with the distribution. + +3.4. Intel retains all right, title, and interest in and to the Original Intel Code. + +3.5. Neither the name Intel nor any other trademark owned or controlled by Intel shall be used in advertising or otherwise to promote the sale, use or other dealings in products derived from or relating to the Covered Code without prior written authorization from Intel. + +4. Disclaimer and Export Compliance + + +4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. + +4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. + +4.3. Licensee shall not export, either directly or indirectly, any of this software or system incorporating such software without first obtaining any required license or other approval from the U. S. Department of Commerce or any other agency or department of the United States Government. In the event Licensee exports any such software from the United States or re-exports any such software from a foreign destination, Licensee shall ensure that the distribution and export/re-export of the software is in compliance with all laws, regulations, orders, or other restrictions of the U.S. Export Administration Regulations. Licensee agrees that neither it nor any of its subsidiaries will export/re-export any technical data, process, software, or service, directly or indirectly, to any country for which the United States government or any agency thereof requires an export license, other governmental approval, or letter of assurance, without first obtaining such license, approval or letter. + +===================================================================================== +13. METIS + Copyright 1997, Regents of the University of Minnesota + +===================================================================================== +14. MC64 Algorithm, part of HSL (formerly the Harwell Subroutine Library) + Copyright (c) 1999 Council for the Central Laboratory + of the Research Councils + All rights reserved. + +===================================================================================== +15. sparse-blas + + Matrix Market I/O + +Software Disclaimer +The research software provided on this web site ("software") is provided by NIST as a public service. You may use, copy and distribute copies of the software in any medium, provided that you keep intact this entire notice. You may improve, modify and create derivative works of the software or any portion of the software, and you may copy and distribute such modifications or works. Modified works should carry a notice stating that you changed the software and should note the date and nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the source of the software. + +The software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. + +You are solely responsible for determining the appropriateness of using and distributing the software and you assume all risks associated with its use, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of operation. This software is not intended to be used in any situation where a failure could cause risk of injury or damage to property. The software was developed by NIST employees. NIST employee contributions are not subject to copyright protection within the United States. + +===================================================================================== +16. LAPACK - Linear Algebra PACKage + +Copyright (c) 1992-2013 The University of Tennessee and The University + of Tennessee Research Foundation. All rights + reserved. +Copyright (c) 2000-2013 The University of California Berkeley. All + rights reserved. +Copyright (c) 2006-2013 The University of Colorado Denver. All rights + reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +- Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer listed + in this license in the documentation and/or other materials + provided with the distribution. + +- Neither the name of the copyright holders nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +The copyright holders provide no reassurances that the source code +provided does not infringe any patent, copyright, or any other +intellectual property rights of third parties. The copyright holders +disclaim any liability to any recipient for claims brought against +recipient by any third party for infringement of that parties +intellectual property rights. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +===================================================================================== +17. Intel(R) oneAPI DPC++ Library (oneDPL) + Copyright Intel Corporation + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +--- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + +===================================================================================== +18. Open MPI + +Most files in this release are marked with the copyrights of the +organizations who have edited them. The copyrights below are in no +particular order and generally reflect members of the Open MPI core +team who have contributed code to this release. The copyrights for +code used under license from other parties are included in the +corresponding files. + +Copyright (c) 2004-2012 The Trustees of Indiana University and Indiana + University Research and Technology + Corporation. All rights reserved. +Copyright (c) 2004-2021 The University of Tennessee and The University + of Tennessee Research Foundation. All rights + reserved. +Copyright (c) 2004-2018 High Performance Computing Center Stuttgart, + University of Stuttgart. All rights reserved. +Copyright (c) 2004-2008 The Regents of the University of California. + All rights reserved. +Copyright (c) 2006-2018 Los Alamos National Security, LLC. All rights + reserved. +Copyright (c) 2006-2021 Cisco Systems, Inc. All rights reserved. +Copyright (c) 2006-2010 Voltaire, Inc. All rights reserved. +Copyright (c) 2006-2021 Sandia National Laboratories. All rights reserved. +Copyright (c) 2006-2010 Sun Microsystems, Inc. All rights reserved. + Use is subject to license terms. +Copyright (c) 2006-2021 The University of Houston. All rights reserved. +Copyright (c) 2006-2009 Myricom, Inc. All rights reserved. +Copyright (c) 2007-2017 UT-Battelle, LLC. All rights reserved. +Copyright (c) 2007-2021 IBM Corporation. All rights reserved. +Copyright (c) 1998-2005 Forschungszentrum Juelich, Juelich Supercomputing + Centre, Federal Republic of Germany +Copyright (c) 2005-2008 ZIH, TU Dresden, Federal Republic of Germany +Copyright (c) 2007 Evergrid, Inc. All rights reserved. +Copyright (c) 2008-2016 Chelsio, Inc. All rights reserved. +Copyright (c) 2008-2009 Institut National de Recherche en + Informatique. All rights reserved. +Copyright (c) 2007 Lawrence Livermore National Security, LLC. + All rights reserved. +Copyright (c) 2007-2019 Mellanox Technologies. All rights reserved. +Copyright (c) 2006-2010 QLogic Corporation. All rights reserved. +Copyright (c) 2008-2017 Oak Ridge National Labs. All rights reserved. +Copyright (c) 2006-2012 Oracle and/or its affiliates. All rights reserved. +Copyright (c) 2009-2015 Bull SAS. All rights reserved. +Copyright (c) 2010 ARM ltd. All rights reserved. +Copyright (c) 2016 ARM, Inc. All rights reserved. +Copyright (c) 2010-2011 Alex Brick . All rights reserved. +Copyright (c) 2012 The University of Wisconsin-La Crosse. All rights reserved. +Copyright (c) 2013-2020 Intel, Inc. All rights reserved. +Copyright (c) 2011-2021 NVIDIA Corporation. All rights reserved. +Copyright (c) 2016-2018 Broadcom Limited. All rights reserved. +Copyright (c) 2011-2021 Fujitsu Limited. All rights reserved. +Copyright (c) 2014-2015 Hewlett-Packard Development Company, LP. All + rights reserved. +Copyright (c) 2013-2021 Research Organization for Information Science (RIST). + All rights reserved. +Copyright (c) 2017-2021 Amazon.com, Inc. or its affiliates. All Rights + reserved. +Copyright (c) 2018 DataDirect Networks. All rights reserved. +Copyright (c) 2018-2021 Triad National Security, LLC. All rights reserved. +Copyright (c) 2019-2021 Hewlett Packard Enterprise Development, LP. +Copyright (c) 2020-2021 Google, LLC. All rights reserved. +Copyright (c) 2002 University of Chicago +Copyright (c) 2001 Argonne National Laboratory +Copyright (c) 2020-2021 Cornelis Networks, Inc. All rights reserved. +Copyright (c) 2021 Nanook Consulting +Copyright (c) 2017-2019 Iowa State University Research Foundation, Inc. + All rights reserved. + +$COPYRIGHT$ + +Additional copyrights may follow + +$HEADER$ + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +- Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer listed + in this license in the documentation and/or other materials + provided with the distribution. + +- Neither the name of the copyright holders nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +The copyright holders provide no reassurances that the source code +provided does not infringe any patent, copyright, or any other +intellectual property rights of third parties. The copyright holders +disclaim any liability to any recipient for claims brought against +recipient by any third party for infringement of that parties +intellectual property rights. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +----------------[Copyright from inclusion of MPICH code]---------------- + +The following is a notice of limited availability of the code, and disclaimer +which must be included in the prologue of the code and in all source listings +of the code. + +Copyright Notice + + 2002 University of Chicago + +Permission is hereby granted to use, reproduce, prepare derivative works, and +to redistribute to others. This software was authored by: + +Mathematics and Computer Science Division +Argonne National Laboratory, Argonne IL 60439 + +(and) + +Department of Computer Science +University of Illinois at Urbana-Champaign + + + GOVERNMENT LICENSE + +Portions of this material resulted from work developed under a U.S. +Government Contract and are subject to the following license: the Government +is granted for itself and others acting on its behalf a paid-up, nonexclusive, +irrevocable worldwide license in this computer software to reproduce, prepare +derivative works, and perform publicly and display publicly. + + DISCLAIMER + +This computer code material was prepared, in part, as an account of work +sponsored by an agency of the United States Government. Neither the United +States, nor the University of Chicago, nor any of their employees, makes any +warranty express or implied, or assumes any legal liability or responsibility +for the accuracy, completeness, or usefulness of any information, apparatus, +product, or process disclosed, or represents that its use would not infringe +privately owned rights. + +===================================================================================== + +The following third party programs have their own third party program files. These additional third party program files are as follows: + +1. List of third party for Intel Open Source Technology Center Safe String Library is available in the third-party-programs-safestring.txt. + +2. List of third party for Intel(R) oneAPI Threading Building Blocks is available in third-party-programs-oneTBB.txt. + +3. List of third party for Intel(R) MPI Library is available in third-party-programs-IntelMPI.txt. + +4. List of third party for Intel(R) OpenMP* Runtime is available in the third-party-programs-openmp.txt file. + +5. List of third party for oneAPI Math Kernel Library (oneMKL) Interfaces is available in the third-party-programs-oneMKL-Interfaces.txt file. + +6. List of third party for level-zero is available in third-party-programs-level-zero.txt. + + +===================================================================================== diff --git a/licenses/Intel-oneMKL.txt b/licenses/Intel-oneMKL.txt new file mode 100644 index 0000000..0783c05 --- /dev/null +++ b/licenses/Intel-oneMKL.txt @@ -0,0 +1,25 @@ +Intel Simplified Software License (Version October 2022) + +Use and Redistribution. You may use and redistribute the software, which is provided in binary form only, (the “Software”), without modification, provided the following conditions are met: + +* Redistributions must reproduce the above copyright notice and these terms of use in the Software and in the documentation and/or other materials provided with the distribution. +* Neither the name of Intel nor the names of its suppliers may be used to endorse or promote products derived from this Software without specific prior written permission. +* No reverse engineering, decompilation, or disassembly of the Software is permitted, nor any modification or alteration of the Software or its operation at any time, including during execution. + +No other licenses. Except as provided in the preceding section, Intel grants no licenses or other rights by implication, estoppel or otherwise to, patent, copyright, trademark, trade name, service mark or other intellectual property licenses or rights of Intel. + +Third party software. “Third Party Software” means the files (if any) listed in the “third-party-software.txt” or other similarly-named text file that may be included with the Software. Third Party Software, even if included with the distribution of the Software, may be governed by separate license terms, including without limitation, third party license terms, open source software notices and terms, and/or other Intel software license terms. These separate license terms solely govern Your use of the Third Party Software. + +DISCLAIMER. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED. THIS SOFTWARE IS NOT INTENDED FOR USE IN SYSTEMS OR APPLICATIONS WHERE FAILURE OF THE SOFTWARE MAY CAUSE PERSONAL INJURY OR DEATH AND YOU AGREE THAT YOU ARE FULLY RESPONSIBLE FOR ANY CLAIMS, COSTS, DAMAGES, EXPENSES, AND ATTORNEYS’ FEES ARISING OUT OF ANY SUCH USE, EVEN IF ANY CLAIM ALLEGES THAT INTEL WAS NEGLIGENT REGARDING THE DESIGN OR MANUFACTURE OF THE SOFTWARE. + +LIMITATION OF LIABILITY. IN NO EVENT WILL INTEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +No support. Intel may make changes to the Software, at any time without notice, and is not obligated to support, update or provide training for the Software. + +Termination. Your right to use the Software is terminated in the event of your breach of this license. + +Feedback. Should you provide Intel with comments, modifications, corrections, enhancements or other input (“Feedback”) related to the Software, Intel will be free to use, disclose, reproduce, license or otherwise distribute or exploit the Feedback in its sole discretion without any obligations or restrictions of any kind, including without limitation, intellectual property rights or licensing obligations. + +Compliance with laws. You agree to comply with all relevant laws and regulations governing your use, transfer, import or export (or prohibition thereof) of the Software. + +Governing law. All disputes will be governed by the laws of the United States of America and the State of Delaware without reference to conflict of law principles and subject to the exclusive jurisdiction of the state or federal courts sitting in the State of Delaware, and each party agrees that it submits to the personal jurisdiction and venue of those courts and waives any objections. THE UNITED NATIONS CONVENTION ON CONTRACTS FOR THE INTERNATIONAL SALE OF GOODS (1980) IS SPECIFICALLY EXCLUDED AND WILL NOT APPLY TO THE SOFTWARE. diff --git a/licenses/OpenMPI.txt b/licenses/OpenMPI.txt deleted file mode 100644 index d037513..0000000 --- a/licenses/OpenMPI.txt +++ /dev/null @@ -1,146 +0,0 @@ -Most files in this release are marked with the copyrights of the -organizations who have edited them. The copyrights below are in no -particular order and generally reflect members of the Open MPI core -team who have contributed code to this release. The copyrights for -code used under license from other parties are included in the -corresponding files. - -Copyright (c) 2004-2012 The Trustees of Indiana University and Indiana - University Research and Technology - Corporation. All rights reserved. -Copyright (c) 2004-2024 The University of Tennessee and The University - of Tennessee Research Foundation. All rights - reserved. -Copyright (c) 2004-2018 High Performance Computing Center Stuttgart, - University of Stuttgart. All rights reserved. -Copyright (c) 2004-2008 The Regents of the University of California. - All rights reserved. -Copyright (c) 2006-2018 Los Alamos National Security, LLC. All rights - reserved. -Copyright (c) 2006-2024 Cisco Systems, Inc. All rights reserved. -Copyright (c) 2006-2010 Voltaire, Inc. All rights reserved. -Copyright (c) 2006-2023 Sandia National Laboratories. All rights reserved. -Copyright (c) 2006-2010 Sun Microsystems, Inc. All rights reserved. - Use is subject to license terms. -Copyright (c) 2006-2023 The University of Houston. All rights reserved. -Copyright (c) 2006-2009 Myricom, Inc. All rights reserved. -Copyright (c) 2007-2017 UT-Battelle, LLC. All rights reserved. -Copyright (c) 2007-2023 IBM Corporation. All rights reserved. -Copyright (c) 1998-2005 Forschungszentrum Juelich, Juelich Supercomputing - Centre, Federal Republic of Germany -Copyright (c) 2005-2008 ZIH, TU Dresden, Federal Republic of Germany -Copyright (c) 2007 Evergrid, Inc. All rights reserved. -Copyright (c) 2008-2016 Chelsio, Inc. All rights reserved. -Copyright (c) 2008-2009 Institut National de Recherche en - Informatique. All rights reserved. -Copyright (c) 2007 Lawrence Livermore National Security, LLC. - All rights reserved. -Copyright (c) 2007-2019 Mellanox Technologies. All rights reserved. -Copyright (c) 2006-2010 QLogic Corporation. All rights reserved. -Copyright (c) 2008-2017 Oak Ridge National Labs. All rights reserved. -Copyright (c) 2006-2012 Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2009-2015 Bull SAS. All rights reserved. -Copyright (c) 2010 ARM ltd. All rights reserved. -Copyright (c) 2016 ARM, Inc. All rights reserved. -Copyright (c) 2010-2011 Alex Brick . All rights reserved. -Copyright (c) 2012 The University of Wisconsin-La Crosse. All rights reserved. -Copyright (c) 2013-2020 Intel, Inc. All rights reserved. -Copyright (c) 2011-2024 NVIDIA Corporation. All rights reserved. -Copyright (c) 2016-2018 Broadcom Limited. All rights reserved. -Copyright (c) 2011-2023 Fujitsu Limited. All rights reserved. -Copyright (c) 2014-2015 Hewlett-Packard Development Company, LP. All - rights reserved. -Copyright (c) 2013-2023 Research Organization for Information Science (RIST). - All rights reserved. -Copyright (c) 2017-2024 Amazon.com, Inc. or its affiliates. All Rights - reserved. -Copyright (c) 2018 DataDirect Networks. All rights reserved. -Copyright (c) 2018-2024 Triad National Security, LLC. All rights reserved. -Copyright (c) 2019-2023 Hewlett Packard Enterprise Development, LP. -Copyright (c) 2020-2023 Google, LLC. All rights reserved. -Copyright (c) 2002 University of Chicago -Copyright (c) 2001 Argonne National Laboratory -Copyright (c) 2020-2024 Cornelis Networks, Inc. All rights reserved. -Copyright (c) 2021 Nanook Consulting -Copyright (c) 2017-2019 Iowa State University Research Foundation, Inc. - All rights reserved. - -$COPYRIGHT$ - -Additional copyrights may follow - -$HEADER$ - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -- Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -- Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer listed - in this license in the documentation and/or other materials - provided with the distribution. - -- Neither the name of the copyright holders nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -The copyright holders provide no reassurances that the source code -provided does not infringe any patent, copyright, or any other -intellectual property rights of third parties. The copyright holders -disclaim any liability to any recipient for claims brought against -recipient by any third party for infringement of that parties -intellectual property rights. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -----------------[Copyright from inclusion of MPICH code]---------------- - -The following is a notice of limited availability of the code, and disclaimer -which must be included in the prologue of the code and in all source listings -of the code. - -Copyright Notice - + 2002 University of Chicago - -Permission is hereby granted to use, reproduce, prepare derivative works, and -to redistribute to others. This software was authored by: - -Mathematics and Computer Science Division -Argonne National Laboratory, Argonne IL 60439 - -(and) - -Department of Computer Science -University of Illinois at Urbana-Champaign - - - GOVERNMENT LICENSE - -Portions of this material resulted from work developed under a U.S. -Government Contract and are subject to the following license: the Government -is granted for itself and others acting on its behalf a paid-up, nonexclusive, -irrevocable worldwide license in this computer software to reproduce, prepare -derivative works, and perform publicly and display publicly. - - DISCLAIMER - -This computer code material was prepared, in part, as an account of work -sponsored by an agency of the United States Government. Neither the United -States, nor the University of Chicago, nor any of their employees, makes any -warranty express or implied, or assumes any legal liability or responsibility -for the accuracy, completeness, or usefulness of any information, apparatus, -product, or process disclosed, or represents that its use would not infringe -privately owned rights. diff --git a/licenses/PMIx.txt b/licenses/PMIx.txt deleted file mode 100644 index 16e9a77..0000000 --- a/licenses/PMIx.txt +++ /dev/null @@ -1,97 +0,0 @@ -Most files in this release are marked with the copyrights of the -organizations who have edited them. The copyrights below are in no -particular order and generally reflect members of the Open MPI core -team who have contributed code that may or may not have been ported -to PMIx. Per the terms of that LICENSE, we include the list here. -The copyrights for code used under license from other parties -are included in the corresponding files. - -Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana - University Research and Technology - Corporation. All rights reserved. -Copyright (c) 2004-2010 The University of Tennessee and The University - of Tennessee Research Foundation. All rights - reserved. -Copyright (c) 2004-2010 High Performance Computing Center Stuttgart, - University of Stuttgart. All rights reserved. -Copyright (c) 2004-2008 The Regents of the University of California. - All rights reserved. -Copyright (c) 2006-2010 Los Alamos National Security, LLC. All rights - reserved. -Copyright (c) 2006-2010 Cisco Systems, Inc. All rights reserved. -Copyright (c) 2006-2010 Voltaire, Inc. All rights reserved. -Copyright (c) 2006-2011 Sandia National Laboratories. All rights reserved. -Copyright (c) 2006-2010 Sun Microsystems, Inc. All rights reserved. - Use is subject to license terms. -Copyright (c) 2006-2010 The University of Houston. All rights reserved. -Copyright (c) 2006-2009 Myricom, Inc. All rights reserved. -Copyright (c) 2007-2008 UT-Battelle, LLC. All rights reserved. -Copyright (c) 2007-2019 IBM Corporation. All rights reserved. -Copyright (c) 1998-2005 Forschungszentrum Juelich, Juelich Supercomputing - Centre, Federal Republic of Germany -Copyright (c) 2005-2008 ZIH, TU Dresden, Federal Republic of Germany -Copyright (c) 2007 Evergrid, Inc. All rights reserved. -Copyright (c) 2008 Chelsio, Inc. All rights reserved. -Copyright (c) 2008-2009 Institut National de Recherche en - Informatique. All rights reserved. -Copyright (c) 2007 Lawrence Livermore National Security, LLC. - All rights reserved. -Copyright (c) 2007-2019 Mellanox Technologies. All rights reserved. -Copyright (c) 2006-2010 QLogic Corporation. All rights reserved. -Copyright (c) 2008-2010 Oak Ridge National Labs. All rights reserved. -Copyright (c) 2006-2010 Oracle and/or its affiliates. All rights reserved. -Copyright (c) 2009 Bull SAS. All rights reserved. -Copyright (c) 2010 ARM ltd. All rights reserved. -Copyright (c) 2010-2011 Alex Brick . All rights reserved. -Copyright (c) 2012 The University of Wisconsin-La Crosse. All rights - reserved. -Copyright (c) 2013-2019 Intel, Inc. All rights reserved. -Copyright (c) 2020-2023 Nanook Consulting. All rights reserved -Copyright (c) 2011-2014 NVIDIA Corporation. All rights reserved. -Copyright (c) 2019-2023 Amazon.com, Inc. or its affiliates. All Rights - reserved. -Copyright (c) 2022-2023 Triad National Security, LLC. All rights reserved - -$COPYRIGHT$ - -Additional copyrights may follow - -$HEADER$ - -The following LICENSE pertains to both PMIx and any code ported -from Open MPI. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -- Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -- Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer listed - in this license in the documentation and/or other materials - provided with the distribution. - -- Neither the name of the copyright holders nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -The copyright holders provide no reassurances that the source code -provided does not infringe any patent, copyright, or any other -intellectual property rights of third parties. The copyright holders -disclaim any liability to any recipient for claims brought against -recipient by any third party for infringement of that parties -intellectual property rights. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/licenses/hwloc.txt b/licenses/hwloc.txt deleted file mode 100644 index 33b2108..0000000 --- a/licenses/hwloc.txt +++ /dev/null @@ -1,46 +0,0 @@ -SPDX-License-Identifier: BSD-3-Clause - -Copyright © 2004-2006 The Trustees of Indiana University and Indiana University Research and Technology Corporation. All rights reserved. -Copyright © 2004-2005 The University of Tennessee and The University of Tennessee Research Foundation. All rights reserved. -Copyright © 2004-2005 High Performance Computing Center Stuttgart, University of Stuttgart. All rights reserved. -Copyright © 2004-2005 The Regents of the University of California. All rights reserved. -Copyright © 2009 CNRS -Copyright © 2009-2016 Inria. All rights reserved. -Copyright © 2009-2015 Université Bordeaux -Copyright © 2009-2015 Cisco Systems, Inc. All rights reserved. -Copyright © 2009-2012 Oracle and/or its affiliates. All rights reserved. -Copyright © 2010 IBM -Copyright © 2010 Jirka Hladky -Copyright © 2012 Aleksej Saushev, The NetBSD Foundation -Copyright © 2012 Blue Brain Project, EPFL. All rights reserved. -Copyright © 2013-2014 University of Wisconsin-La Crosse. All rights reserved. -Copyright © 2015 Research Organization for Information Science and Technology (RIST). All rights reserved. -Copyright © 2015-2016 Intel, Inc. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -hwloc/base64.c is distributed under the ISC license. - -contrib/android/AndroidApp/lstopo/src/main/java/com/hwloc/lstopo/ZoomView/ -is distributed under the MIT license. diff --git a/licenses/libevent.txt b/licenses/libevent.txt deleted file mode 100644 index 402ca50..0000000 --- a/licenses/libevent.txt +++ /dev/null @@ -1,99 +0,0 @@ -Libevent is available for use under the following license, commonly known -as the 3-clause (or "modified") BSD license: - -============================== -Copyright (c) 2000-2007 Niels Provos -Copyright (c) 2007-2012 Niels Provos and Nick Mathewson - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -============================== - -Portions of Libevent are based on works by others, also made available by -them under the three-clause BSD license above. The copyright notices are -available in the corresponding source files; the license is as above. Here's -a list: - -log.c: - Copyright (c) 2000 Dug Song - Copyright (c) 1993 The Regents of the University of California. - -strlcpy.c: - Copyright (c) 1998 Todd C. Miller - -win32select.c: - Copyright (c) 2003 Michael A. Davis - -evport.c: - Copyright (c) 2007 Sun Microsystems - -ht-internal.h: - Copyright (c) 2002 Christopher Clark - -minheap-internal.h: - Copyright (c) 2006 Maxim Yegorushkin - -============================== - -The arc4module is available under the following, sometimes called the -"OpenBSD" license: - - Copyright (c) 1996, David Mazieres - Copyright (c) 2008, Damien Miller - - Permission to use, copy, modify, and distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -============================== - -The Windows timer code is based on code from libutp, which is -distributed under this license, sometimes called the "MIT" license. - - -Copyright (c) 2010 BitTorrent, Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/licenses/sprung-solve.txt b/licenses/sprung-solve.txt new file mode 100644 index 0000000..86dba5a --- /dev/null +++ b/licenses/sprung-solve.txt @@ -0,0 +1,27 @@ +sprung-solve (native/sprung-solve in the Sprung FEA source) + +MIT License + +Copyright (c) 2026 Sprung FEA contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Prebuilt sprung-solve executables also contain Intel oneMKL, under the Intel +Simplified Software License (Intel-oneMKL.txt), with the third-party notices +in Intel-oneMKL-third-party-programs.txt. diff --git a/native/calculix/accelerate_pardiso.c b/native/calculix/accelerate_pardiso.c new file mode 100644 index 0000000..50b3ae2 --- /dev/null +++ b/native/calculix/accelerate_pardiso.c @@ -0,0 +1,234 @@ +/* PARDISO entry point for CalculiX backed by Apple Accelerate's sparse + direct solvers. + + CalculiX built with -DPARDISO calls the MKL routine pardiso_ with phase + 12 (analyze and factor), 33 (solve) and -1 (release), for real symmetric + (mtype -2: upper triangle by rows) and real nonsymmetric (mtype 1, 11: + full matrix by rows) systems, 1-based. This file provides that routine: + symmetric systems are factored by supernodal Cholesky, or LDLT with + threshold partial pivoting when Cholesky finds them indefinite; + nonsymmetric ones by LU with threshold partial pivoting (QR before macOS + 15.5). The ordering of the last matrix structure is kept, so the + iterations of a nonlinear step only refactor. Accelerate factors on the + threads vecLib allows (VECLIB_MAXIMUM_THREADS). + + Licensed like CalculiX: GNU General Public License, version 2 or later. */ + +#include +#include +#include +#include + +typedef int ITG; + +struct factored { + SparseOpaqueFactorization_Double factor; + ITG n; +}; + +static void fail(const char *what, SparseStatus_t status) { + printf(" *ERROR in pardiso (Apple Accelerate): %s (status %d)\n", what, + (int)status); + fflush(stdout); + exit(201); +} + +static const char *kind_name(SparseFactorization_t kind) { + switch (kind) { + case SparseFactorizationCholesky: return "Cholesky"; + case SparseFactorizationLDLT: return "LDLT"; + case SparseFactorizationQR: return "QR"; + default: return "LU"; + } +} + +/* The symbolic factorization (ordering and fill pattern) of the last + matrix structure and factorization kind. Nonlinear steps refactor the + same structure every iteration, and its METIS ordering costs about as + much as the numeric factorization. `indefinite` remembers that Cholesky + failed on this structure, so later iterations go straight to LDLT. */ +static struct { + int valid, indefinite; + SparseFactorization_t kind; + SparseOpaqueSymbolicFactorization symbolic; + ITG n; + long nnz; + long *starts; + int *rows; +} cache; + +static int same_structure(ITG n, long nnz, const long *starts, + const int *rows) { + return cache.valid && cache.n == n && cache.nnz == nnz && + !memcmp(cache.starts, starts, sizeof(long) * (n + 1)) && + !memcmp(cache.rows, rows, sizeof(int) * nnz); +} + +/* Takes ownership of the structure's arrays: the cache keeps them, or + frees them when it already holds the same structure. Nested dissection + (METIS) suits 3D solid meshes: less fill and more independent work than + the default minimum-degree ordering. */ +static SparseOpaqueSymbolicFactorization symbolic_for( + SparseFactorization_t kind, SparseMatrixStructure S, long nnz) { + long *starts = S.columnStarts; + int *rows = S.rowIndices; + if (same_structure(S.columnCount, nnz, starts, rows)) { + if (starts != cache.starts) { + free(starts); + free(rows); + } + if (cache.kind == kind) return cache.symbolic; + } else { + if (cache.valid) { + free(cache.starts); + free(cache.rows); + } + cache.n = S.columnCount; + cache.nnz = nnz; + cache.starts = starts; + cache.rows = rows; + cache.indefinite = 0; + } + if (cache.valid) SparseCleanup(cache.symbolic); + S.columnStarts = cache.starts; + S.rowIndices = cache.rows; + SparseSymbolicFactorOptions options = _SparseDefaultSymbolicFactorOptions; + options.orderMethod = SparseOrderMetis; + cache.symbolic = SparseFactor(kind, S, options); + cache.kind = kind; + cache.valid = cache.symbolic.status == SparseStatusOK; + if (!cache.valid) fail("ordering failed", cache.symbolic.status); + return cache.symbolic; +} + +/* A's structure arrays pass to the cache, and A is left pointing at the + cache's copy of the same structure. */ +static SparseOpaqueFactorization_Double factor(SparseFactorization_t kind, + SparseMatrix_Double *A) { + long nnz = A->structure.columnStarts[A->structure.columnCount]; + SparseOpaqueSymbolicFactorization S = symbolic_for(kind, A->structure, nnz); + A->structure.columnStarts = cache.starts; + A->structure.rowIndices = cache.rows; + return SparseFactor(S, *A, _SparseDefaultNumericFactorOptions_Double); +} + +static void analyze_and_factor(long long *pt, ITG mtype, ITG n, double *a, + ITG *ia, ITG *ja) { + long nnz = (long)ia[n] - 1; + long *starts = malloc(sizeof(long) * (n + 1)); + int *rows = malloc(sizeof(int) * (nnz > 0 ? nnz : 1)); + double *values = a; + SparseMatrix_Double A; + SparseOpaqueFactorization_Double F; + SparseFactorization_t kind; + if (!starts || !rows) fail("out of memory", SparseInternalError); + + if (mtype == -2) { + /* The upper triangle by rows is the lower triangle by columns. */ + for (ITG i = 0; i <= n; i++) starts[i] = (long)ia[i] - 1; + for (long k = 0; k < nnz; k++) rows[k] = ja[k] - 1; + A.structure = (SparseMatrixStructure){ + .rowCount = n, + .columnCount = n, + .columnStarts = starts, + .rowIndices = rows, + .attributes = {.kind = SparseSymmetric, + .triangle = SparseLowerTriangle}, + .blockSize = 1}; + A.data = values; + kind = same_structure(n, nnz, starts, rows) && cache.indefinite + ? SparseFactorizationLDLT + : SparseFactorizationCholesky; + F = factor(kind, &A); + if (F.status != SparseStatusOK && kind == SparseFactorizationCholesky) { + /* Not positive definite: a shifted eigenvalue problem, buckling, + or a structure that is not held. */ + SparseCleanup(F); + kind = SparseFactorizationLDLT; + F = factor(kind, &A); + cache.indefinite = 1; + } + } else if (mtype == 1 || mtype == 11) { + /* Rows to columns: count, then scatter each row's entries. */ + values = malloc(sizeof(double) * (nnz > 0 ? nnz : 1)); + if (!values) fail("out of memory", SparseInternalError); + memset(starts, 0, sizeof(long) * (n + 1)); + for (long k = 0; k < nnz; k++) starts[ja[k]]++; + for (ITG j = 0; j < n; j++) starts[j + 1] += starts[j]; + for (ITG i = 0; i < n; i++) + for (long k = ia[i] - 1; k < ia[i + 1] - 1; k++) { + long dest = starts[ja[k] - 1]++; + rows[dest] = i; + values[dest] = a[k]; + } + for (ITG j = n; j > 0; j--) starts[j] = starts[j - 1]; + starts[0] = 0; + A.structure = (SparseMatrixStructure){ + .rowCount = n, + .columnCount = n, + .columnStarts = starts, + .rowIndices = rows, + .attributes = {.kind = SparseOrdinary}, + .blockSize = 1}; + A.data = values; + kind = SparseFactorizationQR; +#ifdef __MAC_15_5 + /* SDKs before macOS 15.5 do not declare LU. */ + if (__builtin_available(macOS 15.5, *)) kind = SparseFactorizationLUTPP; +#endif + F = factor(kind, &A); + } else { + printf(" *ERROR in pardiso (Apple Accelerate): matrix type %d is not " + "supported\n", (int)mtype); + exit(201); + } + /* The factorization keeps its own copy of the values. */ + if (values != a) free(values); + if (F.status != SparseStatusOK) { + SparseCleanup(F); + fail(F.status == SparseMatrixIsSingular ? "the matrix is singular" + : "factorization failed", + F.status); + } + printf(" Apple Accelerate sparse %s factorization\n", kind_name(kind)); + struct factored *state = malloc(sizeof *state); + state->factor = F; + state->n = n; + pt[0] = (long long)(intptr_t)state; +} + +void pardiso_(long long *pt, ITG *maxfct, ITG *mnum, ITG *mtype, ITG *phase, + ITG *neq, double *a, ITG *ia, ITG *ja, ITG *perm, ITG *nrhs, + ITG *iparm, ITG *msglvl, double *b, double *x, ITG *error) { + struct factored *state = (struct factored *)(intptr_t)pt[0]; + (void)maxfct; (void)mnum; (void)perm; (void)iparm; (void)msglvl; + *error = 0; + if (*phase == 12) { + if (state) { + SparseCleanup(state->factor); + free(state); + pt[0] = 0; + } + analyze_and_factor(pt, *mtype, *neq, a, ia, ja); + } else if (*phase == 33) { + if (!state) fail("solve before factorization", SparseInternalError); + ITG n = state->n, m = *nrhs; + memcpy(x, b, sizeof(double) * (size_t)n * (size_t)m); + DenseMatrix_Double X = {.rowCount = n, + .columnCount = m, + .columnStride = n, + .attributes = {0}, + .data = x}; + SparseSolve(state->factor, X); + } else if (*phase == -1 || *phase == 0) { + if (state) { + SparseCleanup(state->factor); + free(state); + } + pt[0] = 0; + } else { + printf(" *ERROR in pardiso (Apple Accelerate): phase %d is not " + "supported\n", (int)*phase); + exit(201); + } +} diff --git a/native/calculix/mkl_service.h b/native/calculix/mkl_service.h new file mode 100644 index 0000000..3caeabc --- /dev/null +++ b/native/calculix/mkl_service.h @@ -0,0 +1,7 @@ +/* CalculiX's PARDISO interface sets MKL's thread count through MKL's + headers. CalculiX is built without MKL: Accelerate manages its own + threads (macOS), and sprung-solve (pardiso_client.c) takes the count + from MKL_NUM_THREADS, which pardiso.c sets before its first call. */ +#define MKL_DOMAIN_BLAS 1 +#define MKL_DOMAIN_PARDISO 4 +static inline int mkl_domain_set_num_threads(int n, int domain) { (void)n; (void)domain; return 0; } diff --git a/native/calculix/pardiso_client.c b/native/calculix/pardiso_client.c new file mode 100644 index 0000000..deb99ec --- /dev/null +++ b/native/calculix/pardiso_client.c @@ -0,0 +1,308 @@ +/* PARDISO for CalculiX on Linux and Windows, solved in a separate program: + sprung-solve (native/sprung-solve), which runs Intel oneMKL's PARDISO in + its own process. + + CalculiX built with -DPARDISO calls the MKL routine pardiso_ with phase + 12 (analyze and factor), 33 (solve) and -1 (release), for real symmetric + (mtype -2: upper triangle by rows), structurally symmetric (mtype 1) and + unsymmetric (mtype 11) systems, 1-based. This file provides that routine + without MKL: it starts sprung-solve the first time, and hands it each + system through a pipe, by the documented protocol in + native/sprung-solve/protocol.h (docs/solver-protocol.md). sprung-solve + is found in SPRUNG_FEA_SOLVE, else at sprung-solve/sprung-solve beside + this executable. It ends when this program ends. + + MKL threads with the count in MKL_NUM_THREADS, which CalculiX's + pardiso.c sets before its first call; it is passed on with each system. + + Licensed like CalculiX's other additions here: GNU General Public + License, version 2 or later. */ + +#include +#include +#include +#include + +#include "protocol.h" + +typedef int ITG; + +#ifdef _WIN32 +#include +static HANDLE to_helper, from_helper; +#else +#include +#include +#include +#include +#include +extern char **environ; +static int to_helper = -1, from_helper = -1; +#endif + +static int started; + +static void fail(const char *what) { + printf(" *ERROR in pardiso: %s\n", what); + fflush(stdout); + exit(201); +} + +static void stopped(void) { + fail("sprung-solve, which runs the PARDISO solver, stopped unexpectedly"); +} + +#ifdef _WIN32 + +static void put(const void *data, size_t bytes) { + const char *p = data; + while (bytes) { + DWORD chunk = bytes > (1u << 30) ? (1u << 30) : (DWORD)bytes, done; + if (!WriteFile(to_helper, p, chunk, &done, NULL)) stopped(); + p += done; + bytes -= done; + } +} + +static void get(void *data, size_t bytes) { + char *p = data; + while (bytes) { + DWORD chunk = bytes > (1u << 30) ? (1u << 30) : (DWORD)bytes, done; + if (!ReadFile(from_helper, p, chunk, &done, NULL) || !done) stopped(); + p += done; + bytes -= done; + } +} + +static void start_helper(void) { + wchar_t path[MAX_PATH * 4], command[MAX_PATH * 4 + 16]; + const wchar_t *given = _wgetenv(L"SPRUNG_FEA_SOLVE"); + SECURITY_ATTRIBUTES inherit = {sizeof inherit, NULL, TRUE}; + HANDLE child_in, child_out, child_err, job; + STARTUPINFOW startup; + PROCESS_INFORMATION process; + JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits; + if (given && *given) { + wcsncpy(path, given, MAX_PATH * 4 - 1); + path[MAX_PATH * 4 - 1] = 0; + } else { + DWORD length = GetModuleFileNameW(NULL, path, MAX_PATH * 4 - 40); + wchar_t *slash = wcsrchr(path, L'\\'); + if (!length || !slash) fail("this program's folder was not found"); + wcscpy(slash + 1, L"sprung-solve\\sprung-solve.exe"); + } + /* Our ends stay ours; the helper inherits its ends as its standard + input and output, and shares our standard error. */ + if (!CreatePipe(&child_in, &to_helper, &inherit, 1 << 20) || + !CreatePipe(&from_helper, &child_out, &inherit, 1 << 20)) + fail("a pipe to sprung-solve could not be made"); + SetHandleInformation(to_helper, HANDLE_FLAG_INHERIT, 0); + SetHandleInformation(from_helper, HANDLE_FLAG_INHERIT, 0); + if (!DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE), + GetCurrentProcess(), &child_err, 0, TRUE, + DUPLICATE_SAME_ACCESS)) + child_err = CreateFileW(L"NUL", GENERIC_WRITE, FILE_SHARE_WRITE, &inherit, + OPEN_EXISTING, 0, NULL); + memset(&startup, 0, sizeof startup); + startup.cb = sizeof startup; + startup.dwFlags = STARTF_USESTDHANDLES; + startup.hStdInput = child_in; + startup.hStdOutput = child_out; + startup.hStdError = child_err; + _snwprintf(command, sizeof command / sizeof *command, L"\"%ls\" --serve", path); + command[sizeof command / sizeof *command - 1] = 0; + if (!CreateProcessW(path, command, NULL, NULL, TRUE, + CREATE_SUSPENDED | CREATE_NO_WINDOW, NULL, NULL, + &startup, &process)) { + char text[MAX_PATH * 4 + 160]; + snprintf(text, sizeof text, + "sprung-solve, which runs the PARDISO solver, could not be " + "started from %ls (Windows error %lu)", + path, (unsigned long)GetLastError()); + fail(text); + } + /* A job that ends the helper with this program, even mid-factorization + when this program is stopped. */ + job = CreateJobObjectW(NULL, NULL); + memset(&limits, 0, sizeof limits); + limits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + if (job && SetInformationJobObject(job, JobObjectExtendedLimitInformation, + &limits, sizeof limits)) + AssignProcessToJobObject(job, process.hProcess); + ResumeThread(process.hThread); + CloseHandle(process.hThread); + CloseHandle(process.hProcess); + CloseHandle(child_in); + CloseHandle(child_out); + CloseHandle(child_err); +} + +#else + +static void put(const void *data, size_t bytes) { + const char *p = data; + while (bytes) { + ssize_t done = write(to_helper, p, bytes); + if (done < 0 && errno == EINTR) continue; + if (done <= 0) stopped(); + p += done; + bytes -= (size_t)done; + } +} + +static void get(void *data, size_t bytes) { + char *p = data; + while (bytes) { + ssize_t done = read(from_helper, p, bytes); + if (done < 0 && errno == EINTR) continue; + if (done <= 0) stopped(); + p += done; + bytes -= (size_t)done; + } +} + +static void start_helper(void) { + char path[4096], text[4300]; + const char *given = getenv("SPRUNG_FEA_SOLVE"); + int in[2], out[2], error; + pid_t pid; + posix_spawn_file_actions_t actions; + char *argv[3]; + if (given && *given) { + snprintf(path, sizeof path, "%s", given); + } else { + ssize_t length = readlink("/proc/self/exe", path, sizeof path - 40); + char *slash; + if (length <= 0) fail("this program's folder was not found"); + path[length] = 0; + slash = strrchr(path, '/'); + strcpy(slash + 1, "sprung-solve/sprung-solve"); + } + if (pipe(in) || pipe(out)) fail("a pipe to sprung-solve could not be made"); + /* Only the helper's standard input and output survive into it. */ + fcntl(in[0], F_SETFD, FD_CLOEXEC); + fcntl(in[1], F_SETFD, FD_CLOEXEC); + fcntl(out[0], F_SETFD, FD_CLOEXEC); + fcntl(out[1], F_SETFD, FD_CLOEXEC); + posix_spawn_file_actions_init(&actions); + posix_spawn_file_actions_adddup2(&actions, in[0], 0); + posix_spawn_file_actions_adddup2(&actions, out[1], 1); + argv[0] = path; + argv[1] = "--serve"; + argv[2] = NULL; + error = posix_spawn(&pid, path, &actions, NULL, argv, environ); + posix_spawn_file_actions_destroy(&actions); + if (error) { + snprintf(text, sizeof text, + "sprung-solve, which runs the PARDISO solver, could not be " + "started from %s: %s", + path, strerror(error)); + fail(text); + } + close(in[0]); + close(out[1]); + to_helper = in[1]; + from_helper = out[0]; + /* A helper that stops shows as a failed write, not a signal. */ + signal(SIGPIPE, SIG_IGN); +} + +#endif + +/* A reply's status, and its text in `text`. */ +static int32_t answer(char *text, size_t size) { + int32_t status; + uint32_t length, kept; + char rest[256]; + get(&status, sizeof status); + get(&length, sizeof length); + kept = length < size - 1 ? length : (uint32_t)(size - 1); + get(text, kept); + text[kept] = 0; + for (length -= kept; length; length -= kept) { + kept = length < sizeof rest ? length : (uint32_t)sizeof rest; + get(rest, kept); + } + return status; +} + +static void request(uint32_t op, long long *pt) { + struct sprung_solve_request header; + header.magic = SPRUNG_SOLVE_MAGIC; + header.op = op; + /* CalculiX keeps one handle array (pt) for each factorization. */ + header.handle = (uint64_t)(uintptr_t)pt; + put(&header, sizeof header); +} + +static void start(void) { + uint32_t version = SPRUNG_SOLVE_VERSION; + char name[512]; + start_helper(); + started = 1; + request(SPRUNG_SOLVE_HELLO, NULL); + put(&version, sizeof version); + if (answer(name, sizeof name)) fail(name); + printf(" PARDISO: %s, in sprung-solve\n", name); + fflush(stdout); +} + +/* 1-based ITG indices as 0-based 64-bit ones, a block at a time. */ +static void put_indices(const ITG *index, long long count) { + int64_t block[8192]; + long long i, k; + for (i = 0; i < count; i += k) { + for (k = 0; k < 8192 && i + k < count; k++) block[k] = (int64_t)index[i + k] - 1; + put(block, sizeof *block * (size_t)k); + } +} + +static void check(void) { + char text[512]; + if (answer(text, sizeof text)) fail(text); +} + +void pardiso_(long long *pt, ITG *maxfct, ITG *mnum, ITG *mtype, ITG *phase, + ITG *neq, double *a, ITG *ia, ITG *ja, ITG *perm, ITG *nrhs, + ITG *iparm, ITG *msglvl, double *b, double *x, ITG *error) { + int64_t n = *neq; + (void)maxfct; (void)mnum; (void)perm; (void)iparm; (void)msglvl; + *error = 0; + if (*phase == -1) { + if (started) { + request(SPRUNG_SOLVE_RELEASE, pt); + check(); + } + return; + } + if (!started) start(); + if (*phase == 12) { + uint32_t kind, threads; + const char *env = getenv("MKL_NUM_THREADS"); + int64_t nnz = (int64_t)ia[n] - 1; + if (*mtype == -2) kind = SPRUNG_SOLVE_SYMMETRIC; + else if (*mtype == 1) kind = SPRUNG_SOLVE_STRUCTURALLY_SYMMETRIC; + else if (*mtype == 11) kind = SPRUNG_SOLVE_UNSYMMETRIC; + else fail("this matrix type is not supported"); + threads = env && atoi(env) > 0 ? (uint32_t)atoi(env) : 0; + request(SPRUNG_SOLVE_FACTOR, pt); + put(&kind, sizeof kind); + put(&threads, sizeof threads); + put(&n, sizeof n); + put(&nnz, sizeof nnz); + put_indices(ia, n + 1); + put_indices(ja, nnz); + put(a, sizeof *a * (size_t)nnz); + check(); + } else if (*phase == 33) { + int64_t count = *nrhs; + request(SPRUNG_SOLVE_SOLVE, pt); + put(&n, sizeof n); + put(&count, sizeof count); + put(b, sizeof *b * (size_t)(n * count)); + check(); + get(x, sizeof *x * (size_t)(n * count)); + } else { + fail("this PARDISO phase is not supported"); + } +} diff --git a/native/calculix/solver-env-linux.yml b/native/calculix/solver-env-linux.yml new file mode 100644 index 0000000..5856804 --- /dev/null +++ b/native/calculix/solver-env-linux.yml @@ -0,0 +1,13 @@ +# Toolchain and libraries for scripts/build-solver.py on Linux x64: +# micromamba create -n sprung-solver -f native/calculix/solver-env-linux.yml +# Intel oneMKL's static libraries go into sprung-solve, the separate +# program that runs CalculiX's PARDISO solves; CalculiX does not link it. +channels: [conda-forge] +dependencies: + - gcc_linux-64 + - gfortran_linux-64 + - arpack 3.9.* + - libblas=*=*openblas + - patchelf + - mkl-static 2026.* + - mkl-include 2026.* diff --git a/native/calculix/solver-env-macos.yml b/native/calculix/solver-env-macos.yml new file mode 100644 index 0000000..6080e6d --- /dev/null +++ b/native/calculix/solver-env-macos.yml @@ -0,0 +1,11 @@ +# Toolchain and libraries for scripts/build-solver.py on Apple silicon: +# micromamba create -n sprung-solver -f native/calculix/solver-env-macos.yml +# C is compiled by the Xcode command line tools' clang, for Accelerate; +# PARDISO is Apple Accelerate (native/calculix/accelerate_pardiso.c). +channels: [conda-forge] +dependencies: + - gfortran_osx-arm64 + - clang + - arpack 3.9.* + - libblas=*=*openblas + - llvm-openmp diff --git a/native/calculix/solver-env-windows.yml b/native/calculix/solver-env-windows.yml new file mode 100644 index 0000000..e4ac282 --- /dev/null +++ b/native/calculix/solver-env-windows.yml @@ -0,0 +1,18 @@ +# Toolchain and libraries for scripts/build-solver.py on Windows x64: +# micromamba create -n sprung-solver -f native/calculix/solver-env-windows.yml +# CalculiX is built by MinGW. sprung-solve, the separate program that runs +# CalculiX's PARDISO solves, is built by Microsoft's compiler (Visual +# Studio's C++ tools), which Intel oneMKL's static libraries are made for. +channels: [conda-forge] +dependencies: + - gcc_win-64 + - gfortran_win-64 + - arpack 3.9.* + - libblas=*=*openblas + # OpenBLAS's import library, for the link. + - openblas + - mkl-static 2026.* + - mkl-include 2026.* + # LLVM's OpenMP, as libiomp5md: MKL's threads in sprung-solve (what + # conda-forge's Windows MKL runs on). + - llvm-openmp diff --git a/native/calculix/spooles-patches/0000-transform-ivinit.patch b/native/calculix/spooles-patches/0000-transform-ivinit.patch new file mode 100644 index 0000000..1b3870d --- /dev/null +++ b/native/calculix/spooles-patches/0000-transform-ivinit.patch @@ -0,0 +1,37 @@ +commit 32466b7e010aa17caa1597b7cfb42c4251c68140 +Author: looooo +Date: Mon Jul 22 17:28:13 2024 +0200 + + osx.patch + +diff --git a/ETree/src/transform.c b/ETree/src/transform.c +index 1e36981..dbdfc70 100644 +--- a/ETree/src/transform.c ++++ b/ETree/src/transform.c +@@ -291,7 +291,7 @@ etree2 = ETree_compress(etree, mapIV) ; + remap the nzeros[] vector + ------------------------- + */ +-temp = IVinit(nfront, NULL) ; ++temp = IVinit(nfront, 0) ; + IVcopy(nfront, temp, nzeros) ; + IV_setSize(nzerosIV, nnew) ; + nzeros = IV_entries(nzerosIV) ; +@@ -453,7 +453,7 @@ etree2 = ETree_compress(etree, mapIV) ; + remap the nzeros[] vector + ------------------------- + */ +-temp = IVinit(nfront, NULL) ; ++temp = IVinit(nfront, 0) ; + IVcopy(nfront, temp, nzeros) ; + IV_setSize(nzerosIV, nnew) ; + nzeros = IV_entries(nzerosIV) ; +@@ -614,7 +614,7 @@ etree2 = ETree_compress(etree, mapIV) ; + remap the nzeros[] vector + ------------------------- + */ +-temp = IVinit(nfront, NULL) ; ++temp = IVinit(nfront, 0) ; + IVcopy(nfront, temp, nzeros) ; + IV_setSize(nzerosIV, nnew) ; + nzeros = IV_entries(nzerosIV) ; diff --git a/native/calculix/spooles-patches/0001-MT-add-acquire-release-primitives-and-order-the-work.patch b/native/calculix/spooles-patches/0001-MT-add-acquire-release-primitives-and-order-the-work.patch new file mode 100644 index 0000000..8a1989c --- /dev/null +++ b/native/calculix/spooles-patches/0001-MT-add-acquire-release-primitives-and-order-the-work.patch @@ -0,0 +1,363 @@ +From cb806200085ebfa1ecf2b6018608ad65e49e299c Mon Sep 17 00:00:00 2001 +From: Jacob Oursland +Date: Mon, 7 Sep 2026 17:26:48 -0600 +Subject: [PATCH] MT: add acquire/release primitives and order the work-list + handoff + +This is the defect that corrupts the factorization. + +ChvList_addObjectToList() pushes the object onto heads[ilist] and then +decrements counts[ilist], both under the list's mutex. The consumer, +FrontMtx_factorVisit(), reads both *without* the mutex: + + if ( ChvList_isListNonempty(aggList, J) == 1 ) + assembleAggregates(...) ; + if ( ChvList_isCountZero(aggList, J) == 1 ) { + if ( ChvList_isListNonempty(aggList, J) == 1 ) + assembleAggregates(...) ; + allAggregatesHere = 'Y' ; /* front is now factored */ + } + +ChvList_isCountZero() and ChvList_isListNonempty() take no lock at all, +and ChvList_getList() has an explicit unlocked fast path once the count +reaches zero. So a thread can observe counts[J] == 0 -- "every other +thread has contributed" -- while heads[J] still reads NULL, conclude +that no aggregates are pending, and factor front J without a +Schur-complement update that another thread has in fact already +produced. The result is silently wrong by O(1), not a crash. + +On a total-store-ordered machine (x86, x86_64, SPARC TSO) the +producer's stores reach memory in program order and the consumer's +loads are not reordered, so the code mostly gets away with it. On a +weakly ordered machine (aarch64, armhf, ppc64el, riscv64, loong64) +nothing orders them at all. "Mostly" is doing real work in that +sentence: the same reproducer still fails 8 runs in 2000 on x86_64. + +Add Utilities/SPOOLESatomic.h, a small set of acquire/release +primitives over the __atomic builtins (with a __sync fallback for GCC +before 4.7), and use them here: the heads[] store becomes a release +store, the counts[] store a release store sequenced after it, and every +consumer-side read of either an acquire load. Observing counts[J]==0 +now implies observing heads[J] and everything the producer wrote into +the object it published. + +The primitives deliberately operate on the *existing*, unqualified +struct fields rather than introducing _Atomic-qualified members, so +struct layouts, sizes and the library ABI are unchanged and this is safe +to apply to an already-shipped shared library. Every access is to a +naturally aligned int, char or pointer, so they all inline -- no +libatomic dependency. On x86 an acquire load and a release store are +ordinary MOVs; on aarch64 they become LDAPR/STLR on flag and pointer +words only, never inside a numerical loop. + +The unlocked paths are ordered too, not just the locked ones -- the +lock-free path is taken precisely when the count says the producers are +finished, which is the case that was broken. + +Verified: this and the following two patches together take SPOOLES' own +MT/drivers/testGridMT from 66/400 wrong at 20^3 on 4 threads (aarch64, +Apple M-series, clang -O2) to 0/2000, and remove all 19 Chv_assembleChv +and 6 real_updDenseColumns races ThreadSanitizer reported -- those were +consequences of this missing edge, not separate defects. +--- + ChvList/src/util.c | 32 +++++++------ + SubMtxList/src/util.c | 32 +++++++------ + Utilities/SPOOLESatomic.h | 97 +++++++++++++++++++++++++++++++++++++++ + 3 files changed, 133 insertions(+), 28 deletions(-) + create mode 100644 Utilities/SPOOLESatomic.h + +diff --git a/ChvList/src/util.c b/ChvList/src/util.c +index 33c752e..ea4d8dd 100644 +--- a/ChvList/src/util.c ++++ b/ChvList/src/util.c +@@ -1,6 +1,7 @@ + /* util.c */ + + #include "../ChvList.h" ++#include "../../Utilities/SPOOLESatomic.h" + + #define MYDEBUG 0 + +@@ -27,7 +28,7 @@ if ( chvlist == NULL || ilist < 0 || ilist >= chvlist->nlist ) { + fprintf(stderr, "\n fatal error in ChvList_isListNonempty(%p,%d)" + "\n bad input\n", chvlist, ilist) ; + } +-return(chvlist->heads[ilist] != NULL) ; } ++return(SPOOLES_LOAD_ACQUIRE(&chvlist->heads[ilist]) != NULL) ; } + + /*--------------------------------------------------------------------*/ + /* +@@ -55,7 +56,7 @@ if ( chvlist == NULL || ilist < 0 || ilist >= chvlist->nlist ) { + if ( chvlist->counts == NULL ) { + return(1) ; + } else { +- return(chvlist->counts[ilist] == 0) ; ++ return(SPOOLES_LOAD_ACQUIRE(&chvlist->counts[ilist]) == 0) ; + } + } + +@@ -102,11 +103,12 @@ if ( chvlist->lock != NULL + */ + Lock_lock(chvlist->lock) ; + if ( chv != NULL ) { +- chv->next = chvlist->heads[ilist] ; +- chvlist->heads[ilist] = chv ; ++ chv->next = SPOOLES_LOAD_ACQUIRE(&chvlist->heads[ilist]) ; ++ SPOOLES_STORE_RELEASE(&chvlist->heads[ilist], chv) ; + } + if ( chvlist->counts != NULL ) { +- chvlist->counts[ilist]-- ; ++ SPOOLES_STORE_RELEASE(&chvlist->counts[ilist], ++ SPOOLES_LOAD_RELAXED(&chvlist->counts[ilist]) - 1) ; + } + chvlist->nlocks++ ; + Lock_unlock(chvlist->lock) ; +@@ -118,11 +120,12 @@ if ( chvlist->lock != NULL + --------------------------------------------- + */ + if ( chv != NULL ) { +- chv->next = chvlist->heads[ilist] ; +- chvlist->heads[ilist] = chv ; ++ chv->next = SPOOLES_LOAD_ACQUIRE(&chvlist->heads[ilist]) ; ++ SPOOLES_STORE_RELEASE(&chvlist->heads[ilist], chv) ; + } + if ( chvlist->counts != NULL ) { +- chvlist->counts[ilist]-- ; ++ SPOOLES_STORE_RELEASE(&chvlist->counts[ilist], ++ SPOOLES_LOAD_RELAXED(&chvlist->counts[ilist]) - 1) ; + } + } + #if MYDEBUG > 0 +@@ -163,17 +166,18 @@ if ( chvlist == NULL || ilist < 0 || ilist >= chvlist->nlist ) { + fprintf(stdout, "\n ChvList %p : get list %d", chvlist, ilist) ; + fflush(stdout) ; + #endif +-if ( chvlist->heads[ilist] != NULL ) { ++if ( SPOOLES_LOAD_ACQUIRE(&chvlist->heads[ilist]) != NULL ) { + if ( chvlist->lock == NULL + || (chvlist->flags != NULL && chvlist->flags[ilist] == 'N') +- || (chvlist->counts != NULL && chvlist->counts[ilist] == 0) ) { ++ || (chvlist->counts != NULL ++ && SPOOLES_LOAD_ACQUIRE(&chvlist->counts[ilist]) == 0) ) { + /* + ------------------------ + no need to lock the list + ------------------------ + */ +- chv = chvlist->heads[ilist] ; +- chvlist->heads[ilist] = NULL ; ++ chv = SPOOLES_LOAD_ACQUIRE(&chvlist->heads[ilist]) ; ++ SPOOLES_STORE_RELAXED(&chvlist->heads[ilist], (Chv *) NULL) ; + } else { + /* + ---------------------------------------------------- +@@ -181,8 +185,8 @@ if ( chvlist->heads[ilist] != NULL ) { + ---------------------------------------------------- + */ + Lock_lock(chvlist->lock) ; +- chv = chvlist->heads[ilist] ; +- chvlist->heads[ilist] = NULL ; ++ chv = SPOOLES_LOAD_ACQUIRE(&chvlist->heads[ilist]) ; ++ SPOOLES_STORE_RELAXED(&chvlist->heads[ilist], (Chv *) NULL) ; + chvlist->nlocks++ ; + Lock_unlock(chvlist->lock) ; + } +diff --git a/SubMtxList/src/util.c b/SubMtxList/src/util.c +index 8570a46..ee3365b 100644 +--- a/SubMtxList/src/util.c ++++ b/SubMtxList/src/util.c +@@ -1,6 +1,7 @@ + /* util.c */ + + #include "../SubMtxList.h" ++#include "../../Utilities/SPOOLESatomic.h" + + #define MYDEBUG 0 + +@@ -28,7 +29,7 @@ if ( list == NULL || ilist < 0 || ilist >= list->nlist ) { + "\n fatal error in SubMtxList_isListNonempty(%p,%d)" + "\n bad input\n", list, ilist) ; + } +-return(list->heads[ilist] != NULL) ; } ++return(SPOOLES_LOAD_ACQUIRE(&list->heads[ilist]) != NULL) ; } + + /*--------------------------------------------------------------------*/ + /* +@@ -56,7 +57,7 @@ if ( list == NULL || ilist < 0 || ilist >= list->nlist ) { + if ( list->counts == NULL ) { + return(1) ; + } else { +- return(list->counts[ilist] == 0) ; ++ return(SPOOLES_LOAD_ACQUIRE(&list->counts[ilist]) == 0) ; + } + } + +@@ -101,11 +102,12 @@ if ( list->lock != NULL + */ + Lock_lock(list->lock) ; + if ( mtx != NULL ) { +- mtx->next = list->heads[ilist] ; +- list->heads[ilist] = mtx ; ++ mtx->next = SPOOLES_LOAD_ACQUIRE(&list->heads[ilist]) ; ++ SPOOLES_STORE_RELEASE(&list->heads[ilist], mtx) ; + } + if ( list->counts != NULL ) { +- list->counts[ilist]-- ; ++ SPOOLES_STORE_RELEASE(&list->counts[ilist], ++ SPOOLES_LOAD_RELAXED(&list->counts[ilist]) - 1) ; + } + list->nlocks++ ; + Lock_unlock(list->lock) ; +@@ -117,11 +119,12 @@ if ( list->lock != NULL + --------------------------------------------- + */ + if ( mtx != NULL ) { +- mtx->next = list->heads[ilist] ; +- list->heads[ilist] = mtx ; ++ mtx->next = SPOOLES_LOAD_ACQUIRE(&list->heads[ilist]) ; ++ SPOOLES_STORE_RELEASE(&list->heads[ilist], mtx) ; + } + if ( list->counts != NULL ) { +- list->counts[ilist]-- ; ++ SPOOLES_STORE_RELEASE(&list->counts[ilist], ++ SPOOLES_LOAD_RELAXED(&list->counts[ilist]) - 1) ; + } + } + #if MYDEBUG > 0 +@@ -162,17 +165,18 @@ if ( list == NULL || ilist < 0 || ilist >= list->nlist ) { + fprintf(stdout, "\n SubMtxList %p : get list %d", list, ilist) ; + fflush(stdout) ; + #endif +-if ( list->heads[ilist] != NULL ) { ++if ( SPOOLES_LOAD_ACQUIRE(&list->heads[ilist]) != NULL ) { + if ( list->lock == NULL + || (list->flags != NULL && list->flags[ilist] == 'N') +- || (list->counts != NULL && list->counts[ilist] == 0) ) { ++ || (list->counts != NULL ++ && SPOOLES_LOAD_ACQUIRE(&list->counts[ilist]) == 0) ) { + /* + ------------------------ + no need to lock the list + ------------------------ + */ +- mtx = list->heads[ilist] ; +- list->heads[ilist] = NULL ; ++ mtx = SPOOLES_LOAD_ACQUIRE(&list->heads[ilist]) ; ++ SPOOLES_STORE_RELAXED(&list->heads[ilist], (SubMtx *) NULL) ; + } else { + /* + ---------------------------------------------------- +@@ -180,8 +184,8 @@ if ( list->heads[ilist] != NULL ) { + ---------------------------------------------------- + */ + Lock_lock(list->lock) ; +- mtx = list->heads[ilist] ; +- list->heads[ilist] = NULL ; ++ mtx = SPOOLES_LOAD_ACQUIRE(&list->heads[ilist]) ; ++ SPOOLES_STORE_RELAXED(&list->heads[ilist], (SubMtx *) NULL) ; + list->nlocks++ ; + Lock_unlock(list->lock) ; + } +diff --git a/Utilities/SPOOLESatomic.h b/Utilities/SPOOLESatomic.h +new file mode 100644 +index 0000000..8fe393c +--- /dev/null ++++ b/Utilities/SPOOLESatomic.h +@@ -0,0 +1,97 @@ ++/* SPOOLESatomic.h */ ++ ++#ifndef _SPOOLES_ATOMIC_ ++#define _SPOOLES_ATOMIC_ ++ ++/* ++ -------------------------------------------------------------------- ++ Acquire/release helpers for the multithreaded (MT) solvers. ++ ++ The MT factorization and solve hand data between threads through ++ plain, unqualified memory: the ChvList/SubMtxList heads[] and ++ counts[] vectors, the frontIsDone[]/p_mtx[] pair in the solve, and ++ the lowerIsDone[]/diagIsDone[]/upperIsDone[] barriers. In every case ++ a producer writes a payload and then publishes a flag or pointer, and ++ a consumer tests the flag and then reads the payload -- with no ++ synchronization between the two. ++ ++ On a total-store-ordered machine (x86, x86_64, SPARC TSO) the ++ producer's stores reach memory in program order and the consumer's ++ loads are not reordered, so observing the flag implies observing the ++ payload and the code happens to be correct. On a weakly ordered ++ machine (aarch64, armhf, ppc64el, riscv64, loong64) nothing orders ++ them and a consumer can act on a payload it cannot yet see. ++ ++ These macros put a release store on each publication and an acquire ++ load on each consumption, which is exactly the missing edge. They ++ deliberately operate on the *existing*, unqualified struct fields ++ rather than introducing _Atomic-qualified members, so that struct ++ layouts, sizes and the library ABI are unchanged and this is a ++ drop-in patch for an already-shipped shared library. ++ ++ Cost: on x86 an acquire load and a release store are ordinary MOVs, ++ so TSO targets are unaffected. On aarch64 they become LDAR/STLR on ++ flag and pointer words only -- not in any inner numerical loop. ++ ++ created -- 2026sep07 ++ -------------------------------------------------------------------- ++*/ ++ ++#if defined(__ATOMIC_ACQUIRE) && defined(__ATOMIC_RELEASE) ++/* ++ GCC 4.7+, Clang 3.1+, ICC, and any compiler providing the __atomic ++ builtins. Applying these to a non-_Atomic lvalue is supported and ++ generates the plain load/store plus the required barrier. ++*/ ++#define SPOOLES_LOAD_ACQUIRE(ptr) __atomic_load_n((ptr), __ATOMIC_ACQUIRE) ++#define SPOOLES_STORE_RELEASE(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_RELEASE) ++#define SPOOLES_LOAD_RELAXED(ptr) __atomic_load_n((ptr), __ATOMIC_RELAXED) ++#define SPOOLES_STORE_RELAXED(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_RELAXED) ++#define SPOOLES_FETCH_ADD_RELAXED(ptr, val) \ ++ __atomic_fetch_add((ptr), (val), __ATOMIC_RELAXED) ++#define SPOOLES_HAVE_ATOMICS 1 ++ ++#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) ++/* ++ Older GCC: the legacy __sync builtins only give us a full barrier, ++ which is stronger than needed but correct. volatile keeps the ++ compiler from caching the flag across a spin loop. ++*/ ++#define SPOOLES_LOAD_ACQUIRE(ptr) \ ++ ({ __typeof__(*(ptr)) _v = *(volatile __typeof__(*(ptr)) *)(ptr) ; \ ++ __sync_synchronize() ; _v ; }) ++#define SPOOLES_STORE_RELEASE(ptr, val) \ ++ do { __sync_synchronize() ; \ ++ *(volatile __typeof__(*(ptr)) *)(ptr) = (val) ; } while (0) ++#define SPOOLES_LOAD_RELAXED(ptr) (*(volatile __typeof__(*(ptr)) *)(ptr)) ++#define SPOOLES_STORE_RELAXED(ptr, val) \ ++ do { *(volatile __typeof__(*(ptr)) *)(ptr) = (val) ; } while (0) ++#define SPOOLES_FETCH_ADD_RELAXED(ptr, val) __sync_fetch_and_add((ptr), (val)) ++#define SPOOLES_HAVE_ATOMICS 1 ++ ++#else ++/* ++ No atomic builtins. Fall back to plain accesses, which is what SPOOLES ++ 2.2 has always done. This is correct only on a total-store-ordered ++ machine; warn so that a weakly ordered port does not silently inherit ++ the original bug. ++ ++ Note that __typeof__ is a GNU extension, so it cannot be used here -- ++ this branch exists precisely for compilers that are not GCC-like. The ++ spin loops in FrontMtx_workerSolve() are therefore not protected from ++ being hoisted; a compiler reaching this branch needs its own equivalent ++ of volatile there. ++*/ ++#if defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) \ ++ || defined(__powerpc64__) || defined(__riscv) || defined(__loongarch__) ++#error "SPOOLES MT: no atomic builtins on a weakly ordered target. The MT solvers return silently wrong results without them -- see Utilities/SPOOLESatomic.h. Build without the MT library, or add acquire/release primitives for this compiler." ++#endif ++#define SPOOLES_LOAD_ACQUIRE(ptr) (*(ptr)) ++#define SPOOLES_STORE_RELEASE(ptr, val) do { *(ptr) = (val) ; } while (0) ++#define SPOOLES_LOAD_RELAXED(ptr) (*(ptr)) ++#define SPOOLES_STORE_RELAXED(ptr, val) do { *(ptr) = (val) ; } while (0) ++#define SPOOLES_FETCH_ADD_RELAXED(ptr, val) (*(ptr) += (val)) ++#define SPOOLES_HAVE_ATOMICS 0 ++#endif ++ ++#endif /* _SPOOLES_ATOMIC_ */ diff --git a/native/calculix/spooles-patches/0002-MT-order-the-frontIsDone-p_mtx-publication-in-the-so.patch b/native/calculix/spooles-patches/0002-MT-order-the-frontIsDone-p_mtx-publication-in-the-so.patch new file mode 100644 index 0000000..d9bb9c8 --- /dev/null +++ b/native/calculix/spooles-patches/0002-MT-order-the-frontIsDone-p_mtx-publication-in-the-so.patch @@ -0,0 +1,106 @@ +From 40e29ead7e0c1d43d85075179a51587c7e9e38f4 Mon Sep 17 00:00:00 2001 +From: Jacob Oursland +Date: Mon, 7 Sep 2026 17:26:49 -0600 +Subject: [PATCH] MT: order the frontIsDone[]/p_mtx[] publication in the solve + +The same defect shape in the triangular solve. The thread that owns +front J finishes it with + + p_mtx[J] = BJ ; + frontIsDone[J] = 'Y' ; + +and any other thread picks it up with + + if ( frontIsDone[I] == 'Y' ) + if ( (YI = p_mtx[I]) != NULL ) + ... use YI's entries ... + +Neither side is synchronized. A consumer that sees the flag but not +the pointer skips a real update; one that sees the pointer but not the +SubMtx entries behind it reads uninitialized memory and folds it into +the solution. ThreadSanitizer attributed the latter to +real_updDenseColumns() and DVadd(), which is where the garbage was +consumed rather than where it came from. + +Release-store the flag after the payload at all five publication sites +(forward, diagonal and backward visits), and acquire-load it at the two +consumption sites in computeForwardUpdates()/computeBackwardUpdates(). +--- + FrontMtx/src/solveUtil.c | 15 ++++++++------- + 1 file changed, 8 insertions(+), 7 deletions(-) + +diff --git a/FrontMtx/src/solveUtil.c b/FrontMtx/src/solveUtil.c +index fbf7184..8a39ca3 100644 +--- a/FrontMtx/src/solveUtil.c ++++ b/FrontMtx/src/solveUtil.c +@@ -1,6 +1,7 @@ + /* solveUtil.c */ + + #include "../FrontMtx.h" ++#include "../../Utilities/SPOOLESatomic.h" + #include "../../SubMtxList.h" + + /*--------------------------------------------------------------------*/ +@@ -198,7 +199,7 @@ if ( (nJ = FrontMtx_frontSize(frontmtx, J)) == 0 ) { + ----------------------------------------------------- + */ + if ( owners == NULL || owners[J] == myid ) { +- frontIsDone[J] = 'Y' ; ++ SPOOLES_STORE_RELEASE(&frontIsDone[J], 'Y') ; + } + status[J] = 'F' ; + return ; +@@ -304,7 +305,7 @@ if ( updDone == 'Y' && aggDone == 'Y' ) { + */ + p_agg[J] = NULL ; + p_mtx[J] = BJ ; +- frontIsDone[J] = 'Y' ; ++ SPOOLES_STORE_RELEASE(&frontIsDone[J], 'Y') ; + } else if ( BJ != NULL ) { + /* + -------------------------------------- +@@ -366,7 +367,7 @@ if ( owners == NULL || owners[J] == myid ) { + p_mtx[J] = NULL ; + p_agg[J] = BJ ; + } +- frontIsDone[J] = 'Y' ; ++ SPOOLES_STORE_RELEASE(&frontIsDone[J], 'Y') ; + } + return ; } + +@@ -411,7 +412,7 @@ if ( (nJ = FrontMtx_frontSize(frontmtx, J)) == 0 ) { + ----------------------------------------------------- + */ + if ( owners == NULL || owners[J] == myid ) { +- frontIsDone[J] = 'Y' ; ++ SPOOLES_STORE_RELEASE(&frontIsDone[J], 'Y') ; + } + status[J] = 'F' ; + return ; +@@ -512,7 +513,7 @@ if ( updDone == 'Y' && aggDone == 'Y' ) { + */ + p_agg[J] = NULL ; + p_mtx[J] = ZJ ; +- frontIsDone[J] = 'Y' ; ++ SPOOLES_STORE_RELEASE(&frontIsDone[J], 'Y') ; + } else if ( ZJ != NULL ) { + /* + -------------------------------------- +@@ -758,7 +759,7 @@ for ( ip = heads[J], heads[J] = NULL ; + I, frontIsDone[I], I, p_mtx[I]) ; + fflush(msgFile) ; + } +- if ( frontIsDone[I] == 'Y' ) { ++ if ( SPOOLES_LOAD_ACQUIRE(&frontIsDone[I]) == 'Y' ) { + if ( (YI = p_mtx[I]) != NULL ) { + /* + -------------------------------- +@@ -930,7 +931,7 @@ for ( ip = heads[J], heads[J] = NULL ; + "\n\n frontIsDone[%d] = %c", K, frontIsDone[K]) ; + fflush(msgFile) ; + } +- if ( frontIsDone[K] == 'Y' ) { ++ if ( SPOOLES_LOAD_ACQUIRE(&frontIsDone[K]) == 'Y' ) { + if ( (XK = p_mtx[K]) != NULL ) { + /* + -------------------------------- diff --git a/native/calculix/spooles-patches/0003-MT-make-the-solve-s-three-inter-phase-barriers-actua.patch b/native/calculix/spooles-patches/0003-MT-make-the-solve-s-three-inter-phase-barriers-actua.patch new file mode 100644 index 0000000..1b3b532 --- /dev/null +++ b/native/calculix/spooles-patches/0003-MT-make-the-solve-s-three-inter-phase-barriers-actua.patch @@ -0,0 +1,113 @@ +From d1176c4eb445a2b87dc6dea18418d9bd0c282529 Mon Sep 17 00:00:00 2001 +From: Jacob Oursland +Date: Mon, 7 Sep 2026 17:26:49 -0600 +Subject: [PATCH] MT: make the solve's three inter-phase barriers actually + synchronize + +FrontMtx_workerSolve() separates the forward solve, the diagonal solve +and the backward solve with three hand-rolled barriers, each spinning +on a plain char vector: + + lowerIsDone[myid] = 'Y' ; + do { + everybodyDone = 1 ; + for ( iproc = 0 ; iproc < nproc ; iproc++ ) + if ( lowerIsDone[iproc] != 'Y' ) { everybodyDone = 0 ; break ; } + } while ( everybodyDone == 0 ) ; + +There is no fence and no volatile. Two consequences: + + - No ordering. A thread can see every flag set to 'Y' and still not + see the results the other threads wrote during the phase that just + ended. The barrier separates the phases in program order only. + Since the whole point is that the backward solve reads what the + forward and diagonal solves produced, a violation corrupts the + solution wholesale rather than subtly. + + - No compiler guarantee. The flags are ordinary memory, so a + compiler is entitled to hoist the load out of the spin loop and + hang. That has not been observed with gcc or clang here, but it is + not something to leave to luck in a spin loop. + +Release-store the flag on arrival, acquire-load it while waiting. The +reset of frontIsDone[] between the diagonal and backward phases is made +explicit for the same reason. +--- + MT/src/solveMT.c | 15 ++++++++------- + 1 file changed, 8 insertions(+), 7 deletions(-) + +diff --git a/MT/src/solveMT.c b/MT/src/solveMT.c +index 77d4620..c2fd58c 100644 +--- a/MT/src/solveMT.c ++++ b/MT/src/solveMT.c +@@ -1,6 +1,7 @@ + /* solveMT.c */ + + #include "../spoolesMT.h" ++#include "../../Utilities/SPOOLESatomic.h" + #include "../../Ideq.h" + #include "../../timings.h" + #include "../../SolveMap.h" +@@ -497,7 +498,7 @@ if ( msglvl > 1 ) { + all processes wait here until all are done + ------------------------------------------ + */ +-lowerIsDone[myid] = 'Y' ; ++SPOOLES_STORE_RELEASE(&lowerIsDone[myid], 'Y') ; + do { + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n 1. checking out lowerIsDone[] vector: ") ; +@@ -509,7 +510,7 @@ do { + fprintf(msgFile, " %c", lowerIsDone[iproc]) ; + fflush(msgFile) ; + } +- if ( lowerIsDone[iproc] != 'Y' ) { ++ if ( SPOOLES_LOAD_ACQUIRE(&lowerIsDone[iproc]) != 'Y' ) { + everybodyDone = 0 ; + break ; + } +@@ -530,7 +531,7 @@ for ( J = 0 ; J < nfront ; J++ ) { + set frontIsDone[J] to 'N' to be ready for the backward solve + ------------------------------------------------------------ + */ +- frontIsDone[J] = 'N' ; ++ SPOOLES_STORE_RELAXED(&frontIsDone[J], 'N') ; + } + } + MARKTIME(t2) ; +@@ -540,7 +541,7 @@ cpus[3] += t2 - t1 ; + all processes wait here until all are done + ------------------------------------------ + */ +-diagIsDone[myid] = 'Y' ; ++SPOOLES_STORE_RELEASE(&diagIsDone[myid], 'Y') ; + do { + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n 2. checking out diagIsDone[] vector: ") ; +@@ -552,7 +553,7 @@ do { + fprintf(msgFile, " %c", diagIsDone[iproc]) ; + fflush(msgFile) ; + } +- if ( diagIsDone[iproc] != 'Y' ) { ++ if ( SPOOLES_LOAD_ACQUIRE(&diagIsDone[iproc]) != 'Y' ) { + everybodyDone = 0 ; + break ; + } +@@ -650,7 +651,7 @@ cpus[4] += t2 - t1 ; + all processes wait here until all are done + ------------------------------------------ + */ +-upperIsDone[myid] = 'Y' ; ++SPOOLES_STORE_RELEASE(&upperIsDone[myid], 'Y') ; + do { + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n 2. checking out upperIsDone[] vector: ") ; +@@ -662,7 +663,7 @@ do { + fprintf(msgFile, " %c", upperIsDone[iproc]) ; + fflush(msgFile) ; + } +- if ( upperIsDone[iproc] != 'Y' ) { ++ if ( SPOOLES_LOAD_ACQUIRE(&upperIsDone[iproc]) != 'Y' ) { + everybodyDone = 0 ; + break ; + } diff --git a/native/calculix/spooles-patches/0004-MT-stop-losing-updates-on-the-factor-s-entry-counter.patch b/native/calculix/spooles-patches/0004-MT-stop-losing-updates-on-the-factor-s-entry-counter.patch new file mode 100644 index 0000000..fc5d429 --- /dev/null +++ b/native/calculix/spooles-patches/0004-MT-stop-losing-updates-on-the-factor-s-entry-counter.patch @@ -0,0 +1,125 @@ +From 4598b5f4fda04c40e64faebd979eb1037b275ef6 Mon Sep 17 00:00:00 2001 +From: Jacob Oursland +Date: Mon, 7 Sep 2026 17:26:50 -0600 +Subject: [PATCH] MT: stop losing updates on the factor's entry counters + +FrontMtx_storeFront() accumulates frontmtx->nentD, nentL and nentU with +plain read-modify-writes at ten sites, and every factorization thread +runs it concurrently for the fronts it owns. ThreadSanitizer reported +three of these directly. + +The counters feed the operation-count and storage statistics only -- +FrontMtx_nentD()/nentL()/nentU() and the driver's nops estimate -- so +the damage is an understated report, not a wrong answer. They are +still a lost-update race and still undefined behaviour, and they are +the last thing standing between the factorization and a clean +ThreadSanitizer run, so make them relaxed atomic fetch-adds. Relaxed +is sufficient: nothing is published through these counters, and no +ordering is required, so the cost is a single LDADD on aarch64 and +LOCK XADD on x86, ten times per front. +--- + FrontMtx/src/storeFront.c | 21 +++++++++++---------- + 1 file changed, 11 insertions(+), 10 deletions(-) + +diff --git a/FrontMtx/src/storeFront.c b/FrontMtx/src/storeFront.c +index 2465a40..0925d6e 100644 +--- a/FrontMtx/src/storeFront.c ++++ b/FrontMtx/src/storeFront.c +@@ -1,6 +1,7 @@ + /* storeFront.c */ + + #include "../FrontMtx.h" ++#include "../../Utilities/SPOOLESatomic.h" + + /*--------------------------------------------------------------------*/ + /* +@@ -137,7 +138,7 @@ if ( pivotsizes != NULL ) { + SubMtx_writeForHumanEye(mtx, msgFile) ; + fflush(msgFile) ; + } +- frontmtx->nentD += nent ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentD, nent) ; + } else { + /* + --------------- +@@ -154,7 +155,7 @@ if ( pivotsizes != NULL ) { + SubMtx_diagonalInfo(mtx, &nent, &entries) ; + Chv_copyEntriesToVector(frontJ, npivot, pivotsizes, nent, entries, + CHV_DIAGONAL, CHV_BY_ROWS) ; +- frontmtx->nentD += nD ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentD, nD) ; + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n entries in SubMtx") ; + DVfprintf(msgFile, nent, entries) ; +@@ -219,7 +220,7 @@ if ( FRONTMTX_IS_DENSE_FRONTS(frontmtx) ) { + SubMtx_rowIndices(mtx, &nrow, &rowind) ; + IVcopy(nrow, rowind, rowindJ) ; + if ( FRONTMTX_IS_PIVOTING(frontmtx) ) { +- frontmtx->nentU += nent ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentU, nent) ; + } + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n UJJ matrix") ; +@@ -257,7 +258,7 @@ if ( FRONTMTX_IS_DENSE_FRONTS(frontmtx) ) { + IVcopy(ncol, colind, colindJ) ; + SubMtx_rowIndices(mtx, &nrow, &rowind) ; + IVcopy(nrow, rowind, rowindJ) ; +- frontmtx->nentU += nent ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentU, nent) ; + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n UJJ matrix") ; + SubMtx_writeForHumanEye(mtx, msgFile) ; +@@ -295,7 +296,7 @@ if ( FRONTMTX_IS_DENSE_FRONTS(frontmtx) ) { + SubMtx_rowIndices(mtx, &nrow, &rowind) ; + IVcopy(nrow, rowind, rowindJ) ; + if ( FRONTMTX_IS_PIVOTING(frontmtx) ) { +- frontmtx->nentU += nent ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentU, nent) ; + } + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n UJJN matrix") ; +@@ -333,7 +334,7 @@ if ( FRONTMTX_IS_DENSE_FRONTS(frontmtx) ) { + IVcopy(ncol, colind, colindJ + nD) ; + SubMtx_rowIndices(mtx, &nrow, &rowind) ; + IVcopy(nrow, rowind, rowindJ) ; +- frontmtx->nentU += nent ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentU, nent) ; + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n UJJN matrix") ; + SubMtx_writeForHumanEye(mtx, msgFile) ; +@@ -378,7 +379,7 @@ if ( FRONTMTX_IS_NONSYMMETRIC(frontmtx) ) { + SubMtx_rowIndices(mtx, &nrow, &rowind) ; + IVcopy(nrow, rowind, rowindJ) ; + if ( FRONTMTX_IS_PIVOTING(frontmtx) ) { +- frontmtx->nentL += nent ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentL, nent) ; + } + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n LJJ matrix") ; +@@ -416,7 +417,7 @@ if ( FRONTMTX_IS_NONSYMMETRIC(frontmtx) ) { + IVcopy(ncol, colind, colindJ) ; + SubMtx_rowIndices(mtx, &nrow, &rowind) ; + IVcopy(nrow, rowind, rowindJ) ; +- frontmtx->nentL += nent ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentL, nent) ; + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n LJJ matrix") ; + SubMtx_writeForHumanEye(mtx, msgFile) ; +@@ -454,7 +455,7 @@ if ( FRONTMTX_IS_NONSYMMETRIC(frontmtx) ) { + SubMtx_rowIndices(mtx, &nrow, &rowind) ; + IVcopy(nrow, rowind, rowindJ + nD) ; + if ( FRONTMTX_IS_PIVOTING(frontmtx) ) { +- frontmtx->nentL += nent ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentL, nent) ; + } + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n LNJ matrix") ; +@@ -492,7 +493,7 @@ if ( FRONTMTX_IS_NONSYMMETRIC(frontmtx) ) { + IVcopy(ncol, colind, colindJ) ; + SubMtx_rowIndices(mtx, &nrow, &rowind) ; + IVcopy(nrow, rowind, rowindJ + nD) ; +- frontmtx->nentL += nent ; ++ SPOOLES_FETCH_ADD_RELAXED(&frontmtx->nentL, nent) ; + if ( msglvl > 2 ) { + fprintf(msgFile, "\n\n LNJ matrix") ; + SubMtx_writeForHumanEye(mtx, msgFile) ; diff --git a/native/calculix/spooles-patches/0005-MT-give-each-solve-thread-its-own-cpus-vector.patch b/native/calculix/spooles-patches/0005-MT-give-each-solve-thread-its-own-cpus-vector.patch new file mode 100644 index 0000000..426804c --- /dev/null +++ b/native/calculix/spooles-patches/0005-MT-give-each-solve-thread-its-own-cpus-vector.patch @@ -0,0 +1,58 @@ +From 2f6d8e1eda9e2669ebe52d3a661736050f29c3f3 Mon Sep 17 00:00:00 2001 +From: Jacob Oursland +Date: Mon, 7 Sep 2026 17:26:51 -0600 +Subject: [PATCH] MT: give each solve thread its own cpus[] vector + +FrontMtx_MT_solve() hands every SolveData the *same* caller-supplied +cpus[] vector: + + data->cpus = cpus ; + +and each worker then accumulates into it with cpus[i] += t2 - t1 at +seven sites. Concurrent read-modify-writes on a shared double: the +last seven races ThreadSanitizer reports. + +The reduction afterwards cannot work either -- + + DVzero(8, cpus) ; + for ( myid = 0 ; myid < nthread ; myid++, data++ ) + for ( ii = 0 ; ii < 8 ; ii++ ) + cpus[ii] += data->cpus[ii] ; + +data->cpus *is* cpus, so DVzero() erases the measurements and the loop +then sums the zeros into themselves. The MT solve's cpu breakdown has +always been reported as all zeros. + +FactorData already does this correctly, with an embedded double +cpus[20] per thread that the master sums after the join. Do the same +here: embed double cpus[8] in SolveData, zero it per thread at setup, +and leave the existing reduction, which now has something real to +reduce. + +With this the MT factor and solve are ThreadSanitizer-clean. +--- + MT/src/solveMT.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/MT/src/solveMT.c b/MT/src/solveMT.c +index c2fd58c..fe2fab1 100644 +--- a/MT/src/solveMT.c ++++ b/MT/src/solveMT.c +@@ -78,7 +78,7 @@ struct _SolveData { + char *lowerIsDone ; + char *diagIsDone ; + char *upperIsDone ; +- double *cpus ; ++ double cpus[8] ; + int msglvl ; + FILE *msgFile ; + } ; +@@ -176,7 +176,7 @@ for ( myid = 0, data = dataObjects ; myid < nthread ; myid++, data++ ) { + data->lowerIsDone = lowerIsDone ; + data->diagIsDone = diagIsDone ; + data->upperIsDone = upperIsDone ; +- data->cpus = cpus ; ++ DVzero(8, data->cpus) ; + data->msglvl = msglvl ; + if ( msglvl > 0 ) { + sprintf(buffer, "solve.res.%d", myid) ; diff --git a/native/calculix/spooles-patches/0006-I2Ohash-fix-int-overflow-in-the-bucket-index.patch b/native/calculix/spooles-patches/0006-I2Ohash-fix-int-overflow-in-the-bucket-index.patch new file mode 100644 index 0000000..cbb42c3 --- /dev/null +++ b/native/calculix/spooles-patches/0006-I2Ohash-fix-int-overflow-in-the-bucket-index.patch @@ -0,0 +1,111 @@ +From: Jacob Oursland +Subject: [PATCH] I2Ohash: fix int overflow in the bucket index + +I2Ohash_insert(), I2Ohash_locate() and I2Ohash_remove() each compute the +bucket for a (key1,key2) pair as + + loc1 = (key1 + 1) % hashtable->nlist ; + loc2 = (key2 + 1) % hashtable->nlist ; + loc = (loc1*loc2) % hashtable->nlist ; + +loc1*loc2 is a signed int multiplication. Both factors can approach +nlist, so the product overflows once nlist > 46341 -- undefined +behaviour, and in practice a negative index into heads[]. + +FrontMtx/src/postProcess.c:127 sizes that table with + + I2Ohash_init(frontmtx->upperhash, nfront, nfront, nfront) + +so any factorization with more than ~46k fronts is exposed. The +reported symptom is a segfault in I2Ohash_insert() reached from +FrontMtx_splitUpperMatrices(). + +Widen the product to long int and cast back. I2Ohash_measure() and +I2Ohash_writeStats() accumulate count*count the same way; make those +products double. + +Debian carries this as debian/patches/I2Ohash-64bit.patch and FreeBSD +ports as files/patch-I2Ohash-large-input. conda-forge did not have it. + +--- a/I2Ohash/src/util.c ++++ b/I2Ohash/src/util.c +@@ -20,6 +20,7 @@ + void *value + ) { + int loc, loc1, loc2 ; ++long int loc3 ; + I2OP *i2op, *j2op, *prev ; + + if ( hashtable == NULL ) { +@@ -39,9 +40,10 @@ + */ + loc1 = (key1 + 1) % hashtable->nlist ; + loc2 = (key2 + 1) % hashtable->nlist ; +-loc = (loc1*loc2) % hashtable->nlist ; ++loc3 = (long int)loc1*(long int)loc2 % hashtable->nlist ; ++loc =(int) loc3; + #if MYDEBUG > 0 +-fprintf(stdout, "\n loc1 = %d, loc2 = %d, loc3 = %d", loc1, loc2, loc) ; ++fprintf(stdout, "\n loc1 = %d, loc2 = %d, loc3 = %ld, loc = %d", loc1, loc2, loc3, loc) ; + fflush(stdout) ; + #endif + /* +@@ -139,6 +141,7 @@ + void **pvalue + ) { + int loc, loc1, loc2, rc ; ++long int loc3 ; + I2OP *i2op ; + /* + --------------- +@@ -158,9 +161,10 @@ + #endif + loc1 = (key1 + 1) % hashtable->nlist ; + loc2 = (key2 + 1) % hashtable->nlist ; +-loc = (loc1*loc2) % hashtable->nlist ; ++loc3 = (long int)loc1*(long int)loc2 % hashtable->nlist ; ++loc = (int) loc3 ; + #if MYDEBUG > 0 +-fprintf(stdout, "\n loc1 = %d, loc2 = %d, loc3 = %d", loc1, loc2, loc) ; ++fprintf(stdout, "\n loc1 = %d, loc2 = %d, loc3 = %ld, loc = %d", loc1, loc2, loc3, loc) ; + fflush(stdout) ; + #endif + /* +@@ -215,6 +219,7 @@ + void **pvalue + ) { + int loc, loc1, loc2, rc ; ++long int loc3 ; + I2OP *i2op, *prev ; + /* + --------------- +@@ -229,7 +234,8 @@ + } + loc1 = (key1 + 1) % hashtable->nlist ; + loc2 = (key2 + 1) % hashtable->nlist ; +-loc = (loc1*loc2) % hashtable->nlist ; ++loc3 = (long int)loc1*(long int)loc2 % hashtable->nlist ; ++loc = (int) loc3 ; + /* + --------------------------------------------------- + find the location of the first (key1,key2,*) triple +@@ -294,7 +300,7 @@ + count++ ; + i2op = i2op->next ; + } +- measure += count*count ; ++ measure += (double)count*(double)count ; + } + } + measure = sqrt(measure) ; +--- a/I2Ohash/src/IO.c ++++ b/I2Ohash/src/IO.c +@@ -41,7 +41,7 @@ + i2op->value0, i2op->value1, i2op->value2) ; + i2op = i2op->next ; + } +- measure += count*count ; ++ measure += (double)count*(double)count ; + nfull++ ; + } + } diff --git a/native/sprung-solve/LICENSE b/native/sprung-solve/LICENSE new file mode 100644 index 0000000..4c2f3d2 --- /dev/null +++ b/native/sprung-solve/LICENSE @@ -0,0 +1,24 @@ +MIT License + +Copyright (c) 2026 Sprung FEA contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Prebuilt sprung-solve executables also contain Intel oneMKL, under the Intel +Simplified Software License (Intel-oneMKL.txt), with the third-party notices diff --git a/native/sprung-solve/protocol.h b/native/sprung-solve/protocol.h new file mode 100644 index 0000000..758fac6 --- /dev/null +++ b/native/sprung-solve/protocol.h @@ -0,0 +1,46 @@ +/* The sprung-solve protocol, version 1: a client sends a sparse linear + system to the sprung-solve process through its standard input, and reads + the replies from its standard output. docs/solver-protocol.md describes + it in full. + + SPDX-License-Identifier: MIT + Copyright (c) 2026 Sprung FEA contributors */ + +#ifndef SPRUNG_SOLVE_PROTOCOL_H +#define SPRUNG_SOLVE_PROTOCOL_H + +#include + +#define SPRUNG_SOLVE_VERSION 1 +/* "SPRS", read as a little-endian 32-bit integer. */ +#define SPRUNG_SOLVE_MAGIC 0x53525053u + +/* Every request starts with this header; a payload follows. */ +struct sprung_solve_request { + uint32_t magic; + uint32_t op; + uint64_t handle; /* chosen by the client; names one factorization */ +}; + +enum sprung_solve_op { + SPRUNG_SOLVE_HELLO = 0, /* u32 version */ + SPRUNG_SOLVE_FACTOR = 1, /* u32 kind, u32 threads, i64 n, i64 nnz, + i64 row_start[n+1], i64 column[nnz], + f64 value[nnz] */ + SPRUNG_SOLVE_SOLVE = 2, /* i64 n, i64 nrhs, f64 b[n*nrhs] */ + SPRUNG_SOLVE_RELEASE = 3, /* nothing */ +}; + +/* The matrix, by rows (compressed sparse rows), 0-based, the columns of + each row ascending. */ +enum sprung_solve_kind { + SPRUNG_SOLVE_SYMMETRIC = 0, /* the upper triangle */ + SPRUNG_SOLVE_STRUCTURALLY_SYMMETRIC = 1, /* every entry */ + SPRUNG_SOLVE_UNSYMMETRIC = 2, /* every entry */ +}; + +/* Every reply: i32 status (0: done), u32 length, that many bytes of text + (UTF-8, no terminator): the solver's name after HELLO, otherwise what + went wrong, or nothing. A SOLVE that is done then sends f64 x[n*nrhs]. */ + +#endif diff --git a/native/sprung-solve/sprung_solve.c b/native/sprung-solve/sprung_solve.c new file mode 100644 index 0000000..81412f5 --- /dev/null +++ b/native/sprung-solve/sprung_solve.c @@ -0,0 +1,523 @@ +/* sprung-solve: solves sparse linear systems with Intel oneMKL's PARDISO, + in a process of its own. + + sprung-solve --serve + Takes systems through standard input and answers through standard + output, by the protocol in protocol.h (docs/solver-protocol.md). + CalculiX, as built for Sprung FEA, starts it this way for its PARDISO + solves. Ends when its input closes. + sprung-solve --version + Checks that PARDISO solves on this computer, and names it. + sprung-solve A.mtx [b.mtx] + Solves A x = b for a Matrix Market matrix A (coordinate; real or + integer; general or symmetric) and right-hand side b (array; all ones + when not given), and prints x, one value per line. + + Each factorization keeps PARDISO's analysis (ordering and symbolic + factorization) while the matrix's structure stays the same, so the + iterations of a nonlinear step only refactor. + + SPDX-License-Identifier: MIT + Copyright (c) 2026 Sprung FEA contributors */ + +#include +#include +#include +#include + +#include + +#include "protocol.h" + +#ifdef _WIN32 +#include +#include +#endif +#ifdef __linux__ +#include +#include +#include +#endif + +/* ---------------------------------------------------------------- PARDISO */ + +struct system { + uint64_t handle; + int factored; + uint32_t kind; + long long mtype, n, nnz; + long long *rows, *columns; + double *values; + void *pt[64]; + long long iparm[64]; +}; + +static void *allocate(size_t bytes) { + void *p = malloc(bytes ? bytes : 1); + if (!p) { + fprintf(stderr, "sprung-solve: out of memory (%zu bytes)\n", bytes); + exit(3); + } + return p; +} + +static const char *pardiso_error(long long error) { + switch (error) { + case -1: return "the input is inconsistent"; + case -2: return "there is not enough memory"; + case -3: return "the reordering failed"; + case -4: return "a zero pivot was found: the system is singular"; + case -5: return "an internal error occurred"; + case -6: return "the preordering failed"; + case -7: return "the diagonal is singular"; + case -8: return "a 32-bit integer overflowed"; + case -9: return "there is not enough memory for the out-of-core solver"; + case -10: return "the out-of-core files could not be opened"; + case -11: return "the out-of-core files could not be read or written"; + case -13: return "the solve was interrupted"; + default: return "it failed"; + } +} + +static long long mtype_of(uint32_t kind) { + /* Real: symmetric indefinite (CalculiX's stiffness matrices can be + shifted indefinite, as in frequency analyses), structurally symmetric, + unsymmetric. */ + return kind == SPRUNG_SOLVE_SYMMETRIC ? -2 + : kind == SPRUNG_SOLVE_STRUCTURALLY_SYMMETRIC ? 1 : 11; +} + +static long long call(struct system *s, long long phase, long long nrhs, + double *b, double *x) { + long long maxfct = 1, mnum = 1, msglvl = 0, error = 0, perm = 0; + pardiso_64(s->pt, &maxfct, &mnum, &s->mtype, &phase, &s->n, s->values, + s->rows, s->columns, &perm, &nrhs, s->iparm, &msglvl, b, x, + &error); + return error; +} + +static void release(struct system *s) { + if (s->factored) call(s, -1, 1, NULL, NULL); + s->factored = 0; + free(s->rows); + free(s->columns); + free(s->values); + s->rows = s->columns = NULL; + s->values = NULL; +} + +/* PARDISO's defaults for the matrix type (what CalculiX asks for), with + 0-based indices and the parallel nested dissection ordering, and + iterative refinement only after pivots were perturbed (MKL's "automatic" + setting) rather than pardisoinit's two steps on every solve. Refinement + in working precision ruins nearly singular systems: CalculiX's frequency + analysis of a free part factors K - M, whose rigid-body directions sit + ten orders of magnitude below its elastic ones, and refined solves there + turned elastic modes into spurious ones. */ +static void defaults(struct system *s) { + MKL_INT mtype = (MKL_INT)s->mtype, iparm[64]; + int i; + pardisoinit(s->pt, &mtype, iparm); + for (i = 0; i < 64; i++) s->iparm[i] = iparm[i]; + s->iparm[0] = 1; /* not all defaults: these are set */ + s->iparm[1] = 3; /* parallel nested dissection */ + s->iparm[7] = 0; /* refine only after perturbed pivots */ + s->iparm[34] = 1; /* 0-based indices */ +} + +/* Takes ownership of the arrays. Returns PARDISO's error code. */ +static long long factor(struct system *s, uint32_t kind, long long n, + long long nnz, long long *rows, long long *columns, + double *values) { + int same = s->factored && s->kind == kind && s->n == n && s->nnz == nnz && + !memcmp(s->rows, rows, sizeof *rows * (n + 1)) && + !memcmp(s->columns, columns, sizeof *columns * nnz); + long long error; + if (same) { + free(rows); + free(columns); + free(s->values); + s->values = values; + error = call(s, 22, 1, NULL, NULL); + } else { + release(s); + s->kind = kind; + s->mtype = mtype_of(kind); + s->n = n; + s->nnz = nnz; + s->rows = rows; + s->columns = columns; + s->values = values; + defaults(s); + error = call(s, 12, 1, NULL, NULL); + } + s->factored = 1; + if (error) release(s); + return error; +} + +static const char *describe(void) { + static char name[128]; + MKLVersion v; + mkl_get_version(&v); + /* 2026.1 is major version 2026, update 1. */ + snprintf(name, sizeof name, "Intel oneMKL %d.%d PARDISO", v.MajorVersion, + v.UpdateVersion); + return name; +} + +/* --------------------------------------------------------------- protocol */ + +static void receive(void *data, size_t bytes, int may_end) { + size_t got = fread(data, 1, bytes, stdin); + if (got == bytes) return; + /* The client closed its end: it is done, or gone. */ + if (got == 0 && may_end) exit(0); + fprintf(stderr, "sprung-solve: the request ended early\n"); + exit(2); +} + +static void *receive_array(size_t count, size_t size) { + void *data = allocate(count * size); + receive(data, count * size, 0); + return data; +} + +static void put(const void *data, size_t bytes) { + if (fwrite(data, 1, bytes, stdout) != bytes) exit(2); +} + +static void reply(int32_t status, const char *text) { + uint32_t length = (uint32_t)strlen(text); + put(&status, sizeof status); + put(&length, sizeof length); + put(text, length); +} + +static void reply_error(const char *what, long long error) { + char text[256]; + snprintf(text, sizeof text, "%s: %s (PARDISO error %lld)", what, + pardiso_error(error), error); + reply(error ? (int32_t)error : -1, text); +} + +static struct system *systems; +static size_t count, capacity; + +static struct system *find(uint64_t handle, int create) { + size_t i; + for (i = 0; i < count; i++) + if (systems[i].handle == handle) return &systems[i]; + if (!create) return NULL; + if (count == capacity) { + capacity = capacity ? 2 * capacity : 4; + systems = realloc(systems, capacity * sizeof *systems); + if (!systems) exit(3); + } + memset(&systems[count], 0, sizeof *systems); + systems[count].handle = handle; + return &systems[count++]; +} + +/* Rows and columns must index inside the matrix, as PARDISO does not + check them all. */ +static int valid(uint32_t kind, long long n, long long nnz, + const long long *rows, const long long *columns) { + long long i, k; + if (kind > SPRUNG_SOLVE_UNSYMMETRIC || rows[0] != 0 || rows[n] != nnz) + return 0; + for (i = 0; i < n; i++) { + if (rows[i + 1] < rows[i]) return 0; + /* PARDISO needs every diagonal entry of a symmetric matrix. */ + if (kind == SPRUNG_SOLVE_SYMMETRIC && + (rows[i + 1] == rows[i] || columns[rows[i]] != i)) + return 0; + for (k = rows[i]; k < rows[i + 1]; k++) + if (columns[k] < (kind == SPRUNG_SOLVE_SYMMETRIC ? i : 0) || + columns[k] >= n || (k > rows[i] && columns[k] <= columns[k - 1])) + return 0; + } + return 1; +} + +static void serve(void) { + struct sprung_solve_request request; +#ifdef __linux__ + /* Ends with CalculiX, even mid-factorization. */ + prctl(PR_SET_PDEATHSIG, SIGKILL); + if (getppid() == 1) exit(0); +#endif + for (;;) { + struct system *s; + receive(&request, sizeof request, 1); + if (request.magic != SPRUNG_SOLVE_MAGIC) { + fprintf(stderr, "sprung-solve: not a request\n"); + exit(2); + } + switch (request.op) { + case SPRUNG_SOLVE_HELLO: { + uint32_t version; + receive(&version, sizeof version, 0); + if (version != SPRUNG_SOLVE_VERSION) + reply(-1, "this sprung-solve speaks protocol version 1"); + else + reply(0, describe()); + break; + } + case SPRUNG_SOLVE_FACTOR: { + uint32_t kind, threads; + long long n, nnz, *rows, *columns, error; + double *values; + receive(&kind, sizeof kind, 0); + receive(&threads, sizeof threads, 0); + receive(&n, sizeof n, 0); + receive(&nnz, sizeof nnz, 0); + if (n < 1 || nnz < 1) { + fprintf(stderr, "sprung-solve: a matrix of order %lld with %lld entries\n", n, nnz); + exit(2); + } + rows = receive_array((size_t)n + 1, sizeof *rows); + columns = receive_array((size_t)nnz, sizeof *columns); + values = receive_array((size_t)nnz, sizeof *values); + if (!valid(kind, n, nnz, rows, columns)) { + free(rows); + free(columns); + free(values); + reply(-1, "the matrix is not 0-based compressed rows with ascending " + "columns (when symmetric, the upper triangle with every " + "diagonal entry)"); + break; + } + if (threads) mkl_set_num_threads((int)threads); + s = find(request.handle, 1); + error = factor(s, kind, n, nnz, rows, columns, values); + if (error) reply_error("The factorization failed", error); + else reply(0, ""); + break; + } + case SPRUNG_SOLVE_SOLVE: { + long long n, nrhs, error; + double *b, *x; + receive(&n, sizeof n, 0); + receive(&nrhs, sizeof nrhs, 0); + if (n < 1 || nrhs < 1) exit(2); + b = receive_array((size_t)(n * nrhs), sizeof *b); + s = find(request.handle, 0); + if (!s || !s->factored || s->n != n) { + reply(-1, "there is no factorization of this order to solve with"); + } else { + x = allocate(sizeof *x * (size_t)(n * nrhs)); + error = call(s, 33, nrhs, b, x); + if (error) { + reply_error("The solve failed", error); + } else { + reply(0, ""); + put(x, sizeof *x * (size_t)(n * nrhs)); + } + free(x); + } + free(b); + break; + } + case SPRUNG_SOLVE_RELEASE: + s = find(request.handle, 0); + if (s) { + release(s); + *s = systems[--count]; + } + reply(0, ""); + break; + default: + fprintf(stderr, "sprung-solve: unknown request %u\n", request.op); + exit(2); + } + fflush(stdout); + } +} + +/* ------------------------------------------------------------ Matrix Market */ + +struct entry { + long long row, column; + double value; +}; + +static int by_position(const void *a, const void *b) { + const struct entry *p = a, *q = b; + if (p->row != q->row) return p->row < q->row ? -1 : 1; + return p->column < q->column ? -1 : p->column > q->column; +} + +static FILE *open_market(const char *path, char *header, size_t size) { + FILE *file = fopen(path, "r"); + char *c; + if (!file || !fgets(header, (int)size, file)) { + fprintf(stderr, "sprung-solve: %s could not be read\n", path); + exit(1); + } + for (c = header; *c; c++) + if (*c >= 'A' && *c <= 'Z') *c += 'a' - 'A'; + if (strncmp(header, "%%matrixmarket matrix ", 22) || strstr(header, "complex") || + strstr(header, "pattern")) { + fprintf(stderr, "sprung-solve: %s is not a real Matrix Market matrix\n", path); + exit(1); + } + return file; +} + +/* The next line that is not a comment. */ +static char *line(FILE *file, char *buffer, int size) { + while (fgets(buffer, size, file)) + if (buffer[0] != '%' && strspn(buffer, " \t\r\n") != strlen(buffer)) + return buffer; + return NULL; +} + +static void solve_files(const char *matrix, const char *rhs) { + char header[256], buffer[512]; + FILE *file = open_market(matrix, header, sizeof header); + int symmetric = strstr(header, "symmetric") != NULL; + long long m, n, nz, i, k, kept; + struct entry *entries; + struct system s; + long long *rows, *columns; + double *values, *b, *x; + long long error; + if (!strstr(header, "coordinate") || strstr(header, "skew") || + strstr(header, "hermitian") || !line(file, buffer, sizeof buffer) || + sscanf(buffer, "%lld %lld %lld", &m, &n, &nz) != 3 || m != n || n < 1) { + fprintf(stderr, "sprung-solve: %s is not a square coordinate matrix, " + "general or symmetric\n", matrix); + exit(1); + } + /* Symmetric: every diagonal entry, as PARDISO needs, zero if absent. */ + entries = allocate(sizeof *entries * (size_t)(nz + n)); + for (k = 0; k < nz; k++) { + long long r, c; + double v; + if (!line(file, buffer, sizeof buffer) || + sscanf(buffer, "%lld %lld %lf", &r, &c, &v) != 3 || r < 1 || c < 1 || + r > n || c > n) { + fprintf(stderr, "sprung-solve: entry %lld of %s is not valid\n", k + 1, matrix); + exit(1); + } + /* The upper triangle of a symmetric matrix (the file has the lower). */ + if (symmetric && r > c) { long long t = r; r = c; c = t; } + entries[k].row = r - 1; + entries[k].column = c - 1; + entries[k].value = v; + } + fclose(file); + if (symmetric) + for (i = 0; i < n; i++) { + entries[nz + i].row = entries[nz + i].column = i; + entries[nz + i].value = 0; + } + nz += symmetric ? n : 0; + qsort(entries, (size_t)nz, sizeof *entries, by_position); + + rows = allocate(sizeof *rows * (size_t)(n + 1)); + columns = allocate(sizeof *columns * (size_t)nz); + values = allocate(sizeof *values * (size_t)nz); + memset(rows, 0, sizeof *rows * (size_t)(n + 1)); + /* Duplicates add up. */ + for (k = 0, kept = 0; k < nz; k++) { + if (kept && entries[k].row == entries[k - 1].row && + entries[k].column == entries[k - 1].column) { + values[kept - 1] += entries[k].value; + continue; + } + columns[kept] = entries[k].column; + values[kept] = entries[k].value; + rows[entries[k].row + 1]++; + kept++; + } + free(entries); + for (i = 0; i < n; i++) rows[i + 1] += rows[i]; + + b = allocate(sizeof *b * (size_t)n); + for (i = 0; i < n; i++) b[i] = 1; + if (rhs) { + long long rows, columns; + file = open_market(rhs, header, sizeof header); + if (!strstr(header, "array") || !line(file, buffer, sizeof buffer) || + sscanf(buffer, "%lld %lld", &rows, &columns) != 2 || rows != n || + columns != 1) { + fprintf(stderr, "sprung-solve: %s is not an array of %lld values\n", rhs, n); + exit(1); + } + for (i = 0; i < n; i++) + if (!line(file, buffer, sizeof buffer) || sscanf(buffer, "%lf", &b[i]) != 1) { + fprintf(stderr, "sprung-solve: %s has too few values\n", rhs); + exit(1); + } + fclose(file); + } + memset(&s, 0, sizeof s); + error = factor(&s, symmetric ? SPRUNG_SOLVE_SYMMETRIC : SPRUNG_SOLVE_UNSYMMETRIC, + n, kept, rows, columns, values); + if (error) { + fprintf(stderr, "sprung-solve: the factorization failed: %s (PARDISO error %lld)\n", + pardiso_error(error), error); + exit(1); + } + x = allocate(sizeof *x * (size_t)n); + error = call(&s, 33, 1, b, x); + if (error) { + fprintf(stderr, "sprung-solve: the solve failed: %s (PARDISO error %lld)\n", + pardiso_error(error), error); + exit(1); + } + for (i = 0; i < n; i++) printf("%.17g\n", x[i]); + release(&s); +} + +/* A small indefinite system with a known answer: PARDISO loads and runs on + this processor. */ +static int works(void) { + struct system s; + long long rows[] = {0, 2, 4, 5}, columns[] = {0, 1, 1, 2, 2}; + double values[] = {4, 1, -3, 1, 2}, b[3], x[3] = {1, 2, 3}, y[3]; + long long *r = allocate(sizeof rows), *c = allocate(sizeof columns); + double *v = allocate(sizeof values); + int i, ok; + memcpy(r, rows, sizeof rows); + memcpy(c, columns, sizeof columns); + memcpy(v, values, sizeof values); + b[0] = 4 * x[0] + x[1]; + b[1] = x[0] - 3 * x[1] + x[2]; + b[2] = x[1] + 2 * x[2]; + memset(&s, 0, sizeof s); + if (factor(&s, SPRUNG_SOLVE_SYMMETRIC, 3, 5, r, c, v)) return 0; + ok = !call(&s, 33, 1, b, y); + for (i = 0; i < 3; i++) ok = ok && y[i] > x[i] - 1e-9 && y[i] < x[i] + 1e-9; + release(&s); + return ok; +} + +int main(int argc, char **argv) { + if (argc == 2 && !strcmp(argv[1], "--serve")) { +#ifdef _WIN32 + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); +#endif + setvbuf(stdin, NULL, _IOFBF, 1 << 20); + setvbuf(stdout, NULL, _IOFBF, 1 << 20); + serve(); + return 0; + } + if (argc == 2 && !strcmp(argv[1], "--version")) { + if (!works()) { + printf("sprung-solve %d: PARDISO does not work here\n", SPRUNG_SOLVE_VERSION); + return 1; + } + printf("sprung-solve %d: %s\n", SPRUNG_SOLVE_VERSION, describe()); + return 0; + } + if ((argc == 2 || argc == 3) && argv[1][0] != '-') { + solve_files(argv[1], argc == 3 ? argv[2] : NULL); + return 0; + } + fprintf(stderr, "Usage: sprung-solve --serve | --version | A.mtx [b.mtx]\n"); + return 2; +} diff --git a/package.json b/package.json index 6d7e795..83423ac 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "type": "module", - "description": "A friendly, open-source mechanical FEA workspace", + "description": "A friendly mechanical FEA workspace", "license": "GPL-3.0-or-later", "main": "electron/main.cjs", "scripts": { @@ -16,6 +16,7 @@ "dist:mac": "npm run package:mac && electron-builder --prepackaged 'release/mac-arm64/Sprung FEA.app' --mac dmg --publish never", "package:win": "npm run build && npm run bundle:engine:win && electron-builder --win nsis --publish never", "package:linux": "npm run build && npm run bundle:engine && electron-builder --linux AppImage --publish never", + "build:solver": "python3 scripts/build-solver.py", "bundle:engine": ".venv/bin/python scripts/bundle-runtime.py", "bundle:engine:win": ".venv\\Scripts\\python.exe scripts/bundle-runtime.py", "test:e2e": "playwright test", diff --git a/scripts/build-solver.py b/scripts/build-solver.py new file mode 100644 index 0000000..f436e6c --- /dev/null +++ b/scripts/build-solver.py @@ -0,0 +1,351 @@ +"""Build CalculiX 2.23 with its fastest direct solvers, on Apple silicon, +Linux x64 and Windows x64. + +Writes solver/ccx (ccx.exe) with the libraries it needs beside it +(solverlibs.py), which the engine and bundle-runtime.py use before any +installed CalculiX, and solver/ccx.json, which tells the engine what the +build can do. The compilers and libraries come from a conda-forge +environment, native/calculix/solver-env-.yml: pass its folder +with --prefix, or run with it active (CONDA_PREFIX). macOS also needs the +Xcode command line tools, and Windows Visual Studio's C++ build tools. + +The build carries two direct solvers, both multithreaded: +- SPOOLES 2.2. Its threaded factor and solve hand work between threads + through plain loads and stores, which lose updates and return wrong + answers (often on Apple silicon). The patches in + native/calculix/spooles-patches, from conda-forge's spooles feedstock + (build 1006), order those hand-offs. +- PARDISO: Apple Accelerate's sparse factorizations on macOS, through + native/calculix/accelerate_pardiso.c. On Linux and Windows it is Intel + oneMKL's, which is not free software, so CalculiX does not link it: + native/calculix/pardiso_client.c hands CalculiX's PARDISO calls through + a pipe to sprung-solve (native/sprung-solve, MIT), a program of its own + that links MKL statically, written to solver/sprung-solve/. With + --without-mkl, sprung-solve is not built and the solver has SPOOLES + only.""" +import argparse, concurrent.futures, hashlib, json, os, re, shutil, subprocess, sys, tarfile, urllib.request +from pathlib import Path + +root=Path(__file__).resolve().parents[1] +native=root/'native'/'calculix' +work=root/'.sprung-fea'/'solver-build' +downloads=root/'.sprung-fea'/'downloads' +VERSION='2.23' +SOURCES={ + 'ccx':(['https://www.dhondt.de/ccx_2.23.src.tar.bz2'],'9c88385c10fb04f5dc6c4e98027a51bebdd8aee3920e05190d6c1dd08357d6e7'), + # The Debian/Ubuntu archive keeps the identical file. + 'spooles':(['https://www.netlib.org/linalg/spooles/spooles.2.2.tgz', + 'http://archive.ubuntu.com/ubuntu/pool/universe/s/spooles/spooles_2.2.orig.tar.gz'], + 'a84559a0e987a1e423055ef4fdf3035d55b65bbe4bf915efaa1a35bef7f8c5dd'), +} +SPOOLES_PATCHES=( + '0000-transform-ivinit.patch', + '0001-MT-add-acquire-release-primitives-and-order-the-work.patch', + '0002-MT-order-the-frontIsDone-p_mtx-publication-in-the-so.patch', + '0003-MT-make-the-solve-s-three-inter-phase-barriers-actua.patch', + '0004-MT-stop-losing-updates-on-the-factor-s-entry-counter.patch', + '0005-MT-give-each-solve-thread-its-own-cpus-vector.patch', + '0006-I2Ohash-fix-int-overflow-in-the-bucket-index.patch', +) +# Electron's minimum macOS. Accelerate's LU is used where the OS has it. +DEPLOYMENT_TARGET='12.0' +MAC,WINDOWS=sys.platform=='darwin',sys.platform=='win32' +# What GCC 14 and clang 16 made errors, and CalculiX's older C still relies +# on. +LENIENT=[f'-Wno-error={w}' for w in ('implicit-function-declaration','implicit-int','int-conversion','incompatible-pointer-types')] +jobs=os.cpu_count() or 4 + + +def fetch(name): + urls,digest=SOURCES[name] + path=downloads/Path(urls[0]).name + def valid(): + return path.exists() and (digest is None or hashlib.sha256(path.read_bytes()).hexdigest()==digest) + for url in urls: + if valid(): break + downloads.mkdir(parents=True,exist_ok=True) + print('Downloading',url,flush=True) + try: + with urllib.request.urlopen(url,timeout=120) as response: path.write_bytes(response.read()) + except OSError as error: print(' ',error) + if not valid(): sys.exit(f'{path.name} could not be downloaded, or does not match its expected SHA-256.') + print(f'{path.name}: SHA-256 {hashlib.sha256(path.read_bytes()).hexdigest()}') + return path + + +def extract(archive, destination): + with tarfile.open(archive) as tar: + if hasattr(tarfile,'data_filter'): tar.extractall(destination,filter='data') + else: tar.extractall(destination) + + +def replace(path, old, new, count=1): + text=path.read_text(errors='surrogateescape') + if text.count(old)!=count: sys.exit(f'{path}: expected {count} occurrence(s) of {old!r}') + path.write_text(text.replace(old,new),errors='surrogateescape') + + +def run(*args, cwd=None, env=None, quiet=False): + result=subprocess.run([str(a) for a in args],cwd=cwd,env={**os.environ,**(env or {})}, + capture_output=quiet,text=True) + if result.returncode: + if quiet: print(result.stdout,result.stderr) + sys.exit(f'Failed ({result.returncode}): {" ".join(str(a) for a in args)}') + + +class Toolchain: + """The environment's compilers and libraries.""" + def __init__(self, prefix): + self.prefix=prefix + self.env={} + if WINDOWS: + base=prefix/'Library' + self.bin,self.lib,self.include=base/'bin',base/'lib',base/'include' + self.cc,self.fc,self.ar=(self.tool('x86_64-w64-mingw32-'+t) for t in ('gcc','gfortran','ar')) + # The MinGW tools load DLLs from the environment, which is not + # activated. + self.env={'PATH':os.pathsep.join([str(self.bin),str(prefix),os.environ.get('PATH','')])} + elif MAC: + self.bin,self.lib,self.include=prefix/'bin',prefix/'lib',prefix/'include' + sdk=subprocess.check_output(['xcrun','--show-sdk-path'],text=True).strip() + # gfortran runs the environment's clang to assemble. + self.env={'MACOSX_DEPLOYMENT_TARGET':DEPLOYMENT_TARGET,'SDKROOT':sdk, + 'PATH':os.pathsep.join([str(self.bin),os.environ.get('PATH','')])} + # Xcode's clang: its SDK declares Accelerate's sparse LU. + self.cc,self.ar=shutil.which('clang'),shutil.which('ar') + self.fc=self.tool('arm64-apple-darwin20.0.0-gfortran') + else: + self.bin,self.lib,self.include=prefix/'bin',prefix/'lib',prefix/'include' + self.cc,self.fc,self.ar=(self.tool('x86_64-conda-linux-gnu-'+t) for t in ('gcc','gfortran','ar')) + + def tool(self, name): + path=self.bin/(name+('.exe' if WINDOWS else '')) + if not path.is_file(): sys.exit(f'{path} was not found. Create the build environment from native/calculix/solver-env-*.yml.') + return path + + def compile(self, sources, objects, flags, cwd, fortran=False): + """Compiles in parallel; sources and objects pair up.""" + compiler=self.fc if fortran else self.cc + def one(pair): + source,obj=pair + result=subprocess.run([str(compiler),*flags,'-c',str(source),'-o',str(obj)],cwd=cwd, + env={**os.environ,**self.env},capture_output=True,text=True) + return source,result + with concurrent.futures.ThreadPoolExecutor(jobs) as pool: + for source,result in pool.map(one,list(zip(sources,objects))): + if result.returncode: + print(result.stdout,result.stderr) + sys.exit(f'Compiling {source} failed (exit {result.returncode:#x}).') + + def archive(self, library, objects): + library.unlink(missing_ok=True) + # A response file keeps Windows' command line short. + listing=library.with_suffix('.txt') + listing.write_text('\n'.join(str(o).replace('\\','/') for o in objects)) + if MAC: run(self.ar,'rcs',library,*objects,env=self.env) + else: run(self.ar,'rcs',library,f'@{listing}',env=self.env) + + +def spooles_patches(): + """The thread fixes, in order. A missing one would still build a solver + that starts, but whose threaded solves give wrong answers, so refuse.""" + folder=native/'spooles-patches' + found=sorted(folder.glob('*.patch')) + missing=[name for name in SPOOLES_PATCHES if not (folder/name).is_file()] + extra=[path.name for path in found if path.name not in SPOOLES_PATCHES] + if missing or extra: + sys.exit(f'{folder} does not hold the expected SPOOLES patches.' + +(f'\nMissing: {", ".join(missing)}' if missing else '') + +(f'\nUnexpected: {", ".join(extra)} (add them to SPOOLES_PATCHES)' if extra else '')) + return [folder/name for name in SPOOLES_PATCHES] + + +def build_spooles(tc): + """spooles.a: the library modules SPOOLES's own makefile lists, and its + threaded factor and solve (MT). Every source of each module is + compiled; the module makefiles' lists are stale, and the linker takes + only what CalculiX uses. Objects are named per module, as the makefiles + do, because file names repeat between modules.""" + patches=spooles_patches() + source=work/'spooles';source.mkdir(parents=True) + extract(fetch('spooles'),source) + patch=shutil.which('patch') + if not patch: sys.exit('patch was not found. On Windows, run the build from Git Bash.') + for p in patches: run(patch,'-p1','--batch','--forward',*(['--binary'] if WINDOWS else []),'-i',p,cwd=source) + modules=re.findall(r'^\s*cd (\w+)\s*; make lib',(source/'makefile').read_text(),re.M) + objects=source/'objects';objects.mkdir() + for module in [*modules,'MT']: + files=sorted((source/module/'src').glob('*.c')) + tc.compile(files,[objects/f'{module}_{f.stem}.o' for f in files],['-O2','-w'],cwd=source/module/'src') + library=source/'spooles.a' + tc.archive(library,sorted(objects.glob('*.o'))) + return source,library + + +def msvc_environment(): + """Visual Studio's 64-bit C build environment (its vcvars64.bat), for + sprung-solve on Windows: Intel oneMKL's static libraries are made for + Microsoft's compiler.""" + vswhere=Path(os.environ.get('ProgramFiles(x86)','C:/Program Files (x86)'))/'Microsoft Visual Studio'/'Installer'/'vswhere.exe' + found=subprocess.run([str(vswhere),'-latest','-products','*','-requires','Microsoft.VisualStudio.Component.VC.Tools.x86.x64', + '-find','VC\\Auxiliary\\Build\\vcvars64.bat'],capture_output=True,text=True).stdout.split('\n')[0].strip() if vswhere.is_file() else '' + if not found: sys.exit("Visual Studio's C++ build tools were not found; sprung-solve needs them (or pass --without-mkl).") + # A batch file of its own: cmd's quoting of a command line is unreliable. + script=work/'msvc-environment.bat' + script.write_text(f'@call "{found}" >nul\r\n@set\r\n') + listing=subprocess.check_output(['cmd','/d','/c',str(script)],text=True) + # Upper case, as os.environ has them on Windows: no name twice. + return {k.upper():v for k,v in (line.split('=',1) for line in listing.splitlines() if '=' in line[1:])} + + +def build_helper(tc): + """sprung-solve (native/sprung-solve), the program CalculiX's PARDISO + calls go to on Linux and Windows, with Intel oneMKL's PARDISO linked + statically: one file that holds what PARDISO uses, and MKL's threads on + the OpenMP runtime beside it (GNU's on Linux, LLVM's libiomp5md on + Windows). Returns the executable and the folders of its libraries.""" + source=root/'native'/'sprung-solve'/'sprung_solve.c' + out=work/'sprung-solve';out.mkdir() + if not (tc.include/'mkl.h').is_file(): + sys.exit(f'Intel oneMKL was not found in {tc.prefix}: create the environment from native/calculix/solver-env-*.yml, or pass --without-mkl.') + if WINDOWS: + env=msvc_environment() + cl=shutil.which('cl',path=env.get('PATH')) + if not cl: sys.exit("Visual Studio's C compiler (cl) was not found.") + exe=out/'sprung-solve.exe' + run(cl,'/nologo','/O2','/MD','/W3',f'/I{tc.include}',source,f'/Fe{exe}',f'/Fo{out}\\','/link',f'/LIBPATH:{tc.lib}', + 'mkl_intel_lp64.lib','mkl_intel_thread.lib','mkl_core.lib','libiomp5md.lib',cwd=out,env=env) + return exe,[tc.bin,tc.prefix] + exe=out/'sprung-solve' + lib=tc.lib + run(tc.cc,'-O2','-Wall',f'-I{tc.include}',source,'-o',exe, + '-Wl,--start-group',lib/'libmkl_intel_lp64.a',lib/'libmkl_gnu_thread.a',lib/'libmkl_core.a','-Wl,--end-group', + '-fopenmp','-lpthread','-lm','-ldl','-s',f'-Wl,-rpath,{lib}',env=tc.env) + return exe,[lib] + + +def ccx_sources(src): + """CalculiX's Fortran and C sources (its Makefile.inc), without its PaStiX + interface (PaStiX is not built in). The list can name a file the release + does not have (2.23: mafillmm.c); the link reports anything really + missing.""" + text=(src/'Makefile.inc').read_text() + def listed(name): + block=re.search(rf'^{name}\s*=(.*?)(?:\n\s*\n|\Z)',text,re.M|re.S).group(1) + files=re.findall(r'[\w.-]+\.[cf]\b',block) + absent=[f for f in files if not (src/f).is_file()] + if absent: print('Listed in Makefile.inc but not in the source:',', '.join(absent)) + return [f for f in files if f not in absent] + c=[f for f in listed('SCCXC') if f!='pastix.c'] + return listed('SCCXF'),c + + +def check_license(src): + """CalculiX's own files are GPL version 2 only ("published by the Free + Software Foundation(version 2)", without "or any later version"), which + THIRD_PARTY_NOTICES.md and the build's design rely on: nothing under an + incompatible license (GPL-3, LGPL-3, Intel's) is linked into it. Refuse + a release whose notices say otherwise.""" + notices=[p for p in src.iterdir() if p.suffix in ('.c','.f','.h') and 'General Public License' in p.read_text(errors='replace')] + only=[p for p in notices if re.search(r'Foundation\s*\(version 2\)',p.read_text(errors='replace'))] + later=[p for p in notices if re.search(r'any later\s+version',p.read_text(errors='replace'))] + print(f'CalculiX license notices: {len(notices)} files, {len(only)} GPL version 2 only, {len(later)} version 2 or later') + if len(only)<0.9*len(notices): + sys.exit("CalculiX's license notices are not the GPL version 2 only ones expected: review THIRD_PARTY_NOTICES.md.") + + +def build_ccx(tc, spooles, spooles_lib): + extract(fetch('ccx'),work) + src=work/'CalculiX'/f'ccx_{VERSION}'/'src' + check_license(src) + # A void function that returns a value (as Homebrew's formula fixes). + replace(src/'readnewmesh.c','*iprfnp=iprfn;*konrfnp=konrfn;*ratiorfnp=ratiorfn;\n \n return NULL;', + '*iprfnp=iprfn;*konrfnp=konrfn;*ratiorfnp=ratiorfn;\n \n return;') + # A Windows-only call written outside any function, which GCC 14 rejects; + # it chose two-digit exponents in the old msvcrt, which the UCRT prints + # anyway. + for name in (f'ccx_{VERSION}.c',f'ccx_{VERSION}step.c'): + replace(src/name,'#ifdef __WIN32\n_set_output_format(_TWO_DIGIT_EXPONENT);\n#endif\n','') + capabilities={'version':VERSION,'threadSafeSpooles':True} + defines=['-DARCH=Linux','-DSPOOLES','-DARPACK','-DMATRIXSTORAGE','-DNETWORKOUT','-DUSE_MT=1','-DPARDISO'] + # native/calculix/mkl_service.h stands in for MKL's header: CalculiX + # never links MKL. native/sprung-solve has the protocol's header. + includes=[f'-I{spooles}',f'-I{native}',f'-I{root/"native"/"sprung-solve"}',f'-I{tc.include}'] + if MAC: + extra=[native/'accelerate_pardiso.c'] + capabilities['pardiso']='Apple Accelerate' + libs=['-framework','Accelerate'] + else: + # PARDISO is offered once sprung-solve is built beside (main). + extra=[native/'pardiso_client.c'] + libs=[] + + cflags=['-O2','-w',*LENIENT,*includes,*defines] + fortran,c=ccx_sources(src) + objects=src/'objects';objects.mkdir() + print(f'Compiling CalculiX: {len(fortran)} Fortran and {len(c)+len(extra)} C files',flush=True) + fobj=[objects/(Path(f).stem+'_f.o') for f in fortran] + tc.compile([src/f for f in fortran],fobj,['-O2','-w','-fopenmp','-cpp','-fallow-argument-mismatch'],cwd=src,fortran=True) + cfiles=[src/f for f in c]+extra + cobj=[objects/(f.stem+'_c.o') for f in cfiles] + tc.compile(cfiles,cobj,cflags,cwd=src) + main=src/f'ccx_{VERSION}.c' + tc.compile([main],[objects/'ccx_main.o'],cflags,cwd=src) + library=src/f'ccx_{VERSION}.a' + tc.archive(library,fobj+cobj) + + exe=src/('ccx.exe' if WINDOWS else 'ccx') + if WINDOWS: + # conda's MinGW-built ARPACK sits apart from the MSVC-style libraries; + # OpenBLAS's import library carries BLAS and LAPACK. + blas=[f'-L{tc.prefix/"Library"/"mingw-w64"/"lib"}','-larpack',f'-L{tc.lib}','-lopenblas'] + else: + blas=[f'-L{tc.lib}','-larpack','-llapack','-lblas'] + common=[objects/'ccx_main.o',library,spooles_lib,*blas] + if MAC: + # Link with Xcode's clang, which knows the SDK. gfortran's runtime + # and OpenMP (LLVM's, which implements gfortran's GOMP calls) come + # from the environment. + run(tc.cc,'-o',exe,*common,*libs,'-lgfortran','-lomp',f'-Wl,-rpath,{tc.lib}',cwd=src,env=tc.env) + elif WINDOWS: + run(tc.fc,'-o',exe,*common,*libs,'-fopenmp','-lpthread',cwd=src,env=tc.env) + else: + run(tc.fc,'-o',exe,*common,*libs,'-fopenmp','-lpthread','-lm',f'-Wl,-rpath,{tc.lib}',cwd=src,env=tc.env) + folders=[tc.lib,tc.bin,tc.prefix/'Library'/'mingw-w64'/'bin'] + return exe,capabilities,folders + + +def main(): + parser=argparse.ArgumentParser(description=__doc__.split('\n')[0]) + parser.add_argument('--prefix',help='the conda-forge build environment (default: CONDA_PREFIX)') + parser.add_argument('--without-mkl',action='store_true',help='do not build sprung-solve: no PARDISO on Linux and Windows') + args=parser.parse_args() + if not (MAC and os.uname().machine=='arm64' or WINDOWS or sys.platform.startswith('linux')): + sys.exit('build-solver.py builds for Apple silicon, Linux x64 and Windows x64.') + prefix=args.prefix or os.environ.get('CONDA_PREFIX') + if not prefix: sys.exit('Pass --prefix with the build environment, created from native/calculix/solver-env-*.yml.') + tc=Toolchain(Path(prefix).resolve()) + shutil.rmtree(work,ignore_errors=True);work.mkdir(parents=True) + executable,capabilities,folders=build_ccx(tc,*build_spooles(tc)) + target=root/'solver' + shutil.rmtree(target,ignore_errors=True) + # patchelf comes with the Linux environment. + os.environ['PATH']=os.pathsep.join([str(tc.bin),os.environ.get('PATH','')]) + sys.path.insert(0,str(root/'scripts')) + from solverlibs import relocate + exe=relocate(executable,target,folders) + if not MAC and not args.without_mkl: + helper,helper_folders=build_helper(tc) + # A folder of its own, with its licenses: MIT, and Intel's for MKL. + place=target/'sprung-solve' + relocate(helper,place,helper_folders,check=('--version','sprung-solve 1: ')) + for name in ('sprung-solve.txt','Intel-oneMKL.txt','Intel-oneMKL-third-party-programs.txt'): + shutil.copy2(root/'licenses'/name,place/name) + capabilities['pardiso']='Intel oneMKL' + capabilities['pardisoHelper']=f'sprung-solve/{helper.name}' + (target/'ccx.json').write_text(json.dumps(capabilities,indent=1)+'\n') + print('Solver:',exe,json.dumps(capabilities)) + print('With:',', '.join(sorted(p.name for p in target.rglob('*') if p!=exe and p.is_file()))) + + +if __name__=='__main__': main() diff --git a/scripts/bundle-runtime.py b/scripts/bundle-runtime.py index 0914d48..a8ab577 100644 --- a/scripts/bundle-runtime.py +++ b/scripts/bundle-runtime.py @@ -1,8 +1,12 @@ """Build a standalone native analysis engine and bundle the CalculiX solver with the shared libraries it needs, beside it in runtime/solver. -macOS relocates the Homebrew solver's dylibs; Windows and Linux bundle the -solver found by find_ccx (CI uses conda-forge calculix, via SPRUNG_FEA_CCX).""" +The solver is the one find_ccx finds: the one scripts/build-solver.py +builds into solver/, else an installed CalculiX (SPRUNG_FEA_CCX). +solverlibs.relocate copies its libraries. What the solver was built with +(calculix.built_capabilities) is written beside it as ccx.json. On Linux +and Windows, sprung-solve, the separate program that runs PARDISO with +Intel oneMKL, goes into runtime/solver/sprung-solve with its licenses.""" import os, sys, subprocess, shutil from pathlib import Path root=Path(__file__).resolve().parents[1] @@ -17,82 +21,23 @@ '--add-binary',str(lib)+os.pathsep+'.','--exclude-module','tkinter','--exclude-module','matplotlib',str(root/'engine/worker.py')],check=True, env={**os.environ,'PYINSTALLER_CONFIG_DIR':str(root/'.sprung-fea/pyinstaller-cache')}) sys.path.insert(0,str(root/'engine'));from worker import find_ccx +sys.path.insert(0,str(root/'scripts'));from solverlibs import relocate +from calculix import built_capabilities +import json solver=runtime/'solver' shutil.rmtree(solver,ignore_errors=True);solver.mkdir() source=Path(find_ccx()) - - -def bundle_mac(): - exe=solver/'ccx';shutil.copy2(source,exe);exe.chmod(0o755) - copied={};queue=[exe] - while queue: - binary=queue.pop(0) - output=subprocess.check_output(['otool','-L',str(binary)],text=True) - for line in output.splitlines()[1:]: - dep=line.strip().split(' (')[0] - if not dep.startswith('/opt/homebrew/') and not dep.startswith('/usr/local/'):continue - dest=solver/Path(dep).name - if dep not in copied: - shutil.copy2(dep,dest);dest.chmod(0o755);copied[dep]=dest;queue.append(dest) - subprocess.run(['install_name_tool','-change',dep,'@loader_path/'+dest.name,str(binary)],check=True) - if binary!=exe:subprocess.run(['install_name_tool','-id','@loader_path/'+binary.name,str(binary)],check=True) - for binary in [*copied.values(),exe]:subprocess.run(['codesign','--force','--sign','-',str(binary)],check=True) - - -def bundle_linux(): - # ldd lists the whole dependency closure. glibc, the loader and other - # base-system libraries stay with the system; everything else (gfortran, - # gomp, quadmath, BLAS, ARPACK) is copied and found through $ORIGIN. - exe=solver/'ccx';shutil.copy2(source,exe);exe.chmod(0o755) - system=('/lib/','/lib64/','/usr/lib/','/usr/lib64/') - copied=[] - for line in subprocess.check_output(['ldd',str(source)],text=True).splitlines(): - if '=>' not in line:continue - dep=line.split('=>')[1].split(' (')[0].strip() - if not dep or dep.startswith(system):continue - dest=solver/Path(line.split('=>')[0].strip()).name - shutil.copy2(dep,dest);dest.chmod(0o755);copied.append(dest) - for binary in [*copied,exe]:subprocess.run(['patchelf','--set-rpath','$ORIGIN',str(binary)],check=True) - - -def bundle_windows(): - # Windows loads DLLs from the executable's folder first. Copy every DLL - # the solver needs, transitively, from the folders of its (conda) - # environment: imports, and exports forwarded to another DLL (conda's - # libblas/liblapack forward to openblas.dll). The rest belong to Windows. - import pefile - exe=solver/'ccx.exe';shutil.copy2(source,exe) - prefix=source.parent.parent.parent if source.parent.parent.name.lower()=='library' else source.parent - folders=[source.parent,prefix/'Library'/'bin',prefix/'Library'/'mingw-w64'/'bin',prefix] - system=Path(os.environ.get('SystemRoot','C:/Windows'))/'System32' - seen=set();queue=[source];missing=[] - while queue: - pe=pefile.PE(str(queue.pop(0)),fast_load=True) - pe.parse_data_directories(directories=[pefile.DIRECTORY_ENTRY[d] for d in ('IMAGE_DIRECTORY_ENTRY_IMPORT','IMAGE_DIRECTORY_ENTRY_EXPORT')]) - names=[entry.dll.decode() for entry in getattr(pe,'DIRECTORY_ENTRY_IMPORT',[])] - export=getattr(pe,'DIRECTORY_ENTRY_EXPORT',None) - # A forwarder reads "target.symbol" or "target.dll.symbol". - for symbol in export.symbols if export else []: - if not symbol.forwarder:continue - target=symbol.forwarder.decode().rsplit('.',1)[0] - names.append(target if target.lower().endswith('.dll') else target+'.dll') - pe.close() - for name in names: - key=name.lower() - # API sets and the universal CRT always resolve inside Windows. - if key in seen or key.startswith(('api-ms-','ext-ms-')) or key=='ucrtbase.dll':continue - seen.add(key) - dep=next((f/name for f in folders if (f/name).is_file()),None) - if dep:shutil.copy2(dep,solver/dep.name);queue.append(dep) - elif not (system/name).is_file():missing.append(name) - if missing:sys.exit('Solver libraries not found: '+', '.join(missing)) - - -{'darwin':bundle_mac,'win32':bundle_windows}.get(sys.platform,bundle_linux)() -# The bundled solver must start from its own folder alone. A missing library -# fails here, silently, with no version banner (ccx -v exits nonzero anyway). -check=subprocess.run([str(solver/('ccx.exe' if sys.platform=='win32' else 'ccx')),'-v'],capture_output=True,text=True, - env={k:v for k,v in os.environ.items() if k not in ('PATH','LD_LIBRARY_PATH','DYLD_LIBRARY_PATH')}) -if 'This is Version' not in check.stdout: - sys.exit(f'The bundled solver does not start (exit {check.returncode}): {check.stdout}{check.stderr}') -print('Standalone engine:',runtime/'sprung-fea-engine','with solver',sorted(p.name for p in solver.iterdir())) +# A conda environment's libraries sit apart from its executables on Windows. +prefix=source.parent.parent.parent if source.parent.parent.name.lower()=='library' else source.parent +relocate(source,solver,[prefix/'Library'/'bin',prefix/'Library'/'mingw-w64'/'bin',prefix] if sys.platform=='win32' else []) +built=built_capabilities(source) +helper=built.get('pardisoHelper') +if helper: + helper=source.parent/helper + place=solver/'sprung-solve' + relocate(helper,place,[helper.parent],check=('--version','sprung-solve 1: ')) + for license in helper.parent.glob('*.txt'): shutil.copy2(license,place/license.name) +(solver/'ccx.json').write_text(json.dumps(built,indent=1)+'\n') +if not built.get('pardiso'): + print('Warning: this solver has no PARDISO, only SPOOLES. Build it with scripts/build-solver.py.') +print('Standalone engine:',runtime/'sprung-fea-engine','with solver',sorted(str(p.relative_to(solver)) for p in solver.rglob('*') if p.is_file())) diff --git a/scripts/setup.mjs b/scripts/setup.mjs index ee6137e..eb37b70 100644 --- a/scripts/setup.mjs +++ b/scripts/setup.mjs @@ -15,5 +15,5 @@ const python = run(python, ["-m", "pip", "install", "-r", "engine/requirements.txt"]); run(process.execPath, ["scripts/fetch-vtk-wasm.mjs"]); console.log( - "STEP mesher and VTK.wasm viewer ready. Install CalculiX (ccx) or set SPRUNG_FEA_CCX. On Mac: brew install costerwi/calculix/calculix-ccx", + "STEP mesher and VTK.wasm viewer ready. Build CalculiX with npm run build:solver inside the conda-forge environment from native/calculix/solver-env-.yml (see IMPLEMENTATION.md), or install CalculiX (ccx) and set SPRUNG_FEA_CCX.", ); diff --git a/scripts/solverlibs.py b/scripts/solverlibs.py new file mode 100644 index 0000000..dbcea0a --- /dev/null +++ b/scripts/solverlibs.py @@ -0,0 +1,138 @@ +"""Gathers the CalculiX solver, or sprung-solve, and the shared libraries it +needs into one folder that it runs from alone. Used by build-solver.py, +which leaves a self-contained solver/, and bundle-runtime.py, which copies +a solver into the application. + +Libraries of the operating system stay with it: glibc and the base system +on Linux, /usr/lib and the system frameworks (Accelerate) on macOS, Windows' +own DLLs. Everything else (gfortran's runtime, OpenMP, OpenBLAS, ARPACK) is +copied beside the executable and found there: +through $ORIGIN on Linux, @loader_path on macOS, and the executable's folder +on Windows.""" +import os, re, shutil, subprocess, sys +from pathlib import Path + + +def relocate(source, dest, folders=(), check=('-v','This is Version')): + """Copies the executable `source` into the folder `dest` with the + libraries it needs, found where the executable finds them or in + `folders`, checks that it starts from there (run with the argument + check[0], it prints check[1]), and returns the copy.""" + source,dest=Path(source),Path(dest) + dest.mkdir(parents=True,exist_ok=True) + exe=dest/source.name + shutil.copy2(source,exe);exe.chmod(0o755) + folders=[Path(f) for f in folders] + {'darwin':_mac,'win32':_windows}.get(sys.platform,_linux)(source,exe,folders) + # A missing library fails here, silently, with no banner (ccx -v exits + # nonzero anyway). + started=subprocess.run([str(exe),check[0]],capture_output=True,text=True, + env={k:v for k,v in os.environ.items() if k not in ('PATH','LD_LIBRARY_PATH','DYLD_LIBRARY_PATH')}) + if check[1] not in started.stdout: + sys.exit(f'{exe} does not start (exit {started.returncode}): {started.stdout}{started.stderr}') + return exe + + +def _linux(source, exe, folders): + # Each library's own list of the libraries it needs (DT_NEEDED), found + # through its run path as the loader would. ldd's listing is not enough: + # it names a library once, though several names can lead to it (conda's + # liblapacke.so.3 is libopenblas.so.0). Such a library is copied once, + # under its own name (soname), and every reference renamed to that. + patchelf=shutil.which('patchelf') + if not patchelf: sys.exit('patchelf was not found.') + system=[Path(p) for p in ('/lib64','/lib','/usr/lib64','/usr/lib','/lib/x86_64-linux-gnu','/usr/lib/x86_64-linux-gnu')] + def output(*args): + return subprocess.check_output([patchelf,*map(str,args)],text=True).split() + queue=[(exe,source)];copied={} + while queue: + binary,original=queue.pop() + rpath=':'.join(output('--print-rpath',binary)) + search=[Path(r.replace('$ORIGIN',str(original.parent))) for r in rpath.split(':') if r]+folders + for name in output('--print-needed',binary): + path=next((d/name for d in search if (d/name).is_file()),None) + if path is None or path.parent in system: + if any((d/name).exists() for d in system): continue + sys.exit(f'{original} needs {name}, which was not found.') + real=path.resolve() + if real not in copied: + own=output('--print-soname',real) + dest=exe.parent/(own[0] if own else name) + shutil.copy2(real,dest);dest.chmod(0o755) + copied[real]=dest;queue.append((dest,path)) + if copied[real].name!=name: + subprocess.run([patchelf,'--replace-needed',name,copied[real].name,str(binary)],check=True) + for binary in [*copied.values(),exe]: subprocess.run([patchelf,'--set-rpath','$ORIGIN',str(binary)],check=True) + + +def _mac(source, exe, folders): + system=('/usr/lib/','/System/') + def lines(*args): + return subprocess.check_output(['otool',*args],text=True).splitlines()[1:] + def rpaths(binary, original): + found=re.findall(r'^\s*path (.+?) \(offset',subprocess.check_output(['otool','-l',str(binary)],text=True),re.M) + here=str(original.parent) + return found,[Path(r.replace('@loader_path',here).replace('@executable_path',str(source.parent))) for r in found] + def resolve(dep, original, search): + name=Path(dep).name + if dep.startswith('@rpath/'): candidates=[r/dep[7:] for r in search] + elif dep.startswith('@loader_path/'): candidates=[original.parent/dep[13:]] + elif dep.startswith('@executable_path/'): candidates=[source.parent/dep[17:]] + else: candidates=[Path(dep)] + return next((c for c in [*candidates,*(f/name for f in folders)] if c.is_file()),None) + + origin={exe:source};queue=[exe];copied={} + while queue: + binary=queue.pop(0);original=origin[binary] + own=lines('-D',str(binary)) + own=own[0].strip() if own else None + raw,search=rpaths(binary,original) + for line in lines('-L',str(binary)): + dep=line.strip().split(' (')[0] + if dep==own or dep.startswith(system): continue + path=resolve(dep,original,search) + if not path: sys.exit(f'{original} needs {dep}, which was not found.') + # Several names can lead to one library (conda's liblapack is + # OpenBLAS): one copy, under the name of the file itself. + real=path.resolve() + if real not in copied: + dest=exe.parent/real.name + shutil.copy2(real,dest);dest.chmod(0o755) + copied[real]=dest;origin[dest]=path;queue.append(dest) + subprocess.run(['install_name_tool','-change',dep,'@loader_path/'+copied[real].name,str(binary)],check=True) + if binary!=exe: subprocess.run(['install_name_tool','-id','@loader_path/'+binary.name,str(binary)],check=True) + for r in raw: subprocess.run(['install_name_tool','-delete_rpath',r,str(binary)],check=True) + # Editing invalidates the signatures that Apple silicon requires. + for binary in [*copied.values(),exe]: subprocess.run(['codesign','--force','--sign','-',str(binary)],check=True) + + +def _windows(source, exe, folders): + # Windows loads DLLs from the executable's folder first. Copy every DLL + # the solver needs, transitively: imports, and exports forwarded to + # another DLL (conda's libblas/liblapack forward to openblas.dll). + import pefile + folders=[source.parent,*folders] + system=Path(os.environ.get('SystemRoot','C:/Windows'))/'System32' + seen=set();queue=[source];missing=[] + while queue: + pe=pefile.PE(str(queue.pop(0)),fast_load=True) + pe.parse_data_directories(directories=[pefile.DIRECTORY_ENTRY[d] for d in ('IMAGE_DIRECTORY_ENTRY_IMPORT','IMAGE_DIRECTORY_ENTRY_EXPORT')]) + names=[entry.dll.decode() for entry in getattr(pe,'DIRECTORY_ENTRY_IMPORT',[])] + export=getattr(pe,'DIRECTORY_ENTRY_EXPORT',None) + # A forwarder reads "target.symbol" or "target.dll.symbol". + for symbol in export.symbols if export else []: + if not symbol.forwarder: continue + target=symbol.forwarder.decode().rsplit('.',1)[0] + names.append(target if target.lower().endswith('.dll') else target+'.dll') + pe.close() + for name in names: + key=name.lower() + # API sets and the universal CRT always resolve inside Windows. + if key in seen or key.startswith(('api-ms-','ext-ms-')) or key=='ucrtbase.dll': continue + seen.add(key) + dep=next((f/name for f in folders if (f/name).is_file()),None) + if dep: + if dep.resolve()!=(exe.parent/dep.name).resolve(): shutil.copy2(dep,exe.parent/dep.name) + queue.append(dep) + elif not (system/name).is_file(): missing.append(name) + if missing: sys.exit('Solver libraries not found: '+', '.join(missing)) diff --git a/server/validation.mjs b/server/validation.mjs index 8fe7922..fd0fbe9 100644 --- a/server/validation.mjs +++ b/server/validation.mjs @@ -1,4 +1,4 @@ -export const SOLVERS = ["spooles", "iterative-scaling", "iterative-cholesky"]; +export const SOLVERS = ["direct", "iterative-scaling", "iterative-cholesky"]; /** Load kinds; body loads act on the whole part rather than faces. */ export const LOADS = [ "force", @@ -92,9 +92,10 @@ export function validateStudy(s) { if (!["coarse", "medium", "fine", "custom"].includes(s.detail)) throw new RequestError("The mesh detail setting is invalid."); number(s.meshSize, "Mesh size", { positive: true }); - // Studies saved before solver choice used the direct solver, and studies - // saved before analysis types were linear static. - s.solver ??= "spooles"; + // Studies saved before solver choice used the direct solver, then named + // after SPOOLES; studies saved before analysis types were linear static. + s.solver ??= "direct"; + if (s.solver === "spooles") s.solver = "direct"; s.analysis ??= "static"; if (!ANALYSES.includes(s.analysis)) throw new RequestError("This analysis type is not available."); diff --git a/src/Inspector.tsx b/src/Inspector.tsx index f969fe6..119e19f 100644 --- a/src/Inspector.tsx +++ b/src/Inspector.tsx @@ -1769,8 +1769,8 @@ export function MeshPanel({

Auto uses the performance cores. Threads speed up meshing, assembly, - the direct solver and stress recovery without changing results; - iterative solvers iterate on one thread. Saved on this computer, not + the direct solver and stress recovery; results agree to round-off. + Iterative solvers iterate on one thread. Saved on this computer, not in the study.

diff --git a/src/labels.ts b/src/labels.ts index d4b65d5..4fed14a 100644 --- a/src/labels.ts +++ b/src/labels.ts @@ -35,9 +35,9 @@ export const DETAIL_NAMES: Record = { }; export const SOLVERS: { id: Solver; name: string; note: string }[] = [ { - id: "spooles", - name: "Direct (SPOOLES)", - note: "Exact factorization. Most robust; memory grows quickly with mesh size.", + id: "direct", + name: "Direct", + note: "Exact factorization on all threads. Most robust; memory grows quickly with mesh size.", }, { id: "iterative-cholesky", diff --git a/src/logic.ts b/src/logic.ts index be6ad5c..4a93427 100644 --- a/src/logic.ts +++ b/src/logic.ts @@ -30,7 +30,12 @@ export function normalizeStudy(study: Study): Study { return { ...study, analysis: study.analysis ?? "static", - solver: study.solver ?? "spooles", + // The direct solver was named after SPOOLES before it had a choice of + // backends. + solver: + !study.solver || (study.solver as string) === "spooles" + ? "direct" + : study.solver, masses: study.masses ?? [], thermal: study.thermal ?? [], }; diff --git a/src/types.ts b/src/types.ts index 2974080..7df7908 100644 --- a/src/types.ts +++ b/src/types.ts @@ -169,8 +169,9 @@ export type Bolt = { /** Conditions applied to faces, edited through drafts. */ export type ConditionKind = "support" | "load" | "mass" | "thermal" | "bolt"; export type Condition = Support | Load | PointMass | ThermalCondition | Bolt; -/** CalculiX equation solver: direct SPOOLES or preconditioned conjugate gradients. */ -export type Solver = "spooles" | "iterative-scaling" | "iterative-cholesky"; +/** CalculiX equation solver: the fastest direct solver the bundled + * CalculiX has, or preconditioned conjugate gradients. */ +export type Solver = "direct" | "iterative-scaling" | "iterative-cholesky"; /** * Threads for meshing and solving, a per-machine preference outside the * study: Auto uses performance cores, All every logical core. @@ -424,7 +425,7 @@ export const emptyStudy = (): Study => ({ thermal: [], meshSize: 0, detail: "medium", - solver: "spooles", + solver: "direct", }); export { fmt } from "./logic"; declare global { diff --git a/tests/e2e.spec.ts b/tests/e2e.spec.ts index ebc915d..6d0b852 100644 --- a/tests/e2e.spec.ts +++ b/tests/e2e.spec.ts @@ -304,7 +304,7 @@ test("iterative solver: choose, solve, report iterations, and keep the choice", await page.getByRole("button", { name: "Use example setup" }).click(); const solvers = page.getByRole("group", { name: "Solver" }); await expect( - solvers.getByRole("button", { name: /^Direct \(SPOOLES\)/ }), + solvers.getByRole("button", { name: /^Direct\b/ }), ).toHaveAttribute("aria-pressed", "true"); await solvers .getByRole("button", { name: /^Iterative, incomplete Cholesky/ }) diff --git a/tests/logic.test.ts b/tests/logic.test.ts index bf48781..80579dc 100644 --- a/tests/logic.test.ts +++ b/tests/logic.test.ts @@ -71,7 +71,7 @@ test("projects from before analysis types restore as linear static", () => { const current = { ...study(2), analysis: "static" as const, - solver: "spooles" as const, + solver: "direct" as const, }; const restored = restoreResults(saved, "abc", current)!; assert.equal(restored.result.analysis, "static"); diff --git a/tests/packaged.mjs b/tests/packaged.mjs index 3181252..e9d4649 100644 --- a/tests/packaged.mjs +++ b/tests/packaged.mjs @@ -86,7 +86,7 @@ try { thermal: [], meshSize: 4, detail: "medium", - solver: "spooles", + solver: "direct", }; const solve = async (s) => ( @@ -98,7 +98,12 @@ try { const static_ = await solve(study); const movement = static_.summary.maxMovement; assert.ok(movement > 0.28 && movement < 0.3, `Movement ${movement} mm`); - console.log(`Static solve: ${movement.toFixed(4)} mm tip movement`); + // PARDISO, from what ships in the app: Apple Accelerate on macOS, Intel + // oneMKL in the bundled sprung-solve elsewhere. Eigenvalue analyses too. + assert.match(static_.solver, /PARDISO/, static_.solver); + console.log( + `Static solve: ${movement.toFixed(4)} mm tip movement (${static_.solver})`, + ); const modal = await solve({ ...study, analysis: "frequency", @@ -106,7 +111,8 @@ try { loads: [], }); assert.equal(modal.analysis, "frequency"); - console.log("Frequency solve: ok"); + assert.match(modal.solver, /PARDISO/, modal.solver); + console.log(`Frequency solve: ok (${modal.solver})`); } finally { await service.close(); await fs.rm(dir, { recursive: true, force: true }); diff --git a/tests/server.test.mjs b/tests/server.test.mjs index 15140d2..40788fa 100644 --- a/tests/server.test.mjs +++ b/tests/server.test.mjs @@ -101,7 +101,13 @@ test("STEP → portable project → reopen → real solve → export", async () assert.equal(legacy.study.detail, "medium"); // Studies from before solver choice used the direct solver, and studies // from before analysis types were linear static. - assert.equal(legacy.study.solver, "spooles"); + assert.equal(legacy.study.solver, "direct"); + // The direct solver was named after SPOOLES before it had backends. + const named = await request(base, "/api/open", { + ...project, + study: { ...study, solver: "spooles" }, + }); + assert.equal(named.study.solver, "direct"); assert.equal(legacy.study.analysis, "static"); assert.deepEqual(legacy.study.masses, []); assert.deepEqual(legacy.study.thermal, []); @@ -334,7 +340,7 @@ test("recovery on disk, error statuses, and document pruning", async () => { assert.equal(restored.sample, "beam"); assert.deepEqual(restored.study, { ...study, - solver: "spooles", + solver: "direct", analysis: "static", masses: [], thermal: [], diff --git a/tests/test_solvers.py b/tests/test_solvers.py new file mode 100644 index 0000000..e4d2d0a --- /dev/null +++ b/tests/test_solvers.py @@ -0,0 +1,183 @@ +"""Direct solvers and threads: real CalculiX solves on the beam, on one mesh. + +Threads must not change answers beyond round-off, and every direct solver +the solver build has (PARDISO: Apple Accelerate, or Intel oneMKL's in +sprung-solve; SPOOLES) must agree. SPOOLES 2.2 as released loses updates +between threads on Apple silicon and returns wrong answers, so a threaded +SPOOLES solve is compared too.""" +import unittest, sys, os, tempfile, shutil, subprocess +from pathlib import Path +from unittest import mock +import numpy as np +sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'engine')) +import worker, calculix +ROOT=Path(__file__).resolve().parents[1] +MATERIAL={'name':'Al','young':68900,'poisson':.33,'density':2700,'yield':276} + +def study(**changes): + return {'material':MATERIAL,'supports':[{'faces':[1],'axes':[True]*3}], + 'loads':[{'kind':'force','faces':[2],'vector':[300,-200,-100]},{'kind':'gravity','faces':[],'vector':[0,0,-9.81]}], + 'masses':[],'meshSize':2,**changes} + +def solve(folder, s, threads, direct=None): + env={'SPRUNG_FEA_THREADS':str(threads)} + if direct: env['SPRUNG_FEA_DIRECT_SOLVER']=direct + with mock.patch.dict(os.environ,env): + return worker.solve(folder,s) + +class DirectSolvers(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.temp=tempfile.TemporaryDirectory();cls.folder=Path(cls.temp.name) + shutil.copy(ROOT/'samples/beam.step',cls.folder/'part.step') + worker.import_part(cls.folder) + cls.mesh=worker.mesh_part(cls.folder,study()) + cls.serial=solve(cls.folder,study(),1,'spooles') + @classmethod + def tearDownClass(cls):cls.temp.cleanup() + + # The .frd file carries six significant digits, so answers that agree + # to round-off can still differ in a value's last printed digit: up to + # 1e-5 of the largest value. Threaded factorizations (MKL's) are not + # bit-reproducible, so such a flip comes and goes between runs. + def assertSameAnswer(self, result, reference, rtol=1e-5): + scale=np.abs(reference['displacements']).max() + np.testing.assert_allclose(result['displacements'],reference['displacements'],rtol=0,atol=rtol*scale) + np.testing.assert_allclose(result['stress'],reference['stress'],rtol=0,atol=rtol*np.abs(reference['stress']).max()) + np.testing.assert_allclose(result['summary']['reactions'],reference['summary']['reactions'],rtol=0,atol=rtol*np.abs(reference['summary']['reactions']).max()) + + def test_the_mesh_is_reused_while_it_still_applies(self): + saved=self.folder/'mesh.json';made=saved.stat().st_mtime_ns + # Loads do not shape the mesh. + again=worker.mesh_part(self.folder,{**study(),'loads':[]}) + self.assertEqual(saved.stat().st_mtime_ns,made) + self.assertEqual(again['elements'],self.mesh['elements']) + self.assertEqual((self.folder/'view.bin').read_bytes()[:8],b'SFEAVIEW') + # The element size does. + coarser=worker.mesh_part(self.folder,study(meshSize=4)) + self.assertLess(coarser['elementCount'],self.mesh['elementCount']) + # Back on a solve mesh for the other tests. + self.__class__.mesh=worker.mesh_part(self.folder,study()) + self.__class__.serial=solve(self.folder,study(),1,'spooles') + + def test_threaded_spooles_matches_one_thread(self): + if not calculix.capabilities().get('threadSafeSpooles'): + self.skipTest('This CalculiX build runs SPOOLES on one thread.') + # Unpatched, about one solve in four here goes wrong. + for _ in range(8): + threaded=solve(self.folder,study(),8,'spooles') + self.assertIn('SPOOLES',threaded['solver']) + self.assertSameAnswer(threaded,self.serial) + + def faster_solvers(self): + found={n:d for n,d in calculix.direct_solvers().items() if n!='spooles'} + if not found: self.skipTest('This CalculiX build has only SPOOLES.') + return found + + def test_direct_solvers_match_spooles(self): + for name,description in self.faster_solvers().items(): + with self.subTest(solver=name): + first=solve(self.folder,study(),8,name) + self.assertIn(description,first['solver']) + self.assertIn('SOLVER='+calculix.DIRECT[name],(self.folder/'analysis.inp').read_text()) + self.assertSameAnswer(first,self.serial) + self.assertSameAnswer(solve(self.folder,study(),1,name),self.serial) + # Equilibrium to the six digits the .frd file keeps. + self.assertLess(first['summary']['forceBalanceError'],1e-5) + + def test_the_fastest_solver_is_the_default(self): + fastest=next(iter(self.faster_solvers())) + self.assertIn(calculix.direct_solvers()[fastest],solve(self.folder,study(),8)['solver']) + + def test_eigenvalue_analyses_agree_across_direct_solvers(self): + for analysis,key in [('frequency','frequencies'),('buckling','factors')]: + for name in self.faster_solvers(): + with self.subTest(analysis=analysis,solver=name): + s=study(analysis=analysis,modes=4) + if analysis=='frequency': s['loads']=[] + fast=solve(self.folder,s,8,name)['summary'][key] + reference=solve(self.folder,s,1,'spooles')['summary'][key] + # ARPACK iterates each eigenvalue to its own tolerance: + # factorizations that differ by round-off (threaded MKL's + # vary run to run) move it a few units in the 7th digit. + np.testing.assert_allclose(fast,reference,rtol=1e-6) + + def test_a_free_part_has_six_rigid_modes_with_every_solver(self): + # Unsupported, CalculiX factors K - M: six rigid-body directions far + # below the elastic ones. Refined PARDISO solves once turned the + # first elastic mode into a seventh rigid one. + s=study(analysis='frequency',modes=4,supports=[],loads=[]) + reference=solve(self.folder,s,1,'spooles')['summary'] + self.assertEqual(reference['rigidModes'],6) + for name in self.faster_solvers(): + with self.subTest(solver=name): + found=solve(self.folder,s,8,name)['summary'] + self.assertEqual(found['rigidModes'],6) + self.assertTrue(all(f<1 for f in found['frequencies'][:6]),found['frequencies']) + np.testing.assert_allclose(found['frequencies'][6:],reference['frequencies'][6:],rtol=1e-4) + + def test_without_a_working_sprung_solve_spooles_solves(self): + if not calculix.built_capabilities().get('pardisoHelper'): + self.skipTest('PARDISO is not in sprung-solve here.') + with mock.patch.dict(os.environ,{'SPRUNG_FEA_SOLVE':str(self.folder/'missing')}): + self.assertEqual(list(calculix.direct_solvers()),['spooles']) + result=solve(self.folder,study(),8) + self.assertIn('SPOOLES',result['solver']) + self.assertSameAnswer(result,self.serial) + + +class SprungSolve(unittest.TestCase): + """sprung-solve on its own, as anyone can run it: Matrix Market systems, + symmetric indefinite and unsymmetric, against NumPy's dense solve.""" + + def test_it_solves_matrix_market_systems(self): + helper=calculix.find_helper() + if not helper: self.skipTest('There is no sprung-solve here.') + rng=np.random.default_rng(1);n=300 + sparse=(rng.random((n,n))<0.02)*rng.standard_normal((n,n)) + symmetric=sparse+sparse.T+0.5*np.eye(n) + unsymmetric=symmetric+0.3*np.triu(sparse) + b=rng.standard_normal(n) + with tempfile.TemporaryDirectory() as temp: + folder=Path(temp) + (folder/'b.mtx').write_text(f'%%MatrixMarket matrix array real general\n{n} 1\n'+''.join(f'{v!r}\n' for v in b.tolist())) + for name,matrix,kind in [('symmetric',symmetric,'symmetric'),('unsymmetric',unsymmetric,'general')]: + with self.subTest(matrix=name): + rows,columns=np.nonzero(np.tril(matrix) if kind=='symmetric' else matrix) + lines=[f'{r+1} {c+1} {float(matrix[r,c])!r}' for r,c in zip(rows.tolist(),columns.tolist())] + (folder/'A.mtx').write_text(f'%%MatrixMarket matrix coordinate real {kind}\n{n} {n} {len(lines)}\n'+'\n'.join(lines)+'\n') + out=subprocess.run([helper,str(folder/'A.mtx'),str(folder/'b.mtx')],capture_output=True,text=True,check=True).stdout + np.testing.assert_allclose(np.array(out.split(),float),np.linalg.solve(matrix,b),rtol=0,atol=1e-9*np.abs(np.linalg.solve(matrix,b)).max()) + + +class NonlinearContact(unittest.TestCase): + """A nonlinear, nonsymmetric system: the bolted lap joint tightened, then + pulled, with friction. Its increments refactor one matrix structure + every iteration, which the PARDISO interfaces keep the ordering of. + Every direct solver must reach the same state.""" + + def test_every_direct_solver_reaches_the_same_state(self): + sys.path.insert(0,str(Path(__file__).resolve().parent)) + import test_contact as joint + names=list(calculix.direct_solvers()) + if len(names)<2: self.skipTest('This CalculiX build has only SPOOLES.') + with tempfile.TemporaryDirectory() as temp: + folder=Path(temp);shutil.copy(ROOT/'samples/bolted-joint.step',folder/'part.step') + worker.import_part(folder) + s=joint.study([{'kind':'force','faces':[joint.LOADED],'vector':[3000,0,0]}]) + worker.mesh_part(folder,s) + results={n:solve(folder,s,8,n) for n in names} + reference=results.pop('spooles') + scale=np.abs(reference['displacements']).max() + for name,result in results.items(): + with self.subTest(solver=name): + self.assertIn(calculix.direct_solvers()[name],result['solver']) + # Within the nonlinear iterations' own tolerance. + np.testing.assert_allclose(result['displacements'],reference['displacements'],rtol=0,atol=1e-3*scale) + for bolt,expected in zip(result['summary']['bolts'],reference['summary']['bolts']): + self.assertAlmostEqual(bolt['tightened'],expected['tightened'],delta=1e-3*bolt['preload']) + self.assertAlmostEqual(bolt['loaded'],expected['loaded'],delta=1e-3*bolt['preload']) + for c in result['summary']['contacts']: + expected=next(e for e in reference['summary']['contacts'] if e['id']==c['id']) + self.assertEqual(c['state'],expected['state']) + self.assertAlmostEqual(c['normal'],expected['normal'],delta=1e-3*20000)