I just got a MacBook Pro with the M1 pro chip. Now I’m trying to install gfortran.
First I installed Xcode from the App Store on my Mac. During the installation it did not ask me anything except whether I wanted to install Rosetta, which I did. I’m not sure if Command Line Tools are installed, but when I type
Next I went to http://hpc.sourceforge.net. and clicked on gfortran-11.2-bin.tar.gz (gfortran only). I then went to the Downloads directory on my Mac and typed
sudo tar -xvf gfortran-11.2-bin.tar -C /.
There appeared to be one error at the beginning of the install,
x usr/local/: Can’t restore time
but the rest of the install looked fine and it ended with
tar: Error exit delayed from previous errors.
I tried to compile a test program but it failed,
gfortran -o mytest.x mytest.f90
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
I tried re-installing gfortran from Downloads (this time without the period at the end):
sudo tar -xvf gfortran-11.2-bin.tar -C /
The problem persists. I googled this and found several suggestions but some seem outdated and I am not sure how to proceed. Any suggestions on how to fix this problem and get gfortran running on my M1pro?
Thanks for the suggestions about brew and conda. I expect I’ll install one of these eventually. But in the meantime I have searched a bit and discovered that I do indeed have Command Line Tools. I read that it has been automatically installed ever since Xcode 6.1 (and yesterday I installed 13.3.1). You can see it by going to Xcode - Preferences - Locations, at which point you can see if/where Command Line Tools are installed.
So my problem is not related to Command Line Tools…
My setup looks different and I can’t figure out what to point to it with -L . If I look inside /Library/Developer/, the only thing I see is a subdirectory called PrivateFrameWorks/
On the other hand, if I open Xcode and go to Xcode - Preferences - Locations, it tells me that the location for Command Line Tools is /Applications/Xcode.app . But don’t see anything that looks relevant in subdirectories of Xcode.app . So I am mystified.
I’m no expert on MacOS so it was trial and error way to find the fix. The directory given above is a location of (among many others) libSystem.tbd file (not libSystem.dylib as one might guess). Try to find that file in your filesystem, maybe it will work.
Problem solved. Thank you msz59. Following your suggestion I searched for libSystem.tbd and I found it in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
So I compiled using
gfortran mytest.f90 -L /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
In retrospect it might have been better to install Homebrew first. I just installed it a moment ago. In the process it downloaded Command Line Tools and put it in /Library/Developer/ . It appears that gfortran expects it there, because now gfortran works without specifying -L .
Xcode is huge (about 12 GB) and it’s possible that I’ll never need anything except Command Line Tools. Also, now I have 2 copies of Command Line Tools. So it might have been better to skip Xcode, install Homebrew, and to use it to install packages like gfortran. I just used it to install gnuplot and it worked perfectly.
At one time, it was possible to install the Apple/gnu command line tools without installing the full Xcode. However, I don’t think you can do that now. I’m like you, I don’t really need the whole Xcode install, but these days disk space isn’t as precious as it used to be, so I just install it and move on.
You can also follow the development of Asahi Linux, and when it fully rolls out you can use gcc on linux on your M1 Mac. Which would probably give you an easier time installing the GCC Fortran compiler in future.
Since installing gfortran I’ve noticed the following:
(1) In one case I needed to add -fallow-argument-mismatch to get a code to compile with the latest gfortran. This was related to compiling a large code with a subroutine that someone else wrote, that I never use, so I was not worried about coding errors.
(2) I have not done a systematic performance test. But I did run a few minute long job on my 2016 MacBook Pro, and also ran it on my M1pro. This was a serial code with no MPI and no OpenMP. The M1pro executed about 2x faster.
You might be in for an interesting result once you start running multi-threaded code on your M1pro. From several tests I have seen the single core performance of the Apple Arm CPU is great, but does not transfer to multi-thread or multi-process performance. Would be interested to see whether you will arrive at the some conclusion.
Would be interested in your experiences here. My Mac M1 with 8 cores has 4 performance cores and 4 efficiency cores. In my very non-scientific experience it seems that limiting to 4 cores is often beneficial.
It depends, I guess. At the moment I do not have access to an M1 machine, but a a while ago I tested my fem code on a M1 Macbook Air. The solvers use BLAS routines a lot (such as DGEMM) and with -framework accelerate the M1 was 2x faster than my Intel Macbook Pro 2020 with OpenBLAS, both without multi-threading. The M1 uses the AMX2 coprocessor and hardly touches the CPU. Each cluster of 4 CPUs has one AMX2, so multithreaded BLAS is not an option with accelerate on an M1, having only 4 high-performance cores. In order to get to a comparable speed on the Intel machine I had to use multti-threaded BLAS with all the four CPUs and the fans making a lot of noise. The Macbook Air doesn’t have a fan and therefore is silent.