How can I treat nvfortran as gfortran to compile dftd4 with meson?

As I’m doing research with VASP on GPU, I’d like to compile it with nvhpc toolkits, however it’s difficult to compile dft-d4 package. It’s website is https://github.com/dftd4/dftd4. I’m using nvhpc 23.1, and I’m a complete newbie to fortran. I found that there maybe some “bugs” in nvfortran that the function move_alloc may cause a string to lose it’s end symbol ‘\0’. I’m not sure about the rule, but just to infer it just like C. Moreover, it can pass all the unit test if I use gfortran but failed much with nvfortran, and for the package compiled by gfortran cannot be linked to a project built by nvfortran, it’s really confusing.

I want to know what FFLAGS should I set that the nvfortran may behaviour just like gfortran? Some uses the parameter below:

gfortran

gfortran -Isubprojects/mctc-lib/libmctc-lib.a.p -Isubprojects/mctc-lib -I../subprojects/mctc-lib -I../subprojects/mctc-lib/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -O2 -g -ffree-line-length-none -fbacktrace -fPIC -fopenmp -DWITH_JSON=0 -Jsubprojects/mctc-lib/libmctc-lib.a.p -o subprojects/mctc-lib/libmctc-lib.a.p/src_mctc_io_read_vasp.f90.o -c ../subprojects/mctc-lib/src/mctc/io/read/vasp.f90

nvfortran

nvfortran -Isubprojects/mctc-lib/libmctc-lib.a.p -Isubprojects/mctc-lib -I../subprojects/mctc-lib -I../subprojects/mctc-lib/include -Minform=inform -O2 -g -Mbackslash -Mallocatable=03 -traceback -fPIC -fopenmp -DWITH_JSON=0 -module subprojects/mctc-lib/libmctc-lib.a.p -o subprojects/mctc-lib/libmctc-lib.a.p/src_mctc_io_read_vasp.f90.o -c ../subprojects/mctc-lib/src/mctc/io/read/vasp.f90

But it just failed in the unit test, so I’m looking for help…

Hi lqc33,

Fortran doesn’t use NULL to define the end of a string. Fortran strings have a defined size, though folks often use the “trim” intrinsic to remove trailing whitespace. In C, a char array is an unbounded pointer thus needs the NULL to know where it ends.

I’m not familiar with DFTD4 so unfortunately don’t know what’s wrong. Though I’ve reached out to the engineer on my team that works with VASP to see if he can offer suggestions.

Though if you could post the steps you di to build and run DFTD4, that would be helpful in trying to recreate the issue.

-Mat