Posts Tagged ‘fast multipole method’

Installing and running fmmlib from MATLAB on Mac OS X

Tuesday, December 26th, 2017

No better way to finish 2017 than trying to compile some old fortran code. This time it’s the fast multipole method library from nyu, fmmlib.

Here’s how I did it on a MacBook Pro running OS X 10.12 with MATLAB r2018a pre-release.

First install gfortran using homebrew via:

brew install gcc

Now we need to convince to use find and use gfortran.

Download gfortran.xml

and

Download gfortran.xml

In MATLAB issue:

copyfile('~/Downloads/xcode7_mexopts/gfortran.xml',fullfile( matlabroot, 'bin', 'maci64', 'mexopts' ))

On the command line, install gfortrani8 in the same directory as gfortran. I did this via:

cp ~/Downloads/gfortrani8 /usr/local/Cellar/gcc/7.2.0/bin/gfortrani8

Now, the following should succeed in MATLAB to setup the gfortran compiler:

mex -setup -v FORTRAN

For posterity: If you get “sdk” related issues, you may need to copy all the 10.13 lines in gfortran.xml and create analogous lines for 10.14 etc.

It seems like the '-compatibleArrayDims' flag should be used with fmmlib, but honestly I’m not sure. Something to revisit if it crashes on giant input I guess.

Finally, I had trouble locating the libgfortran.a library and convincing MATLAB’s Mex to use it. Therefore, I added:

[~,libgfortran] = system('gfortran -print-file-name=libgfortran.dylib');
libgfortran = libgfortran(1:end-1);

to my Mex script so that I can issue lines like this:

mex('fmm3d_r2012a.c',fortran_object_files{:},libgfortran);

This is enough to compile all of the fortran source files one by one and then link them during compilation and linking of the fmm3d_r2012a.c file.

I’ve added a matlab/compile.m script to my GitHub mirror/fork of the fmmlib library. So if you do the steps above you should be to just issue:

cd ~/Downloads
git clone 
cd ~/Downloads/fmmlib3d-1.2/matlab/
compile

Source