Scheduled Downtime
On Friday 21 April 2023 @ 5pm MT, this website will be down for maintenance and expected to return online the morning of 24 April 2023 at the latest

WRF compile fails because of undefined function in module_mp_fast_sbm.f90

This post was from a previous version of the WRF&MPAS-A Support Forum. New replies have been disabled and if you have follow up questions related to this post, then please start a new thread from the forum home page.

irowe1

New member
Hello,

I am trying to build WRF on my Mac (macOS Catalina v10.15.4, Intel CPU) but am having some difficulties. First thing's first, I know my environment is correct as I passed every test listed here: https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compilation_tutorial.php

Originally I used the Homebrew gfortran installation and everything worked fine, but when I went to compile WPS, geogrid.exe and ungrib.exe were compiled, but not metgrid.exe. Looking into the log file, it seems that the metgrid executable was skipped because some of the modules it referenced were "Compiled with a different version of GNU fortran". I noticed that when I installed netcdf via Homebrew, the gcc package was installed, which conflicts with the gfortran package. So I decided to uninstall the gfortran package and use the gfortran-9 binary that came with the gcc package and recompile WRF in hopes that the modules would end up all on the correct version.

The binary for gfortran in that package is called gfortran-9, so I edited the top of the WRF configure script to contain this alias:
Code:
alias gfortran=gfortran-9

Configuration works perfectly, but compilation gives some errors. The first of these is "Unclassifiable Statement" from line 6065 of module_mp_fast_sbm.f90:
Code:
DM_BCAST_MACRO_R16 ( FAF1 )
The function DM_BCAST_MACRO_R16 is not defined in the file or in the ones it includes. It is defined by module_mp_fast_sbm.F, which looks like it is converted to the .f90 format just before in the compile script.

What's going wrong here? Is there anyway to fix this?

Output of gfortran -v:
Code:
Using built-in specs.
COLLECT_GCC=gfortran-9
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/9.3.0_1/libexec/gcc/x86_64-apple-darwin19/9.3.0/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --build=x86_64-apple-darwin19 --prefix=/usr/local/Cellar/gcc/9.3.0_1 --libdir=/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 9.3.0_1' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk SED=/usr/bin/sed
Thread model: posix
gcc version 9.3.0 (Homebrew GCC 9.3.0_1)
 
Yes that is correct. I will compile the same codes here and see whether I can repeat the errors you have.
I suppose you compiled codes in smpar mode. Please let me know if I am wrong. Can you try to build the code in dmpar mode and let me know whether it works? Thanks.
 
I removed the alias from the script and made a symlink from gfortran-9 to /usr/local/bin/gfortran. After running ./clean -a, I was able to recompile successfully.
 
Maybe I didn't really fix it the way I originally thought.

I made some changes to the physics radiation modules and went to recompile, and I encountered this same error again. It is unrelated to the changes I made. So far cleaning and rebuilding has not worked.

Since you asked earlier, here is my configure.wrf:
 

Attachments

  • configure.wrf
    20.3 KB · Views: 66
I should add that I am attempting to compile with the serial configuration.

As best as I can tell, the compile script is taking fixed-width Fortran files and transforming them to free format Fortran and compiling them into object files via this code from configure.wrf (lines 346-357)
Code:
.F.o:
	$(RM) $@
	sed -e "s/^\!.*'.*//" -e "s/^ *\!.*'.*//" $*.F > $*.G
	$(CPP) -I$(WRF_SRC_ROOT_DIR)/inc $(CPPFLAGS) $(OMPCPP) $*.G  > $*.bb
	$(SED_FTN) $*.bb | $(CPP) $(TRADFLAG) > $*.f90
	$(RM) $*.G $*.bb
	@ if echo $(ARCHFLAGS) | $(FGREP) 'DVAR4D'; then \
          echo COMPILING $*.F for 4DVAR ; \
          $(WRF_SRC_ROOT_DIR)/var/build/da_name_space.pl $*.f90 > $*.f90.tmp ; \
          mv $*.f90.tmp $*.f90 ; \
        fi
	$(FC) -o $@ -c $(FCFLAGS) $(OMP) $(MODULE_DIRS) $(PROMOTION) $(FCSUFFIX) $*.f90

