Main menu


Compiling cprnc on Darwin/OSX machine

1 post / 0 new
Compiling cprnc on Darwin/OSX machine

In trying to compile CESM2.1.0 on my MacBook Pro (OS: Mojave 10.14.4/Darwin 18.5.0) for use in single column mode (i.e. SCAM), I've been using the file included in $CIMEROOT/config/machines/userdefined_laptop_template to guide me through a homebrew-centric install and I wanted to make the developers aware of some deviations from the instructions given that I've run into. So far, the most frustrating experience was with installation of cprnc as opposed to compiling/running the model itself -- in fact, cprnc was the very last piece of the puzzle to come together.


Disclaimer: I don't have an in-depth understanding of how cmake or make work, so I suspect there's a basic fix for the issues I highlight below that I'm just not aware of. In particular, I imagine there's a straightforward mechanism to pass compiler options to make but I couldn't figure out the right search terms to find a relevant example on stackoverflow, netcdf forum, etc.


In, the following instructions are given (I'm skipping things that worked fine. Again, this is only for the homebrew set up; I don't know how it would differ using macports):

- install third party libraries from homebrew or macports.

      - home brew

        Install science tap : <>

            brew install gcc --without-multilib cmake mpich hdf5 --enable-fortran netcdf --enable-fortran

        Note: If you see an error while running create_newcase that
        indicates perl can't find XML::LibXML, you may need to install
        p5-xml-libxml as well.

COMMENTS: The science tap has been deprecated; there is a legacy tap "brewsci/science" but I skipped straight to the brew formula given, which also had some issues. The "--without-multilb" option for gcc has been deprecated since Darwin is now fully 64-bit and the "--enable-fortran" option for hdf5 and netcdf is also gone. Most importantly, homebrew does NOT have a mechanism for enabling parallel I/O with hdf5/netcdf. I ended up uninstalling the homebrew taps and compiling hdf5 and netcdf from source code to enable parallel I/O. Note that this did NOT require a separate PnetCDF install, which appears to be necessary only if parallel I/O in the netcdf-2 format is desired; parallel netcdf-4 I/O can be enabled without any external package.

  - Some of the shell scripts used by cesm hard code "gmake" instead
    of using the GMAKE variable from env_build.xml. To work around
    this, you should install gnu make, or simply create a link from
    make to gmake in you path.

        mkdir -p ${HOME}/local/bin

        ln -s `whereis make` ${HOME}/local/bin/gmake

        cat >> ${HOME}/.bashrc <<EOF

        export PATH=${PATH}:${HOME}/local/bin


COMMENTS: creating this symbolic link to make doesn't appear to be necessary.

- build cprnc :

    homebrew :

        cd ${CIMEROOT}/tools/cprnc

        ${CIMEROOT}/tools/configure --macros-format CMake

        mkdir build

cd build

        cmake \

            -DCMAKE_Fortran_COMPILER=/usr/local/bin/mpif90 \

            -DHDF5_DIR=/usr/local \

            -DNetcdf_INCLUDE_DIR=/usr/local/include ..


COMMENTS: Here's where things got hairy. Even though the NetCDF path is specified in and Netcdf_INCLUDE_DIR is explicitly defined in the call to cmake, when I invoked make I got the following error: 


f951:Warning: Nonexistent include directory '/include' [-Wmissing-include-dirs]

2 |   use netcdf
      |      1
Fatal Error: Cannot open module file 'netcdf.mod' for reading at (1): No such file or directory compilation terminated.
make[2]: *** [CMakeFiles/cprnc.dir/filestruct.F90.o] Error 1
make[1]: *** [CMakeFiles/cprnc.dir/all] Error 2
make: *** [all] Error 2


(Note: I changed the path in the second copied line for privacy reasons)

I tried everything I could think of here to correct this issue using the cmake -D option, but nothing I did made a difference. In the end, I went into $CIMEROOT/tools/cprnc/build/CMakeFiles/cprnc.dir and directly modified several files. Most of them contain the warning "CMAKE generated file: DO NOT EDIT!" at the top, which is what leads me to believe there must be a better way to set the following options with cmake. Nevertheless, I made the following edits:

Changed link.txt from:


/usr/local/bin/mpif90 -ffree-line-length-none -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk CMakeFiles/cprnc.dir/compare_vars_mod.F90.o CMakeFiles/cprnc.dir/filestruct.F90.o CMakeFiles/cprnc.dir/utils.F90.o CMakeFiles/cprnc.dir/prec.F90.o CMakeFiles/cprnc.dir/cprnc.F90.o  -o cprnc /include/netcdff.a


to the following:


/usr/local/bin/mpif90 -I/usr/local/include -L/usr/local/lib -lnetcdf -lnetcdff -ffree-line-length-none -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk CMakeFiles/cprnc.dir/compare_vars_mod.F90.o CMakeFiles/cprnc.dir/filestruct.F90.o CMakeFiles/cprnc.dir/utils.F90.o CMakeFiles/cprnc.dir/prec.F90.o CMakeFiles/cprnc.dir/cprnc.F90.o  -o cprnc

Changed the first path of CMAKE_Fortran_TARGET_INCLUDE_PATH in DependInfo.cmake from "/include" to



and in flags.make I changed the first argument in the Fortran_INCLUDES line from "-I/include" to -I/usr/local/include"


And now I have a working cprnc executable. I think some of the things I did are probably redundant (e.g., changing the Fortran_INCLUDES line in flags.make and manually adding compiler flags to link.txt) but I wanted to faithfully communicate everything I did to successfuly compile. I look forward to learning how to streamline this so I can avoid messing with things that start with "DO NOT EDIT!!!" in the future -- any constructive criticsm on my method would be welcome.


Best of luck to anyone else porting to a Mac. I'd be happy to share my limited experience with you or just commiserate if/when you run into similar issues.




Who's new

  • stans
  • ahadibfar@...
  • jskang@...
  • divanova@...
  • mrostami@...