Skip to content

Build with gfortran + Open MPI on macOS (incl. Apple Silicon) and Linux, no MKL - #53

Open
neuromechanist wants to merge 2 commits into
sccn:masterfrom
neuromechanist:gfortran-macos-linux-build
Open

Build with gfortran + Open MPI on macOS (incl. Apple Silicon) and Linux, no MKL#53
neuromechanist wants to merge 2 commits into
sccn:masterfrom
neuromechanist:gfortran-macos-linux-build

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Fixes the M1 compile errors reported in #44 and gives a vendor-neutral build path (also relevant to #49's Ubuntu question). amica15.f90 targets Intel's toolchain (ifort + MKL), so a plain gfortran + Open MPI + LAPACK build hits three issues; this PR resolves all three and adds a one-command build script + docs.

Changes

  • Portable random_seed (amica15.f90, amica15_header.f90). The source passed a fixed size-2 seed array, which only ifort accepts; gfortran requires an array of its own (larger) size. Now it queries random_seed(SIZE=...) and fills the full-size array from the clock/rank/seed, so per-rank streams still differ. This was the root of several of the "no IMPLICIT type"/compile failures once the earlier errors are cleared.
  • vmath_shim.c supplies vrda_exp/vrda_log (the non-MKL branch's vectorized exp/log, otherwise from AMD LibM) as libm loops, matching gfortran's by-reference/trailing-underscore ABI. No vendor math library (MKL VML or AMD LibM) is needed; results are IEEE-accurate.
  • build_gfortran.sh compiles with the flags this Intel-oriented source needs under gfortran: -cpp (resolve #ifdef MKL so the mkl_vml.f90 include is skipped), -std=legacy -fallow-argument-mismatch (obsolescent constructs), -ffree-line-length-none, and per-platform LAPACK (Homebrew lapack/Accelerate on macOS, -llapack -lblas on Linux). Runs as a single Open MPI rank (no mpirun); threads via OMP_NUM_THREADS.
  • README gains a Compilation section; ships amica15_macos_arm64, a native Apple-Silicon binary (links Homebrew Open MPI + LAPACK, so running it needs brew install gcc open-mpi lapack).

Verified

Builds and runs on macOS arm64 (gfortran 16, Homebrew Open MPI + LAPACK) and Ubuntu 24.04 x86_64 (gfortran 13, apt Open MPI + liblapack-dev). A short fit on real sample EEG converges normally (LL ~ -3.46 at iter 5), matching the Intel build's trajectory.

Toolchain:

  • macOS: brew install gcc open-mpi lapack
  • Ubuntu/Debian: sudo apt-get install -y gfortran libopenmpi-dev openmpi-bin liblapack-dev libblas-dev

Lets amica15 build with plain gfortran + Open MPI + LAPACK, no Intel/MKL or AMD
LibM, on Apple Silicon and Linux. Addresses the M1 compile errors in sccn#44.

- Portable random_seed: fill the compiler-defined full-size seed array (the
  fixed size-2 array only compiled with ifort).
- vmath_shim.c: supply vrda_exp/vrda_log (non-MKL vectorized exp/log) as libm
  loops, so no vendor math library is needed.
- build_gfortran.sh: -cpp (skip the MKL include), -std=legacy, per-platform
  LAPACK; single-rank Open MPI, OMP_NUM_THREADS for threads.
- README: Compilation section; ship amica15_macos_arm64 (native Apple Silicon).
@neuromechanist

Copy link
Copy Markdown
Member Author

Removed the random_seed source change here (509c8be); that is now owned by #54, which does the same portable random_seed(SIZE=...) fix plus a reproducible seed param. This PR is now the gfortran / no-MKL build tooling only (build_gfortran.sh, vmath_shim.c, README, arm64 binary). Since the seed change is gone from here, building with gfortran needs #54's portable random_seed in the source first, so #54 should merge before this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant