compiling error - duplication in gfsphysics and ccppphysics lib

Submitted by helin.wei on Mon, 01/04/2021 - 17:52

This is my first time to come across such kind of errors. 

We added two variables (scffac_table and snow_emis_table) in noahmp_tables.f90. They will be used by module_sf_noahmplsm.f90. sfc_noahmp_drv.f has been modified too. All of them are under ccpp physics. More detail can be found from https://github.com/HelinWei-NOAA/ccpp-physics/tree/feature/noahmp

As you know Noah MP source codes will be compiled and included to both ipd and ccpp physics lib( libgfsphysics.a and libccppphys.a), I got the following errors from the last step of compiling (Linking Fortran executable ufs_model),

 

FV3/gfsphysics/libgfsphysics.a(noahmp_tables.f90.o):noahmp_tables.f90:(.text+0x0): first defined here
FV3/ccpp/physics/libccppphys.a(noahmp_tables.f90.o):(.bss+0x0): multiple definition of `noahmp_tables_mp_irri_table_'
FV3/gfsphysics/libgfsphysics.a(noahmp_tables.f90.o):(.bss+0x0): first defined here
FV3/ccpp/physics/libccppphys.a(noahmp_tables.f90.o):(.bss+0x40): multiple definition of `noahmp_tables_mp_esp5_table_'
FV3/gfsphysics/libgfsphysics.a(noahmp_tables.f90.o):(.bss+0x40): first defined here
FV3/ccpp/physics/libccppphys.a(noahmp_tables.f90.o):(.bss+0x140): multiple definition of `noahmp_tables_mp_esp4_table_'
FV3/gfsphysics/libgfsphysics.a(noahmp_tables.f90.o):(.bss+0x140): first defined here
FV3/ccpp/physics/libccppphys.a(noahmp_tables.f90.o):(.data+0x0): multiple definition of `noahmp_tables_mp_bio2lai_table_'

.....

/scratch1/NCEPDEV/global/Helin.Wei/save/git/ufs-weather-model/tests/compile_1.log.fail

 

multiple definition (duplication in ipd and ccpp version of routines).

 

It was fine before we made some changes in  sfc_noahmp_drv.f. We added following two lines:

        parameters%scffac = scffac_table(vegtype)       !snow cover factor

        parameters%snow_emis = snow_emis_table

 

If we remove these two lines and keep all other changes, the compiling can be completed without any error.

Hi Helin,

this is a known problem, see https://github.com/NOAA-EMC/fv3atm/issues/206. The solution is to move the entire land vegetation/soil table initialization from FV3/io/FV3GFS_io.F90 to CCPP, which will be done in the next few weeks as part of the complete removal of the IPD. See issue https://github.com/NOAA-EMC/fv3atm/issues/214 for a description of the steps. Step 2, the next to be done (step 1 is complete), will take care of your problem.

I hope you can wait for another two weeks or so. If not, then a nasty hack to make this work could be to add exactly the same logic in the IPD version of Noah MP LSM (at least this approach has worked in the past).

Hi Helin,

Here is a bit of context and some thoughts about solutions.

There are two versions of NoahMP and its dependencies: the version that exists in the FV3 repository in FV3/gfsphysics/physics and the version that exists in the CCPP-physics repository in FV3/ccpp/physics/physics. Both have an associated noahmp_tables.f90 file. Normally, when schemes are put into the CCPP, the makefile in FV3/gfsphysics/makefile is modified so that the version in the FV3 repository is not compiled when the CCPP is being used. For NoahMP, however, one of the dependencies, noahmp_tables.f90, is needed by FV3, whose files (I think!?) are compiled before the CCPP. Specifically, the data in noahmp_tables.F90 is used in FV3/io/FV3GFS_io.F90/sfc_prop_restart_read to provide a way to "cold start" NoahMP, given Noah initial conditions. So, the FV3 version of noahmp_tables.f90 was kept in the makefile, even when running with CCPP. However, noahmp_tables.f90 is also listed as a dependency for the CCPP version of NoahMP in sfc_noahmp_drv.meta. I think that this means that noahmp_tables.F90 has the potential to be compiled twice -- once for FV3 and once for the CCPP -- and I think that this is the root of the compilation error that you are seeing.

There could be multiple solutions to this problem. I think that one is to move the NoahMP cold start code into sfc_noahmp_drv.f/noahmpdrv_init -- the init phase of the NoahMP CCPP scheme. Then, in FV3/io/FV3GFS_io.F90/sfc_prop_restart_read, put the NoahMP cold start code into a preprocessor block that only gets executed when not using the CCPP, and remove noahmp_tables.f90 from the CCPP section of the makefile. I think this is actually similar to how the RUC LSM does cold starts from Noah initial conditions (within its init phase). I'm guessing that this is possible, but we would need to look carefully at the code in FV3GFS_io.F90 to make sure. 

Another temporary solution would be to remove noahmp_tables.f90 from the dependencies in sfc_noahmp_drv.meta, so it doesn't try to compile the CCPP version, and it can use the FV3 version instead. Since you only modified the CCPP version, you would need to modify the FV3 version to match. I don't think that this is the preferred solution, however.

Perhaps there is also something fancy that can be done in the build system to make this work too, although I'm MUCH less familiar with implementing something like that.

Also, this may be a moot point going forward soon. I was under the impression that IPD and the physics in FV3 were going to be removed altogether soon, in which case this problem would disappear. I could be wrong about this.

We should get Dom Heinzeller to weigh in on the proposed solutions, or perhaps there is some other solution that I'm not thinking of. I will email him and point him to this forum post.

Thanks for the question and being willing to post this in the forum!

-Grant

Ah, I see that Dom already responded before I could. So, it sounds like it will be taken care of soon with the removal of IPD.

-Grant

Dom and Grant,

Thank you so much for your explanation and suggestion. Now I understand the issue and will wait for the removal of IPD to commit our changes to the repository. For my testing of our changes, I just tried to put the same changes to IPD physics and the code was compiled successfully.

 

Helin