NOAA-OWP / snow17

Other
4 stars 10 forks source link

Compile error on Mac M3 chipset #37

Closed drakest123 closed 4 months ago

drakest123 commented 4 months ago

Snow-17 (standalone) builds fine on a Mac M1 chip but fails to build on a Mac M3 Max chip with the current Makefile.

Current behavior

Two files fail to link. I've tried several architecture options (-march flag). The output of the build is:

% make -f Makefile.local
gfortran -O3 -fdefault-real-8 -fno-align-commons -ffree-line-length-none -cpp -fcheck=all -march=native -c  ..//src/snow19//zero19.f  ..//src/snow19//rout19.f  ..//src/snow19//aesc19.f  ..//src/snow19//melt19.f  ..//src/snow19//SNEW.f  ..//src/snow19//SNOWT.f  ..//src/snow19//SNOWPACK.f  ..//src/snow19//adjc19.f  ..//src/snow19//aeco19.f  ..//src/snow19//updt19.f  ..//src/snow19//SNDEPTH.f  ..//src/snow19//PACK19.f  ..//src/snow19//exsnow19.f -I/opt/homebrew/include
gfortran -O3 -fdefault-real-8 -fno-align-commons -ffree-line-length-none -cpp -fcheck=all -c  ..//src/share//nrtype.f90  ..//src/share//constants.f90  ..//src/share//namelistModule.f90  ..//src/share//parametersType.f90  ..//src/share//forcingType.f90  ..//src/share//dateTimeUtilsModule.f90  ..//src/share//runInfoType.f90  ..//src/share//modelVarType.f90  ..//src/share//ioModule.f90  ..//src/share//runSnow17.f90  ..//src/bmi//bmi.f90  ..//src/bmi//bmi_snow17.f90  ..//src/driver//driver_bmi.f90 -I/opt/homebrew/include
gfortran -fPIC -I/opt/homebrew/include -L/opt/homebrew/lib  -o ..//bin//snow17.exe *.o 
Undefined symbols for architecture arm64:
  "_is_recursive.12.0", referenced from:
      ___forcingtype_MOD_initforcing in forcingType.o
      ___forcingtype_MOD_initforcing in forcingType.o
      ___forcingtype_MOD_initforcing in forcingType.o
  "_is_recursive.14.0", referenced from:
      ___modelvartype_MOD_initmodelvar in modelVarType.o
      ___modelvartype_MOD_initmodelvar in modelVarType.o
      ___modelvartype_MOD_initmodelvar in modelVarType.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
make: *** [link] Error 1

When I check one of the problematic object files, the _is_recursive function is referenced at the end of the object file:

_memcpy^@__gfortran_os_error_at^@__gfortran_runtime_error_at^@___defnamelist_MOD_n_hrus^@___forcingtype_MOD_initforcing^@___forcingtype_MOD___copy_forcingtype_Forcing_type^@___forcingtype_MOD___def_init_forcingtype_Forcing_type^@___forcingtype_MOD___final_forcingtype_Forcing_type^@___forcingtype_MOD___vtab_forcingtype_Forcing_type^@_free^@_malloc^@lC9^@lC8^@lC7^@lC17^@lC6^@lC16^@ltmp5^@lC5^@lC15^@ltmp4^@lC4^@lC14^@ltmp3^@lC3^@lC13^@ltmp2^@lC2^@lC12^@ltmp1^@EH_frame1^@lC1^@lC11^@ltmp0^@lC0^@lC10^@_is_recursive.12.0^@^@^@^@

This code is also evident in the object file built on an M1 chip but in that case it links.

hellkite500 commented 4 months ago

One thing to note from looking at the compiler lines, the second object file is built without the march flag whereas the first object file has it...

gfortran -O3 -fdefault-real-8 -fno-align-commons -ffree-line-length-none -cpp -fcheck=all -c 

May need to apply the flag consistently on all make targets.

drakest123 commented 4 months ago

Good idea. I tried that but no luck. I'll works on this some more tomorrow.

% make -f Makefile.local 
gfortran -O3 -fdefault-real-8 -fno-align-commons -ffree-line-length-none -cpp -fcheck=all -march=native -c  ..//src/snow19//zero19.f  ..//src/snow19//rout19.f  ..//src/snow19//aesc19.f  ..//src/snow19//melt19.f  ..//src/snow19//SNEW.f  ..//src/snow19//SNOWT.f  ..//src/snow19//SNOWPACK.f  ..//src/snow19//adjc19.f  ..//src/snow19//aeco19.f  ..//src/snow19//updt19.f  ..//src/snow19//SNDEPTH.f  ..//src/snow19//PACK19.f  ..//src/snow19//exsnow19.f -I/opt/homebrew/include
gfortran -O3 -fdefault-real-8 -fno-align-commons -ffree-line-length-none -cpp -fcheck=all -march=native -c  ..//src/share//nrtype.f90  ..//src/share//constants.f90  ..//src/share//namelistModule.f90  ..//src/share//parametersType.f90  ..//src/share//forcingType.f90  ..//src/share//dateTimeUtilsModule.f90  ..//src/share//runInfoType.f90  ..//src/share//modelVarType.f90  ..//src/share//ioModule.f90  ..//src/share//runSnow17.f90  ..//src/bmi//bmi.f90  ..//src/bmi//bmi_snow17.f90  ..//src/driver//driver_bmi.f90 -I/opt/homebrew/include
gfortran -fPIC -I/opt/homebrew/include -L/opt/homebrew/lib  -o ..//bin//snow17.exe *.o 
Undefined symbols for architecture arm64:
  "_is_recursive.12.0", referenced from:
      ___forcingtype_MOD_initforcing in forcingType.o
      ___forcingtype_MOD_initforcing in forcingType.o
      ___forcingtype_MOD_initforcing in forcingType.o
  "_is_recursive.14.0", referenced from:
      ___modelvartype_MOD_initmodelvar in modelVarType.o
      ___modelvartype_MOD_initmodelvar in modelVarType.o
      ___modelvartype_MOD_initmodelvar in modelVarType.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
make: *** [link] Error 1
drakest123 commented 4 months ago

It turns out that many of the snow-17 object files contain the _is_recursive symbol but with different versions. I looked for but did not find odd characters in these two source files.

drakest123 commented 4 months ago

The following changes resolved the compile errors on a Mac M3 Max. I have not tested the executable yet but I'll be testing it this week.

In share/forcingType.f90 change: class(forcing_type), intent(out) :: this to: class(forcing_type), intent(inout) :: this

In share/modelVarType.f90 change: class(modelvar_type), intent(out) :: this to class(modelvar_type), intent(inout) :: this

SnowHydrology commented 4 months ago

Closed by #43