This leads to the following output in the compile script for each .F file.
Code:
sed -e "s/^\!.*'.*//" -e "s/^ *\!.*'.*//" module_mp_fast_sbm.F > module_mp_fast_sbm.G
cpp -P -nostdinc -xassembler-with-cpp -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/inc -DEM_CORE=1 -DNMM_CORE=0 -DNMM_MAX_DIM=2600 -DDA_CORE=0 -DWRFPLUS=0 -DIWORDSIZE=4 -DDWORDSIZE=8 -DRWORDSIZE=4 -DLWORDSIZE=4 -DNONSTANDARD_SYSTEM_SUBR -DMACOS  -DWRF_USE_CLM  -DDM_PARALLEL -DSTUBMPI -DNETCDF -DLANDREAD_STUB=1 -DUSE_ALLOCATABLES -Dwrfmodel -DGRIB1 -DINTIO -DKEEP_INT_AROUND -DLIMIT_ARGS -DBUILD_RRTMG_FAST=0 -DBUILD_RRTMK=0 -DBUILD_SBM_FAST=1 -DSHOW_ALL_VARS_USED=0 -DCONFIG_BUF_LEN=65536 -DMAX_DOMAINS_F=21 -DMAX_HISTORY=25 -DNMM_NEST=0  -I. -traditional-cpp   module_mp_fast_sbm.G  > module_mp_fast_sbm.bb
/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/tools/standard.exe module_mp_fast_sbm.bb | cpp -P -nostdinc -xassembler-with-cpp -traditional-cpp > module_mp_fast_sbm.f90
rm -f module_mp_fast_sbm.G module_mp_fast_sbm.bb
time gfortran -o module_mp_fast_sbm.o -c -O2 -ftree-vectorize -funroll-loops -w -ffree-form -ffree-line-length-none -fconvert=big-endian -frecord-marker=4   -I../dyn_em -I../dyn_nmm  -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/external/esmf_time_f90  -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/main -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/external/io_netcdf -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/external/io_int -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/frame -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/share -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/phys -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/wrftladj -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/chem -I/Users/isaacrowe/Documents/GitHub/WRF_ARW/WRF/inc -I/usr/local/Cellar/netcdf/4.7.4/include    module_mp_fast_sbm.f90

It looks like the DM_BCAST_MACRO_R1 macro that's in the .F file should have been replaced by its definition (CALL wrf_dm_bcast_bytes(A, size(A)*R16SIZE), as seen on line 5459 of module_mp_fast_sbm.F),in the .f90 output. For some reason that didn't happen, and the resulting .f90 file was not able to be compiled into the .o file.
 
More to digest here. I checked, and many of the other macros were getting correctly substituted. So why not this one? Well, in lines 655 - 673 of module_mp_fast_sbm.F, the spacing of the macro is incorrect:
Code:
#if (defined(DM_PARALLEL))
   	DM_BCAST_MACRO_R16 ( FAF1 )
   	DM_BCAST_MACRO_R16 ( FBF1 )
   	DM_BCAST_MACRO_R16 ( FAB1 )
   	DM_BCAST_MACRO_R16 ( FBB1 )
   ! ... (KS) - Broadcating Snow
   	DM_BCAST_MACRO_R16 ( FAF3 )
   	DM_BCAST_MACRO_R16 ( FBF3 )
   	DM_BCAST_MACRO_R16 ( FAB3 )
   	DM_BCAST_MACRO_R16 ( FBB3 )
   ! ... (KS) - Broadcating Graupel
   	DM_BCAST_MACRO_R16 ( FAF4 )
   	DM_BCAST_MACRO_R16 ( FBF4 )
   	DM_BCAST_MACRO_R16 ( FAB4 )
   	DM_BCAST_MACRO_R16 ( FBB4 )
   ! ### (KS) - Broadcating Hail
   	DM_BCAST_MACRO_R16 ( FAF5 )
   	DM_BCAST_MACRO_R16 ( FBF5 )
   	DM_BCAST_MACRO_R16 ( FAB5 )
   	DM_BCAST_MACRO_R16 ( FBB5 )

EDIT: I thought this may have been illegal spacing in the macro use, but it actually looks valid.
Note that the uses of a macro with arguments can have spaces before the left parenthesis; it's the definition where it matters whether there is a space.
Source: http://www-tcad.stanford.edu/local/DOC/cpp_11.html

I think there may be a bug in my preprocessor, so I further tested this with my own experiment.

test.c:
Code:
#define DM_BCAST_MACRO_R4(A) CALL wrf_dm_bcast_bytes(A, size(A)*R4SIZE)

DM_BCAST_MACRO_R4(3);

DM_BCAST_MACRO_R4 ( 3 );

Then I ran
Code:
cat test.c | cpp -P -nostdinc -xassembler-with-cpp -traditional-cpp > module_mp_fast_sbm.f90

The result:
Code:
CALL wrf_dm_bcast_bytes(3, size(3)*R4SIZE);

DM_BCAST_MACRO_R4 ( 3 );
 
Top