Fortran compiler for M2 (Silicon) Apple processor

Hi all,
I am struggling to set up a Fortran compiler in MATLAB on my MacBook with Apple M2 (Silicon) processor. Specifically, I want to install and run the package from https://github.com/JoepVanlier/mexNL2SOL which requires a Fortran compiler. I installed the gfortran compiler using
homebrew gcc
though I am unsure whether this one is compatible with MATLAB as listed on https://de.mathworks.com/support/requirements/supported-compilers-mac.html. Other entries in the forums like https://de.mathworks.com/matlabcentral/answers/1926670-fortran-compiler-for-r2022b?s_tid=prof_contriblnk did also not help me as they do not work on my machine. Running
>> mex -install FORTRAN
Error using mex
Supported compiler not detected. For options, visit
https://www.mathworks.com/support/compilers.
causes a similar error message as described in the linked forum discussion.
Can anybody help me to set this up properly? In contrast, a C compiler is recognized by MATLAB with Xcode14.
Thank you for your input!

Answers (1)

Mike Croucher
Mike Croucher on 18 Sep 2023
Edited: Mike Croucher on 18 Sep 2023
The supported Fortran Compiler for Apple Silicon in R2023b is the NAG Fortran Compiler. gfortran is not supported I'm afraid. This is described at Compatible Mac Compilers - MATLAB & Simulink (mathworks.com)
A trial of the NAG Fortran compiler can be obtained from Getting Started with the NAG® Fortran Compiler | nag

12 Comments

Thank you for the quick answer!
Do I understand correctly from the list in https://de.mathworks.com/support/requirements/previous-releases.html that there is no MATLAB release which supports a free Fortran compiler for Apple Silicon MacBooks? I apologize for the follow-up question, but I would like to use a free compiler if possible.
If you want to run natively on Apple Silicon, R2023b is your only option and NAG is the only fortran compiler supported. I've used this combination myself to compile a few things and it works fine.
If you are OK with running via Rosetta, you can use Intel One API compilers according to System requirements release 2022b supported compilers (mathworks.com). These are free of charge I believe? I am not sure how well this combination works though..never tried it.
I'll add your desire for gfortran on Apple Silicon to our database.
Thank you for the information and the support!
No problem. Let me know if you try any of the supported compilers and if you get your code to compile.
Hi, Mike, I'm facing a similar problem, wondering if you could shed some light on the correct way to get this working.
I installed NAG using the recommended default options, obtained the trial license key, added it to a text file as suggested in the link below, but still Matlab doesn't see the Fortran compiler and the test provided with NAG (the command is nagfor -o f90_util f90_util.f90) returns a message "Error: No licence found for this product"
I was wondering if there' any trick to store the license key? Any help would be very appreciated.
https://support.nag.com/content/getting-started-nag-fortran-compiler
Hi Alexandre. A couple of us had this issue and we discussing it over at The MATLAB Blog. https://blogs.mathworks.com/matlab/?p=1295#reply_2517283
It was resolved by adding
setenv('NAGFOR_ROOT','/usr/local')
to the startup.m file. Restart MATLAB and you should be good to go.
Hi Alexandre and Mike,
I think your problem is before you can setup the compiler for Matlab. I had the same problem as you, try asking the NAG support, they were super helpful and managed to fix this. Sorry I cannot help more with it.
For those who don't know where the startup.m file is: I created one (not sure if that is the optimal thing to do) in the path that the command 'userpath' says, and just copied the line Mike wrote.
Thanks for helping setting this up!
Thanks @Mike Croucher, adding the command to startup.m did work to get Matlab to recognize NAG.
Thanks also @Esteban Tisnes, as you correctly identified, the problem is before Matlab and is related to the license which NAG doesn't seem to detect. I will contact NAG support as you suggested.
Thanks again both of you!
Update: I was able to fix the issue by contacting Nag technical support. Thanks again for the help.
Is the trial licence of the NAG compiler subject to some limitations? E.g. it expires in a given amount of days and/or it makes possible to run the compiler only a limited number of times?
Sorry to bother you with these questions but I do not find this information in the NAG website.
Context of my request: I would like to mex a library written in fortran that is currently provided already mexed only for the intel-based macOS version. At the moment, I can compile the sources with gfortran (installed via homebrew) but it is not supported by MATLAB, for this reason I'm wondering what one can (and can't) do with the trial licence of the NAG compiler before installing it.
Hi Luca, yes it’s valid only for 30 days. Could I ask what you’re trying to compile in the off-chance that we have the same issue?
Thanks for the answer @Alexandre RUBESAM. I'm interested in compiling AGMG (an aggregation-based algebraic multigrid method to solve linear systems). Here more details: https://agmg.eu/.
I have an academic licence.

Sign in to comment.

Categories

Products

Release

R2023b

Asked:

on 18 Sep 2023

Commented:

on 28 Nov 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!