Undefined reference to MAIN_" error using nvfortran

i faced this error while compiling the code with nvfortran :
nvfortran -o calcul_aladin_gpu.o -g -lcudart calcul_aladin_gpu.cuf
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o : dans la fonction « MAIN_ » :
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:90 : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x3a) : référence indéfinie vers « modd_diag_param_1 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x4d) : référence indéfinie vers « modd_diag_param_1 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x65) : référence indéfinie vers « modd_diag_param_1 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x7d) : référence indéfinie vers « modd_diag_param_1 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x95) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0xa8) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0xbd) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0xd3) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0xe9) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0xff) : encore plus de références indéfinies suivent vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x115) : référence indéfinie vers « modd_diag_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x128) : référence indéfinie vers « modd_diag_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x140) : référence indéfinie vers « modd_diag_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x1d3) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x1e6) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x1fd) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x215) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x22d) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x245) : encore plus de références indéfinies suivent vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x3a0) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x3b3) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x3ca) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x3e1) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x3f8) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortrantG_d5WEKSaX7.o:(.debug_info+0x40f) : référence indéfinie vers « modd_site_param_1 »
pgacclnk: child process exit status 1: /usr/bin/ld
make: *** [Makefile:46 : cuda] Erreur 2

here is my makefile :
FC= mpiifort

FFLAGS= -v -fp-stack-check -shared-intel -mcmodel large -g3
MYLIB= LIBROUTE.a
home1 = /media/sarah/HP x755w/
LIBDIR= $(home1)/ROUTE/lib
MODDIR= $(home1)/ROUTE/include

MODSRC= modd_config.F90 modd_const_grid.F90 modd_namel_config.F90
modd_site_param.F90 modd_model_param.F90 modd_diag_param.F90

SUBRSRC= subp.F90 read_namel_config.F90 read_aladin_prev.F90 read_arome_prev.F90
read_dust_prev.F90 interpol_aladin_prev.F90 interpol_arome_prev.F90
interpol_dust_prev.F90 interpol_nebul_ald_prev.F90 interpol_nebul_aro_prev.F90
calcul_meteo_prev.F90 calcul_meteo_aro_prev.F90 write_meteo_param.F90
MASTERSRC= prev_route.F90
CUDA = calcul_aladin_gpu.cuf

MODOBJ= $(MODSRC:.F90=.o)
MODMOD= $(MODSRC:.F90=.mod)
SUBROBJ= $(SUBRSRC:.F90=.o)
MASTEROBJ= $(MASTERSRC:.F90=.o)
SUBR_CUDAOBJ= $(CUDA: .cuf=.o)

#RPT= $(SRC:.F90=.optrpt)
EXE= PREV_ROUTE
CLEAN+= $(MODOBJ) $(MODMOD) $(SUBROBJ) $(MASTEROBJ) $(MYLIB) $(EXE)
#MOD= *.mod
#SMOD= *.smod

.SUFFIXES:
.SUFFIXES: .F90 .o .x

#build: $(OBJ)

$(MODMOD) $(OBJ) $(EXE)

module:
$(FC) $(FFLAGS) -c $(MODSRC)

cudamodule :
nvfortran -c -g -m64 $(MODSRC)

cuda :
nvfortran -o calcul_aladin_gpu.o -g -lcudart $(CUDA)

#ar -cvq $(MYLIB) $(MODOBJ)

subr:
$(FC) $(FFLAGS) -c $(SUBRSRC)

master:
$(FC) $(FFLAGS) -c $(MASTERSRC)

all:
$(FC) $(FFLAGS) -c $(MODSRC) $(SUBRSRC) $(MASTERSRC)
#.F90.o:

$(FC) $(FFLAGS) $< $(OBJ)

#.o.x:
#exe:

$(FC) $(FFLAGS) -o $(EXE) $(MODOBJ) $(SUBROBJ) $(MASTEROBJ)

libss:
ar crs $(MYLIB) $(MODOBJ) $(SUBROBJ) $(SUBR_CUDAOBJ)

exe:
$(FC) $(FFLAGS) $(MASTEROBJ) $(MYLIB) -g3 -O0 -o PREV_ROUTE -lmpifort $(SUBR_CUDAOBJ) #mpiifort prev_route.F90 lib/LIBROUTE.a -o PREV_ROUTE_LIB

clean:
\rm -f $(CLEAN)

and here is my code : `
module calcul_ald_gpu
use cudafor
implicit none

contains 
  attributes(global) subroutine kernel_calcul(ZPFIELD)

  
  integer :: J , iSta ,JPRD
  integer :: NECMAX ,  NSTA ,NTRANCHE
!   integer :: 
  REAL:: ZPFIELD(:,:,:)

!   nbgn = NPRD_BEGN_PREV_d(JPRD_d);
!   nend = NPRD_END_PREV_d(JPRD_d);
!   mdl = NPRD_MDL_PREV_d(JPRD_d);
       

  
   J = blockDim%x * (blockIdx%x - 1) + threadIdx%x


   if (J .le. (NSTA * NTRANCHE)) then          ! GRILLE ALADIN
     

     iSta = modulo(J, NSTA);  ! ista == tronçon
     JPRD= J / NSTA;         !JPRD_d == periode


     print *, "J From GPU", J
     print *, "ZPFIELD", ZPFIELD(iSta, JPRD, 1)
    
!   !   temerature maximale
  
     
!      TMX_d(ista)=-50.0
!      TMN_d(ista)=70.0 
!      T2MX_d(ista)=-50.0

    
!     ZDIAG_d(ista,1,JPRD_d) = max(TMX_d(ista), ZPFIELD_d(ista, iPrd, 1) - 273.15)
!     TMX_d(ista)=  ZDIAG_d(ista,1,JPRD_d)
  
  
   endif

end subroutine kernel_calcul
end module calcul_ald_gpu

PROGRAM CALCUL_METEO_PREV_GPU

!
USE MODD_MODEL_PARAM, ONLY : ZPFIELD,ZPFIELD_DST

   USE MODD_CONFIG, ONLY : NTRANCHE,NPARR,NPARC,NPARD,NPHENO,NPALD,NECMAX,NPDST
  USE MODD_DIAG_PARAM, ONLY :PPARAM_PREV,CPARAM_PREV,    &
 & NPRD_BEGN_PREV,NPRD_END_PREV,NPRD_MDL_PREV,NEBUL1,NEBUL2,NEBUL3, &   
 & CCIEL
   USE MODD_SITE_PARAM, ONLY :NSTA,PLAT,PLON
   USE calcul_ald_gpu
   USE cudafor

! USE MODD_VIGI_SEUIL_PARAM
!
IMPLICIT NONE
!
!!!
! DIAGNOSTICS PARAMETERS

     REAL, DIMENSION(NSTA) :: TMX1,TMN1,TMX2,TMN2
    REAL, DIMENSION(NSTA) :: TEMP,T2M,TMX,TMN,T2MX,HUM,HUMX,ZWIND, &   
 &   ZWINDX,ZWINDRX,PORAGX,ZNEBUL,TOTT,PCAPE,PORAG,ZWINDR,CON,    &
 &   PMSLPX,ZNEBHX,ZNEBMX,ZNEBBX,ZNEBULX,VIS_MIN,VISMN,ZCIEL,     &
 &   PNEIGE,ZCLOUD,ZNEBH,ZNEBM,ZNEBB,PMSLP 
    REAL, DIMENSION(NSTA) :: ZSRC_DST,ZWIND_DST                 
    INTEGER, DIMENSION(NSTA) ::INEBUL
    CHARACTER(LEN=3),DIMENSION(NSTA,NPARC,NTRANCHE) ::CDIAG

     REAL PII,PHI,T85,T50,RH85,PWS,PW,TD85,VV,VV1,VV2,TT,TT1,PINVV
    INTEGER I,J,K,JPRD,NBGN,NEND,MDL,ISTA,NCOM,ip,iec




real, dimension(NSTA, NPALD, NECMAX), device :: ZPFIELD_d
!integer,device :: NSTA_d ,NTRANCHE,NECMAX 
type(dim3) :: blockDim , gridDim




ZPFIELD_d = ZPFIELD

blockDim = dim3(256,1,1)
gridDim = dim3(((NSTA * NTRANCHE + blockDim%x - 1) / blockDim%x),1,1)

call kernel_calcul <<< gridDim, blockDim >>> (ZPFIELD_d)

END PROGRAM CALCUL_METEO_PREV_GPU`

Hi chs33717,

Looks like you forgot to add the “-c” flag to tell the compiler to only compile the file and not link. You use it elsewhere, but it’s missing for the “cuda” rule.

Hope this helps,
Mat

We have the main program written in Fortran-MPI and compiled using mpiifort. After the MPI processors finish their work, they transfer data to the master process (iproc==0) using a 3D array. The master process then calls a subroutine written in CUDA. This subroutine’s kernel utilizes the 3D array.
There are modules shared between the CUDA subroutine , other subroutines, and the main program.

what compiler should i use for these shared modules?
case 1 :
when i compile the modules using mpiifort with the command ‘make modules’. then i compile the CUDA code using ‘make cuda’, an error occurs:

sarah@sarah-VivoBook-ASUSLaptop-X509JB-X509JB:/media/sarah/HP x755w/ROUTE/ROUTE/src$ make cuda
nvfortran -o calcul_aladin_gpu.o -lcudart calcul_aladin_gpu.cuf
NVFORTRAN-F-0004-Corrupt or Old Module file ./modd_config.mod (calcul_aladin_gpu.cuf: 63)
NVFORTRAN/x86-64 Linux 24.3-0: compilation aborted
make: * [Makefile:41 : cuda] Erreur 2

case 2 :
Additionally, when compiling the modules using nvfortran with ‘make cudamodules’ , the ‘make cuda’ works without errors but when i compile the subroutines using mpiifort, the following error occurs:

/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:90 : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x3a) : référence indéfinie vers « modd_diag_param_1 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x4d) : référence indéfinie vers « modd_diag_param_1 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x65) : référence indéfinie vers « modd_diag_param_1 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x7d) : référence indéfinie vers « modd_diag_param_1 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x95) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0xa8) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0xbd) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0xd3) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0xe9) : référence indéfinie vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0xff) : encore plus de références indéfinies suivent vers « modd_diag_param_8 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x115) : référence indéfinie vers « modd_diag_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x128) : référence indéfinie vers « modd_diag_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x140) : référence indéfinie vers « modd_diag_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x1d3) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x1e6) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x1fd) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x215) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x22d) : référence indéfinie vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x245) : encore plus de références indéfinies suivent vers « modd_model_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x3a0) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x3b3) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x3ca) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x3e1) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x3f8) : référence indéfinie vers « modd_site_param_0 »
/usr/bin/ld : /tmp/nvfortranC0DguhgFGxdr.o:(.debug_info+0x40f) : référence indéfinie vers « modd_site_param_1 »
pgacclnk: child process exit status 1: /usr/bin/ld
make: * [Makefile:46 : cuda] Erreur 2

Modules aren’t compatible between different Fortran compilers. You’ll need to switch to compiling all Fortran code using a MPI that’s built with nvfortran.

We ship several with the NVHPC SDK, OpenMPI 3.1.5, OpenMPI 4.1.5, and HPC-X, with HPC-X being the default. You can find these in your NVHPC install under the “Linux_x86_64/24.3/comm_libs/” directory.

i did try the openmpi but i an error while running make exe :
mpifort -g -c -lmpi -v -I/media/sarah/HP x755w//ROUTE/include -c prev_route.o
Export NVCOMPILER=/opt/nvidia/hpc_sdk/Linux_x86_64/24.3
Export PGI=/opt/nvidia/hpc_sdk
mpifort -g -c -lmpi -v -I/media/sarah/HP x755w//ROUTE/include -o PREV_ROUTE modd_config.o modd_const_grid.o modd_namel_config.o modd_site_param.o modd_model_param.o modd_diag_param.o subp.o read_namel_config.o read_aladin_prev.o read_arome_prev.o read_dust_prev.o interpol_aladin_prev.o interpol_arome_prev.o interpol_dust_prev.o interpol_nebul_ald_prev.o interpol_nebul_aro_prev.o calcul_meteo_prev.o calcul_meteo_aro_prev.o write_meteo_param.o prev_route.o LIBROUTE.a
-L/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi4/bin
calcul_aladin_gpu.o \
Export NVCOMPILER=/opt/nvidia/hpc_sdk/Linux_x86_64/24.3
Export PGI=/opt/nvidia/hpc_sdk
L/usr/local/cuda/lib64 -Wl,–rpath=/usr/local/cuda/lib64 -lcudart
-lmpi
make: L/usr/local/cuda/lib64: Aucun fichier ou dossier de ce nom
make: [Makefile:76 : exe] Erreur 127 (ignorée)

here is the makefile code :

FC= mpifort

FFLAGS=  -g -c -lmpi -v  
MYLIB= LIBROUTE.a
home1 = /media/sarah/HP x755w/
LIBDIR= $(home1)/ROUTE/lib
MODDIR= $(home1)/ROUTE/include


MODSRC= modd_config.F90 modd_const_grid.F90 modd_namel_config.F90 \
        modd_site_param.F90 modd_model_param.F90 modd_diag_param.F90

SUBRSRC= subp.F90 read_namel_config.F90 read_aladin_prev.F90 read_arome_prev.F90 \
        read_dust_prev.F90 interpol_aladin_prev.F90 interpol_arome_prev.F90 \
        interpol_dust_prev.F90 interpol_nebul_ald_prev.F90 interpol_nebul_aro_prev.F90 \
        calcul_meteo_prev.F90 calcul_meteo_aro_prev.F90  write_meteo_param.F90 
MASTERSRC= prev_route.F90
CUDA = calcul_aladin_gpu.cuf


MODOBJ=    $(MODSRC:.F90=.o)
MODMOD=    $(MODSRC:.F90=.mod)       	
SUBROBJ=   $(SUBRSRC:.F90=.o)
MASTEROBJ= $(MASTERSRC:.F90=.o)	
SUBR_CUDAOBJ=   $(CUDA: .cuf=.o)
	
#RPT= $(SRC:.F90=.optrpt)
EXE= PREV_ROUTE
CLEAN+= $(MODOBJ) $(MODMOD) $(SUBROBJ) $(MASTEROBJ) $(MYLIB) $(EXE)
#MOD= *.mod
#SMOD= *.smod

.SUFFIXES:
.SUFFIXES:      .F90 .o .x

#build: $(OBJ)
#       	$(MODMOD) $(OBJ) $(EXE)
module:
	 $(FC) $(FFLAGS) -c $(MODSRC) L/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi4/bin \
          -lmpi 
	

cudamodule :
	nvfortran -c -g -m64 $(MODSRC) 
	
cuda : 
	nvfortran -c -g -m64 calcul_aladin_gpu.cuf -L/usr/local/cuda/lib64 -Wl,--rpath=/usr/local/cuda/lib64 -lcudart -lmodd_model_param -lmodd_diag_param -lmodd_site_param -lmodd_config -lmodd_const_grid -lmodd_namel_config
	

# mpiifort -c -g -m64 calcul_aladin_gpu.cuf -L/usr/local/cuda/lib64 -Wl,--rpath=/usr/local/cuda/lib64 -lmodd_model_param -lmodd_diag_param -lmodd_site_param -lmodd_config -lmodd_const_grid -lmodd_namel_config 
    
#ar -cvq $(MYLIB) $(MODOBJ)

subr:	
	$(FC) $(FFLAGS) -I$(MODDIR) -c $(SUBRSRC) L/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi4/bin \
          -lmpi 

master:
	$(FC) $(FFLAGS) -c  $(MASTERSRC)  L/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi4/bin  -lmpi

all: 	
	$(FC) $(FFLAGS) -c $(MODSRC) $(SUBRSRC) $(MASTERSRC) L/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi4/bin  -lmpi
#.F90.o: 
#	$(FC) $(FFLAGS) $< $(OBJ)	
#.o.x:
#exe:
#	$(FC) $(FFLAGS) -o $(EXE) $(MODOBJ) $(SUBROBJ) $(MASTEROBJ)

libss:
	ar crs $(MYLIB) $(MODOBJ) $(SUBROBJ) 

exe:
# $(FC) $(FFLAGS) $(MASTEROBJ) $(MYLIB) -g3 -O0 -o PREV_ROUTE -lmpifort calcul_aladin_gpu.o -lcudart 
	$(FC) $(FFLAGS) -I$(MODDIR) -c prev_route.o  
	$(FC) $(FFLAGS) -I$(MODDIR) -o $(EXE) $(MODOBJ) $(SUBROBJ) $(MASTEROBJ) $(MYLIB) \
	-L/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi4/bin \
	calcul_aladin_gpu.o \ 
	-L/usr/local/cuda/lib64 -Wl,--rpath=/usr/local/cuda/lib64 -lcudart \
	-lmpi 


clean: 
	\rm -f $(CLEAN)





You’re missing the dash, “-”, before the “L”. “-L” sets the path to look for a library while just “L” gets interrupted as a filename, which is why you get the error “Aucun fichier ou dossier de ce nom” (translated as “No file or folder of that name”).

Note the “bin” directory here doesn’t contain any libraries so adding it is extraneous. Also, the mpifort driver will implicitly include the MPI library on the link line, so the “-lmpi” isn’t needed either. Finally, since “-c” is being used, you’re only compiling the files, not linking, so adding libraries to this line doesn’t do anything.

I’d recommend removing both from the make rule. Something like:

module:
	 $(FC) $(FFLAGS) -c $(MODSRC)

Change the other build rules as well.

For the link rule, i.e. “exe”, again the library path to the bin directory doesn’t do anything.

Also, I’d remove the the CUDA library paths and libraries from the link and instead add “-cuda”. The compiler will implicitly add the required CUDA libraries by default, and ensure the correct version is being used. Plus you’re missing several libraries so would likely get undefined reference errors when you link. Use “-cuda” will fix this.

Thank you so much for the answer. I have another issue: I ran the Makefile, and it compiled successfully (here is the output):

rm -f modd_config.o modd_const_grid.o modd_namel_config.o modd_site_param.o modd_model_param.o modd_diag_param.o subp.o read_namel_config.o read_aladin_prev.o read_arome_prev.o read_dust_prev.o interpol_aladin_prev.o interpol_arome_prev.o interpol_dust_prev.o interpol_nebul_ald_prev.o interpol_nebul_aro_prev.o calcul_meteo_prev.o calcul_meteo_aro_prev.o write_meteo_param.o prev_route.o   LIBROUTE.a PREV_ROUTE modd_config.mod modd_const_grid.mod modd_namel_config.mod modd_site_param.mod modd_model_param.mod modd_diag_param.mod                
mpifort  -g -c  -I/media/sarah/HP x755w/ /ROUTE/include -I/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi/openmpi-3.1.5/include -c modd_config.F90 modd_const_grid.F90 modd_namel_config.F90 modd_site_param.F90 modd_model_param.F90 modd_diag_param.F90
modd_config.F90:
modd_const_grid.F90:
modd_namel_config.F90:
modd_site_param.F90:
modd_model_param.F90:
modd_diag_param.F90:
mpifort  -g -c  -I/media/sarah/HP x755w/ /ROUTE/include -I/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi/openmpi-3.1.5/include -c subp.F90 read_namel_config.F90 read_aladin_prev.F90 read_arome_prev.F90 read_dust_prev.F90 interpol_aladin_prev.F90 interpol_arome_prev.F90 interpol_dust_prev.F90 interpol_nebul_ald_prev.F90 interpol_nebul_aro_prev.F90 calcul_meteo_prev.F90 calcul_meteo_aro_prev.F90 write_meteo_param.F90 
subp.F90:
read_namel_config.F90:
read_aladin_prev.F90:
read_arome_prev.F90:
read_dust_prev.F90:
interpol_aladin_prev.F90:
interpol_arome_prev.F90:
interpol_dust_prev.F90:
interpol_nebul_ald_prev.F90:
interpol_nebul_aro_prev.F90:
calcul_meteo_prev.F90:
calcul_meteo_aro_prev.F90:
write_meteo_param.F90:
mpifort  -g -c  -I/media/sarah/HP x755w/ /ROUTE/include -I/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi/openmpi-3.1.5/include -c prev_route.F90
prev_route.F90:
ar crs LIBROUTE.a modd_config.o modd_const_grid.o modd_namel_config.o modd_site_param.o modd_model_param.o modd_diag_param.o subp.o read_namel_config.o read_aladin_prev.o read_arome_prev.o read_dust_prev.o interpol_aladin_prev.o interpol_arome_prev.o interpol_dust_prev.o interpol_nebul_ald_prev.o interpol_nebul_aro_prev.o calcul_meteo_prev.o calcul_meteo_aro_prev.o write_meteo_param.o
mpifort  -g -c  -I/media/sarah/HP x755w/ /ROUTE/include -I/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi/openmpi-3.1.5/include -o PREV_ROUTE prev_route.o       LIBROUTE.a calcul_aladin_gpu.cuf -L/opt/nvidia/hpc_sdk/Linux_x86_64/24.3/comm_libs/openmpi/openmpi-3.1.5/lib -lmpi -L/usr/local/cuda/lib64 -Wl,--rpath=/usr/local/cuda/lib64 -lcudart
calcul_aladin_gpu.cuf

However, when I try to execute the executable file, I encounter the following:

sarah@sarah-VivoBook-ASUSLaptop-X509JB-X509JB:/media/sarah/HP x755w/ROUTE/ROUTE/src$ mpirun -np 4  ./PREV_ROUTE
--------------------------------------------------------------------------
Open MPI tried to fork a new process via the "execve" system call but
failed.  Open MPI checks many things before attempting to launch a
child process, but nothing is perfect. This error may be indicative
of another problem on the target host, or even something as silly as
having specified a directory for your application. Your job will now
abort.
  Local host:        sarah-VivoBook-ASUSLaptop-X509JB-X509JB
  Working dir:       /media/sarah/HP x755w/ROUTE/ROUTE/src
  Application name:  ./PREV_ROUTE
  Error:             Exec format error
--------------------------------------------------------------------------
--------------------------------------------------------------------------
mpirun was unable to start the specified application as it encountered an
error:

Error code: 1
Error name: (null)
Node: sarah-VivoBook-ASUSLaptop-X509JB-X509JB

when attempting to start process rank 0.
--------------------------------------------------------------------------
4 total processes failed to start
[sarah-VivoBook-ASUSLaptop-X509JB-X509JB:40381] 3 more processes have sent help message help-orte-odls-default.txt / execve error
[sarah-VivoBook-ASUSLaptop-X509JB-X509JB:40381] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages

Your link line includes the “-c” flag which tells the compiler to only compile the file, not link it. Hence the generated “PREV_ROUTE” is an object file not an executable, hence the “Exec format error”.

What I’d recommend is to change your makefile variables to be something like:

OPT = -g
FFLAGS=  $(OPT) -c
LDFLAGS = $(OPT)
...
exe:
	$(FC) $(LDLAGS) -I$(MODDIR) -o $(EXE) $(MODOBJ) $(SUBROBJ) $(MASTEROBJ) $(MYLIB) calcul_aladin_gpu.o

Note that I took out the “$(FC) $(FFLAGS) -I$(MODDIR) -c prev_route.o” line from the “exe” rule since it doesn’t make sense to compile an object file since object files are already compiled (it doesn’t hurt but just doesn’t do anything). Though if the intent is for “prev_route” to be a source file (i.e. “.c”, “.f90”, “.cpp”, etc.), then add it back with the corrected file suffix.

after changing the exe , i’ve got this error :

mpifort  -g -o PREV_ROUTE modd_config.o modd_const_grid.o modd_namel_config.o modd_site_param.o modd_model_param.o modd_diag_param.o subp.o read_namel_config.o read_aladin_prev.o read_arome_prev.o read_dust_prev.o interpol_aladin_prev.o interpol_arome_prev.o interpol_dust_prev.o interpol_nebul_ald_prev.o interpol_nebul_aro_prev.o calcul_meteo_prev.o calcul_meteo_aro_prev.o write_meteo_param.o prev_route.o LIBROUTE.a calcul_aladin_gpu.o
calcul_meteo_prev.o: in the function "calcul_meteo_prev_":
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:751: (.text+0x46d3): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:752: (.text+0x471a): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:753: (.text+0x4761): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:754: (.text+0x47a8): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:755: (.text+0x47ef): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:756: (.text+0x4836): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:757: (.text+0x487d): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:758: (.text+0x48c4): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:759: (.text+0x490b): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:760: (.text+0x493c): truncated relocation to fit: R_X86_64_32S against symbol "modd_diag_param_0_" defined in COMMON section in modd_diag_param.o
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_meteo_prev.F90:761: additional relocation overflow omitted from output
/usr/bin/ld: calcul_aladin_gpu.o: in the function "calcul_ald_gpu_kernel_calcul_":
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:6: undefined reference to "__pgiLaunchKernelFromStub"
/usr/bin/ld: calcul_aladin_gpu.o: in the function "calcul_meteo_prev_gpu_":
/media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:49: undefined reference to "pgf90_dev_auto_alloc04_i8"
/usr/bin/ld: /media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:89: undefined reference to "pgf90_dev_copyin"
/usr/bin/ld: /media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:94: undefined reference to "pgf90_dev_mkdesc"
/usr/bin/ld: /media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:94: undefined reference to "__pgiLaunchKernel"
/usr/bin/ld: /media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:94: undefined reference to "pgf90_dev_auto_dealloc_i8"
/usr/bin/ld: /media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:101: undefined reference to "pgf90_dev_auto_dealloc_i8"
/usr/bin/ld: /media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:101: undefined reference to "__pgi_cuda_register_fat_binaryA"
/usr/bin/ld: /media/sarah/HP x755w/ROUTE/ROUTE/src/calcul_aladin_gpu.cuf:101: undefined reference to "__cudaRegisterFunction"
make: *** [Makefile:552: exe] Error 2

This typically means that you have a static object that’s greater than 2GB in memory size so will need to use the medium memory model by adding the flag “-mcmodel=medium”. This should be added to both the compilation and link flags and all source should be recompiled.

undefined reference to “__pgiLaunchKernelFromStub”

These are references in the CUDA Fortran runtime libraries which isn’t included by default. To fix, add the “-cuda” flag to your link flag. “-cuda” will then automatically include all need CUDA runtime libraries.