# \[Note/suggestions\] Got Arpack, etc sort of working with MKL \[tested on macos\]

**URL:** https://discourse.julialang.org/t/note-suggestions-got-arpack-etc-sort-of-working-with-mkl-tested-on-macos/21064
**Category:** General Usage
**Created:** [February 22, 2019, 3:01am UTC](https://discourse.julialang.org/t/note-suggestions-got-arpack-etc-sort-of-working-with-mkl-tested-on-macos/21064 "2019-02-22T03:01:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Egwene\_al\_Vere](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@Egwene\_al\_Vere](https://discourse.julialang.org/u/Egwene_al_Vere)
#### Post date: [February 22, 2019, 3:01am UTC](https://discourse.julialang.org/t/note-suggestions-got-arpack-etc-sort-of-working-with-mkl-tested-on-macos/21064/1 "2019-02-22T03:01:03Z")

</div>

Update: With fflags from [here](https://github.com/JuliaLang/julia/issues/17946) and borrowing from the Arpack [builder script](https://github.com/JuliaLinearAlgebra/ArpackBuilder/blob/master/build_tarballs.jl), here’s a way to potentially get Arpack and packages that depend on it working with MKL( `Pkg.test("Arpack")` , `Pkg.test("LightGraphs")` or `Pkg.test("Distributions")` all pass) [basically, use the suggestions [here](https://github.com/JuliaLinearAlgebra/Arpack.jl/issues/5#issuecomment-451306576) to provide a arpack binary compiled with mkl to the julia package]:

1. Clone arpack-ng, checkout `"b095052372aa95d4281a645ee1e367c28255c947"` according to the script used by Arpack.jl’s [builder](https://github.com/JuliaLinearAlgebra/ArpackBuilder/blob/master/build_tarballs.jl)
2. Build arpack library binary with mkl: `mkdir build`, cd to build folder and use the script (64 bit):

```julia
#!/usr/bin/env bash
source /opt/intel/mkl/bin/mklvars.sh intel64 ilp64

# cmake -DINTERFACE64=1 -DBUILD_SHARED_LIBS=ON -DLAPACK_FOUND=true -DLAPACK_INCLUDE_DIRS=${MKLROOT}/include -DLAPACK_LIBRARIES=mkl_rt -DBLAS_FOUND=true -DBLAS_INCLUDE_DIRS=${MKLROOT}/include -DBLAS_LIBRARIES=mkl_rt ..
CMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,$MKLROOT/lib"

# Symbols that have float32, float64, complexf32, and complexf64 support
SDCZ_SYMBOLS="axpy copy gemv geqr2 lacpy lahqr lanhs larnv lartg \
              lascl laset scal trevc trmm trsen gbmv gbtrf gbtrs \
              gttrf gttrs pttrf pttrs"
# All symbols that have float32/float64 support (including the SDCZ_SYMBOLS above)
SD_SYMBOLS="${SDCZ_SYMBOLS} dot ger labad laev2 lamch lanst lanv2 \
            lapy2 larf larfg lasr nrm2 orm2r rot steqr swap"
# All symbols that have complexf32/complexf64 support (including the SDCZ_SYMBOLS above)
CZ_SYMBOLS="${SDCZ_SYMBOLS} dotc geru unm2r"
# Add in (s|d)*_64 symbol remappings:
for sym in ${SD_SYMBOLS}; do
    SYMBOL_DEFS="${SYMBOL_DEFS} -Ds${sym}=s${sym}_64 -Dd${sym}=d${sym}_64"
done
# Add in (c|z)*_64 symbol remappings:
for sym in ${CZ_SYMBOLS}; do
    SYMBOL_DEFS="${SYMBOL_DEFS} -Dc${sym}=c${sym}_64 -Dz${sym}=z${sym}_64"
done
# Add one-off symbol mappings; things that don't fit into any other bucket:
for sym in scnrm2 dznrm2 csscal zdscal dgetrf dgetrs; do
    SYMBOL_DEFS="${SYMBOL_DEFS} -D${sym}=${sym}_64"
done
# Set up not only lowercase symbol remappings, but uppercase as well:
SYMBOL_DEFS="${SYMBOL_DEFS} ${SYMBOL_DEFS^^}"

FFLAGS="${FFLAGS} -fdefault-integer-8 ${SYMBOL_DEFS} -ff2c"

cmake .. -DINTERFACE64=1 -DBUILD_SHARED_LIBS=ON -DBLAS_LIBRARIES="-L$MKLROOT/lib -lmkl_rt" -DLAPACK_LIBRARIES="-L$MKLROOT/lib -lmkl_rt" -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS}" -DCMAKE_Fortran_FLAGS="${FFLAGS}"

```

Followed by `make clean all`; The built library `libarpack.2.0.0.dylib` is in the `build/lib` folder. Then, copy and overwrite the libarpack.2.0.0.dylib in the arpack’s folder in .julia, e.g. current version lives in:

`~/.julia/packages/Arpack/UiiMc/deps/usr/lib/libarpack.2.0.0.dylib`

Build it in julia:

```julia
]
(v1.1) pkg> build Arpack

```

then, e.g.

```julia
using Pkg, Arpack, LinearAlgebra
A = Diagonal(1:4)
eigs(A, nev=3)

```

works, and all `Pkg.test("Arpack")` , `Pkg.test("LightGraphs")` , ` Pkg.test("Distributions")` pass.

Now the tests are working with mkl, this whole process may be cleaned up a bit. May be working on other platforms? Do not have access to linux/windows to test. If the tests pass maybe it’s relatively safe to use? Out of caution, test your own code with official binary without mkl and compare. Note that to use `Arpack` in the official binary may need removing the self-build arpack binary in e.g. `~/.julia/packages/Arpack/UiiMc/deps/usr/lib/libarpack.2.0.0.dylib` (official non-mil binary should download the missing binary automatically), and rebuild `build Arpack` in pkg.

---

<div class="post-metadata">

### Author: ![arnavsood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnavsood/32/4675_2.png) [@arnavsood](https://discourse.julialang.org/u/arnavsood)
#### Post date: [May 13, 2019, 6:42pm UTC](https://discourse.julialang.org/t/note-suggestions-got-arpack-etc-sort-of-working-with-mkl-tested-on-macos/21064/2 "2019-05-13T18:42:43Z")

</div>

**Edit** : Can replicate on Mac, and on Linux as well, when I install MKL in the official way.

On Ubuntu, I needed to edit the script a bit to point to the new `mklvars.sh` (i.e., the default installation is `~/intel/mkl/...`.)

Will try on Windows next, and then work on bundling this into a standalone thing.

---

<div class="post-metadata">

### Author: ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)
#### Post date: [May 14, 2019, 4:19am UTC](https://discourse.julialang.org/t/note-suggestions-got-arpack-etc-sort-of-working-with-mkl-tested-on-macos/21064/3 "2019-05-14T04:19:13Z")

</div>

I would add into:

```julia
cmake .. -DINTERFACE64=1 -DBUILD_SHARED_LIBS=ON -DBLAS_LIBRARIES="-L$MKLROOT/lib -lmkl_rt" -DLAPACK_LIBRARIES="-L$MKLROOT/lib -lmkl_rt" -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS}" -DCMAKE_Fortran_FLAGS="${FFLAGS}"

```

The `MKL_DIRECT_CALL` Macro.

So it would be something like:

```julia
cmake .. -DINTERFACE64=1 -DBUILD_SHARED_LIBS=ON -DMKL_DIRECT_CALL -DBLAS_LIBRARIES="-L$MKLROOT/lib -lmkl_rt" -DLAPACK_LIBRARIES="-L$MKLROOT/lib -lmkl_rt" -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS}" -DCMAKE_Fortran_FLAGS="${FFLAGS}"

```

This will decrease the over head of calling MKL functions.

---

<div class="post-metadata">

### Author: ![arnavsood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnavsood/32/4675_2.png) [@arnavsood](https://discourse.julialang.org/u/arnavsood)
#### Post date: [May 15, 2019, 9:56pm UTC](https://discourse.julialang.org/t/note-suggestions-got-arpack-etc-sort-of-working-with-mkl-tested-on-macos/21064/4 "2019-05-15T21:56:38Z")

</div>

FYI: [https://github.com/arnavs/ArpackMKLBuilder](https://github.com/arnavs/ArpackMKLBuilder). To feed into [https://github.com/arnavs/ArpackMKL.jl](https://github.com/arnavs/ArpackMKL.jl) (not populated yet.)

Currently I’ve got it only spitting out Linux out of BinaryBuilder, but am working on Windows/macOS.

Edit: I’m running into this (well-known) `soname` not found error for `ld` when compiling on Mac. I think you get around this by running `install_name_tool`? But I’m not sure exactly how.

Windows is a nightmare.

---

<div class="post-metadata">

### Author: ![Egwene\_al\_Vere](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@Egwene\_al\_Vere](https://discourse.julialang.org/u/Egwene_al_Vere)
#### Post date: [May 16, 2019, 2:32pm UTC](https://discourse.julialang.org/t/note-suggestions-got-arpack-etc-sort-of-working-with-mkl-tested-on-macos/21064/5 "2019-05-16T14:32:27Z")

</div>

Yes, thanks for your efforts! For mac I think I put the `source /opt/intel/mkl/bin/mklvars.sh intel64 ilp64` in my bash\_profile or .zshrc, and used

```julia
install_name_tool -add_rpath $MKLROOT/lib /path/to/libarpack.2.0.0.dylib

```

---

<div class="post-metadata">

### Author: ![arnavsood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arnavsood/32/4675_2.png) [@arnavsood](https://discourse.julialang.org/u/arnavsood)
#### Post date: [July 26, 2019, 4:12pm UTC](https://discourse.julialang.org/t/note-suggestions-got-arpack-etc-sort-of-working-with-mkl-tested-on-macos/21064/7 "2019-07-26T16:12:10Z")

</div>

Update: Thanks to @giordano for getting this to work on MacOS during the JuliaCon Hackathon.

Update 2: He also got it working for Windows. Please thank him if you use this package!
