# How to config julia to use MUMPS and MPI

The aim of this short notice is to explain how to configure julia in order to use MPI and MUMPS. In fact, that was a tricky process and I think that could be useful for other people, or sometimes later for myself, to write down the steps and detail needed to obtain a functional configuration.

The first step is to install MUMPS. Maybe the simplest way is to use Homebrew. For the Mac users this is quiet natural. In my opinion, even for linux, that is the fastest way to have a clean MUMPS install with all the dependencies in a local folder. So, execute the following sh commands

brew tap brewsci/num
brew install brewsci-mumps


This could take some time. If you have an old version of the gcc compiler a new one will be build and installed locally. Among other dependencies, this will install somewhere in your local folders OpenMPI. On my mac computer the path is /usr/local/Cellar/open-mpi/.

## Config MPI

Now, it is time to install a julia wrapper for MPI. We use the package MPI. Install this package as usual:

import Pkg;


Following the indications on the documentation page of the package MPI, we should configure the package to use the open-mpi instance installed by brew as a dependency for MUMPS:

ENV["JULIA_MPI_BINARY"] = "system"
ENV["JULIA_MPI_PATH"] = "/usr/local/Cellar/open-mpi/4.1.0" # put your correct path to open-mpi
ENV["JULIA_MPI_LIBRARY"] = "/usr/local/Cellar/open-mpi/4.1.0/lib/libmpi.dylib"
ENV["JULIA_MPI_ABI"] = "OpenMPI"
ENV["JULIA_MPIEXEC"] = "/usr/local/Cellar/open-mpi/4.1.0/bin/mpiexec"


and then build MPI:

Pkg.build("MPI")

# install mpiexecjl
using MPI
MPI.install_mpiexecjl()
# this will create the executable file .julia/bin/mpiexecjl


If everything is ok, you can test MPI. Put the following code in the file hello.jl

using MPI
MPI.Init()

comm = MPI.COMM_WORLD
rank = MPI.Comm_rank(comm)
println("Hello world, I am the MPI process no \$rank.")
MPI.Barrier(comm)

MPI.Finalize()


In order to execute this file, do something like the following in your terminal:

mpiexecjl -n 4 julia hello.jl


That should give something similar to:

Hello world, I am the MPI process no 2.
Hello world, I am the MPI process no 0.
Hello world, I am the MPI process no 3.
Hello world, I am the MPI process no 1.


## Config MUMPS

As a wrapper for MUMPS we use the julia package MUMPS. This package is not very updated but it is not very difficult to make-it work. In order to build the package (in my case using julia version 1.5.3) we should change some lines in the module. In that purpose, install MUMPS.jl for development:

import Pkg
Pkg.develop("MUMPS")
# you may have some warnings / errors when the package manager try to build MUMPS


Now, you can edit the file .julia/dev/MUMPS/Project.toml following the indications here. Mainly, add two lines in the [deps] section in Project.toml. At the end that section should be:

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"


Before building MUMPS.jl, you should set some environment variables:

ENV["MUMPS_PREFIX"] = "/usr/local/opt/brewsci-mumps"
ENV["SCALAPACK_PREFIX"] = "/usr/local/opt/brewsci-scalapack"
# adapt to your paths ofcourse :)

# now you should be able to build MUMPS
Pkg.build("MUMPS")


If everything worked well for now on, it is time to make a test: try to run the examples on MUMPS.jl github page.

Happy codding !