Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to run this script on Mac OS Ventura 13.0 (M1-Max) #5

Open
ihaseeburrehman opened this issue Nov 9, 2022 · 12 comments
Open
Assignees

Comments

@ihaseeburrehman
Copy link

I am new to WRF. (Even new with Mac terminal :))
I tried to use this script to install WRF v 4.4.1.
But I got many issues e.g.

  • in cask room ( it is now brew cask)
  • Tap dupe ( After google I came to know it is no longer needed)
  • not able to setenv for netCDF, even though I have installed Netcdf through home-brew.
  • in-last not able to configure/compile.

I wonder if anybody can help me. I have attached compile logs.

compile_wrf.log

@Toberumono Toberumono self-assigned this Nov 9, 2022
@Toberumono
Copy link
Owner

Toberumono commented Nov 9, 2022

First off, this is a nightmare of a project to jump into as your first experience with Terminal. While most of the compilation process should be similar with an M1 chip and WRF v4, it doesn't look like it will be directly portable, so using my setup script will likely not be possible.
I haven't actually updated these scripts in years now, and I don't have a machine that I can test them on for ARM compatibility.

Poking around in homebrew's repositories, it looks like the majority of the hacks that I had to do have been obsoleted in the intervening years, which means that you should be able to just run the installers directly:

brew install --cask ncar-ncl
brew install m4 pv ncurses cairo libpng szip lzlib pixman doxygen tcsh hdf5 jasper netcdf-fortran

If the above install commands complete successfully, then it should be possible to proceed with the WRF installation; however, I'd recommend configuring it manually rather than trying to use my setup script. The official instructions can be found here: https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compilation_tutorial.php#STEP4.

The runner part of this project should still work, at least. It's written in Java, which can be installed via homebrew as is M1 compatible, and It doesn't actually rely on the precise internals of WRF - so long as their basic configuration files haven't changed it'll still work.

@ihaseeburrehman
Copy link
Author

ihaseeburrehman commented Nov 10, 2022

Hi
Thank you so much for you brief reply.
This morning I started configuring/compiling manually. I did installation from Homebrew. But I stuck on warning "The moving nest option is not available due to missing rpc/types.h file.
Copy landread.c.dist to landread.c in share directory to bypass compile error."
I did a research on internet, but I did not find any solution. I am using Darwin ARCH option "35.dmper" and basic for nesting.
I got error "make: *** [configcheck] Error 1" while compiling.
Wonder if you can help on this .
Thanks .
image

@Toberumono
Copy link
Owner

Toberumono commented Nov 10, 2022

So. Apparently, WRF doesn't build properly on MacOS anymore (at least, it looks like its newer features don't).
If you take a look in the "share" directory of the WRF folder, you should find the "landread.c" and "landread.c.dist" files.
Remove the first one (landread.c) and rename the second one (landread.c.dist) to landread.c.
If you can't see file extensions, you can either enable that in Finder or you can run the following from the WRF directory:

rm share/landread.c
mv share/landread.c.dist share/landread.c

That should bypass the error that you are currently seeing. You may need to rerun configure after making that change.

@ihaseeburrehman
Copy link
Author

ihaseeburrehman commented Nov 10, 2022

Hi
Thanks again for coming to my comment.
Actually it was warning , and it will pop up when I try to run wrf.exe.
I will follow your suggestion at that time, which i think is the workaround .
But the "error" was related to C compiler which I mentioned above "make ...error 1". I was able to fix it by install mpic through home brew.
Now the issue rises with module "module_dm". It can't find in the directory . Even though it is in the directory (I am not 100 % sure ) .
I am attaching hereby my compile logs .
If you can help ?
Thanks
image

@Toberumono
Copy link
Owner

It looks like the error occurred much earlier than that. Search for the first instance of "module_state_description". You'll likely see some other compile errors. If those compile errors include being unable to open another file, search for errors relating to that one. Rinse and repeat and you should eventually find the original error, which is what we'll need in order to fix this.

@ihaseeburrehman
Copy link
Author

ihaseeburrehman commented Nov 11, 2022

Hi
Today I started again from scratch. While installing library NETCDF I got error "checking if Fortran "byte" is C "signed char"... configure: error: Could not compile conftest.c". I think it's because of my gcc version. WRF forum suggest to use gcc 4.6 or above. But I have currently gcc 12, and I can not install gcc 4.6 because it only support with Xcode 9 or down. I have Xcode 14.
can you suggest me some work around ?
do you think I need to install these libraries (NETCDF, Zlib etc) manually , although I also install these through home brew.
I don't know how it was bypassed in my first attempt.

@Toberumono
Copy link
Owner

GCC 12 is significantly newer than 4.6 by over a decade, so that shouldn't be the issue.
Unfortunately, I don't have a suggestion here - If you can send me the full logfile, I might be able to find something.

@ihaseeburrehman
Copy link
Author

I have attached but I don't think we need to install NETCDF manually, because it is already installed through home-brew. As I can the see from running the command "which ncdump" and it return netcdf 4.9.0.
May you look into my environment which I set. I assume that NETCDF is installed through home-brew . So, I setenv for DIR to home-brew directory.
Also, When I did Test for Fortran + C + NetCDF. I run this command " gfortran -c 01_fortran+c+netcdf_f.f
gcc -c 01_fortran+c+netcdf_c.c
gfortran 01_fortran+c+netcdf_f.o 01_fortran+c+netcdf_c.o
${NETCDF}/lib -lnetcdff -lnetcdf
./a.out
"
I got this ld:
file not found: /opt/homebrew/opt/netcdf/4.9.0/lib
collect2: error: ld returned 1 exit status
[UNIF2MW0C47X3:~/TESTS] haseeb.rehman% ./a.out
C function called by Fortran
Values are xx = 2.00 and ii = 1 "

which should be "SUCCESS test 1 fortran + c + netcdf"

Here are the env which I Set ;
setenv DIR /opt/homebrew/Cellar
setenv CC gcc
setenv CXX g++
setenv FC gfortran
setenv FCFLAGS -m64
setenv F77 gfortran
setenv FFLAGS -m64
setenv JASPERLIB $DIR/grib2/lib
setenv JASPERINC $DIR/grib2/include
setenv LDFLAGS -L$DIR/grib2/lib
setenv CPPFLAGS -I$DIR/grib2/include
setenv NETCDF /opt/homebrew/opt/netcdf/4.9.0

config.log

@Toberumono
Copy link
Owner

Likely Solution

I've left my original recommendations below (and I still recommend reading them), but, on closer inspection, I think that all that you need to do is replace your setenv NETCDF /opt/homebrew/opt/netcdf/4.9.0 line with:

setenv NETCDF /opt/homebrew/Cellar/netcdf/4.9.0

You also likely need to add NETCDF to your path, which can be done with:

setenv PATH /opt/homebrew/Cellar/netcdf/4.9.0/bin:$PATH

Finally, I suspect that your "grib2" directories are wrong. I'm not entirely sure how you derived them, but the Cellar directory of homebrew is two layers deep while your paths require it to be one layer - specifically, the full path for something in the Cellar directory is: "$(brew --prefix)/Cellar/<package name>/<package version>/<bin,lib,etc>" while your path assumes "$(brew --prefix)/Cellar/<package name>/<bin,lib,etc>". If they weren't installed via homebrew, I'd recommend reconfiguring and rebuilding that library so that it is not in a homebrew-managed directory.

Original Recommendations

There are a couple of things that I'm confused by. First, the setenv usage is a bit odd. I'm assuming that you're running this in bash, in which case you can replace that block of instructions with:

DIR='/opt/homebrew/Cellar'
export CC='gcc'
export CXX='g++'
export FC='gfortran'
export FCFLAGS='-m64'
export F77='gfortran'
export JASPERLIB="$DIR/grib2/lib"
export JASPERINC="$DIR/grib2/include"
export LDFLAGS="-L$DIR/grib2/lib"
export CPPFLAGS="-I$DIR/grib2/include"
export NETCDF="/opt/homebrew/Cellar/netcdf/4.9.0"

I suspect that you'll want to add the following:

export PATH="$PATH:$NETCDF/bin"

In general, I'd recommend replacing any instances of /opt/homebrew with $(brew --prefix)

@ihaseeburrehman
Copy link
Author

Thanks for recommendation.
I was able to install the Libraries manually. I came to know that netcdf 4.1.3 (as recommended on WRF forum) no longer supported because it require older version of gcc. same case for mpich and jasper.
I have netcdf 4.9 and jasper 2.0.3
Now I installed the libraries and set the environment.
I was using tcsh as shell before now I am using bash.
below are my environment
export DIR=/Users/haseeb.rehman/Build_WRF/LIBRARIES
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
export LDFLAGS=-L$DIR/grib2/lib
export CPPFLAGS=-I$DIR/grib2/include
export PATH=$DIR/netcdf/bin:$PATH
export NETCDF=$DIR/netcdf
export PATH=$DIR/mpich/bin:$PATH
export NCDIR=/Users/haseeb.rehman/Build_WRF/LIBRARIES/netcdf
export LD_LIBRARY_PATH=${NCDIR}/lib:${LD_LIBRARY_PATH}
export NFDIR=/Users/haseeb.rehman/Build_WRF/LIBRARIES/netcdf

now the problem rise when I start compiling, after successful configuration. let me know if you can see the logs and recommend something. The error is "registry.c:63:3: error: implicit declaration of function 'sym_forget' is invalid in C99 [-Werror,-Wimplicit-function-declaration] sym_forget() ;"
log .txt

@Toberumono
Copy link
Owner

That error is bizarre because it'd normally not be an error - you can see GCC's reason for outputting that message includes -Werror, which means that it's only an error because GCC is being forced to treat it as such.

I was looking into getting this stuff set up myself, but the install process for wgrib2 is a bit insane. Did you manually download NETCDF 4.8.1 and whatever version of HDF5 it requires? I have a sneaking suspicion that a large portion of the errors in the logs are due to compatibility issues between the libraries being used.

If you are willing to give macports a try, it looks like they have all of the libraries that you need pre-built, which should fix the compatibility issues.

If macports isn't an option (or doesn't work), then I'm out of viable ideas - the other one requires significantly more work than I can dedicate to this right now.

@ihaseeburrehman
Copy link
Author

I can't install gcc with version lower than 11 because Mac "M1" does not support it even through Mac ports.
After so many attempts and experiments I am able to compile WRF v4 on Mac which means I created executables successfully.

What I realised I was making mistake , I was using clang compiler (which comes with Xcode ) instead of gcc from Homebrew. Because clang doesn't have <bits/stdc++.h> header, so I was getting weird errors. Although, it's bit tricky to switch to Homebrew gcc from apple clang (gcc) This video [https://www.youtube.com/watch?v=wY24ehH6mC0] helps me. But anyhow I succeeded in compiling the WRF. I had a fear that my compilation may run into errors because I built libraries (Netcdf, mpich, jasper etc) with clang compiler but compilation was ok in the end which was unexpected.
So Now I will instal WPS which I think will also a nightmare for me. I will update here.

I also concluded that Apple Mac with M1 chip is always challenging when compare to intel based Mac. May be it's new in the market.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants