MacPorts is a package manager to install software onto our Mac (OSX) systems. It installs software into /opt/local/bin which is owned by root, so you have to use your admin account for the subset of commands that actually modify that directory. It is one of the ways to get many useful bits of software including ncview, the netCDF libraries, the gfortran compilers, diffuse, etc. I am attaching a list of frequently-used commands. These are often needed after a new OS upgrade or when you get a new machine. You may or may not have to add /opt/local/bin to your path.
csh/tcsh users (this is in my ~/.tcshrc) :
# adding an appropriate PATH variable for use with MacPorts.
setenv PATH "/opt/local/bin:/opt/local/sbin:$PATH"
sh users:
# adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
Once MacPorts has been installed,
searching for available packages can be done using the `port search` command - documented in https://guide.macports.org/#using.port.search. The ones I think that are most useful are:
port search --name --line --glob '*gcc*'
port search --name --line --glob 'mpich*'
After an OS upgrade or after being migrated to a new machine:
When you have to upgrade your operating system via scripts from the workstation group, after the OS install it should update XCode (the apple supplied compilers and build tools) and then it should run additional scripts that update your already-installed macports. For an OS upgrade, it should save a list of the ports you have installed, download a new version of the "port" program if needed, and then reinstall the ports from the list. If this doesn't work, or if you want to install other ports, keep reading.
These are probably good things to do after getting a new machine or OS ... (someone please report on the amount of time this takes!)
For an OS upgrade you may need to download a new version of the 'port' command, see: https://trac.macports.org/wiki/Migration
su <your_admin_account>
sudo port selfupdate
sudo port upgrade outdated
After updating to Catalina, the 'upgrade' step ended with:
thoaradmin@cisl-minnetonka ~ % ---> Some of the ports you installed have notes:
mpich-default has the following notes:
+--- MPICH Usage note ----
| The mpicc wrapper (and friends) are installed as:
|
| /opt/local/bin/mpicc-mpich-mp (likewise mpicxx, ...)
|
| To make mpich-default's wrappers the default (what you get when
| you execute 'mpicc' etc.) please run:
|
| sudo port select --set mpi mpich-mp-fortran
+-------------------------
NOTE: Default fortran changed to +gcc10; consider switching variants to enable
pre-built packages for mpich-default by running:
"sudo port clean mpich-default && sudo port upgrade mpich-default +gcc10 -gcc9"
So I tried their suggestions - which almost worked. macports complained that I needed another option, so the actual sequence that worked for me was to:
sudo port clean mpich-default
sudo port upgrade --enforce-variants mpich-default +gcc10 -gcc9
Apparently gcc10 (and the matching gfortran) are more strict about their interpretation of backwards compatibility.
Be aware that I had to add the 'allow-argument-mismatch' compile flag to be able to compile certain legacy bits of code:
FFLAGS = -O0 -ffree-line-length-none -fallow-argument-mismatch $(INCS)
Starting from Scratch
A sequence which has worked (for Tim) in the past to install compatible gcc, gfortran (which comes with the gcc install), mpich, and netCDF libraries is:
port search --name --line --glob 'mpich*'
port search --name --line --glob '*gcc*'
sudo port install mpich
port select --list mpi
port select --list gcc
sudo port select --set mpi mpich-mp-fortran
sudo port select --set gcc mp-gcc10
sudo port install netcdf
sudo port install netcdf-fortran
sudo port install diffuse
The intent here is that mpich has required packages it will install, including a gcc compiler. Figure out which gcc is required by the mpich-mp-fortran package and then set it to be the default.
Note: I just did this on my 11 year-old iMac and - including installing Xcode and the Xcode command-line tools (required by MacPorts) as well as MacPorts (from the .dmg), the entire process took less than 3 hours.
Please note that the After that, you should be able to build DART.
If you are going to use MacPorts to install netcdf support, it may also be useful to set an environment variable to reference the location:
<tcsh/csh>: setenv NETCDF /opt/local
<ksh/sh>: export NETCDF=/opt/local
Useful commands, in no particular order:
- sudo port uninstall --follow-dependencies <portname>
- port select --summary
- sudo /opt/local/bin/port self-install
Here is a printable "cheat sheet" with common commands:
Here is the RTF (rich text format) source for the cheat sheet above, in case you want to customize it: