Linking CUDA Fortran and gfortran or ifort

Hi,

I have a simple program. I don’t have idea to link the file.
Please help me.

Here is my program and make file.
main.f

	program main
	integer*4 i,j,k
	i=10
	j=5
	call pgfor(i,j,k)
	write(*,*) i,j,k
	end

pgfor.cuf

	subroutine pgfor(a,b,c)
	integer*4 a,b,c
	c=a*b
	end subroutine

makefile

Test: main.f pgfor.o
	ifort main.f pgfor.o
pgfor.o: pgfor.cuf
	pgfortran -c pgfor.cuf
clean:
	rm a.out pgfor.o pgfor.linkinfo

I am getting the following error in this case of ifort
ifort main.f pgfor.o
pgfor.o:(.data+0x0): undefined reference to `pgf90_compiled’
make: *** [Test] Error 1

in case of gfortran
gfortran main.f pgfor.o
pgfor.o:(.data+0x0): undefined reference to `pgf90_compiled’
collect2: ld returned 1 exit status
make: *** [Test] Error 1

in case of pgfortran there is no error.

How to rectify this error?
Please help me.

I have an existing code in ifort. I want to
include some pgfortran code to make it run faster.

regards
panch

I have rectified the things using the following make file.

Test: main.f pgfor.o
	ifort -L /opt/pgi/linux86-64/2011/cuda/4.0/lib64 -lcudart -L /opt/pgi/linux86-64/2011/libso -lcudafor -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgf90rtl -lpgftnrtl  -lpgc main.f pgfor.o
pgfor.o: pgfor.cuf
	pgfortran -c -O3 pgfor.cuf
clean:
	rm a.out pgfor.o pgfor.linkinfo

But right now I am getting the segmentation fault.

Hi Panch,

If you are writing F90 code, constructs such as modules and allocable arrays contain formats that are unique to each compiler vendor. Hence, it is best to compile all F90 code using a single compiler vendor.

For simple F77 code, then you usually can get various compilers working together. However, for CUDA Fortran, Intel and Gfortran compiled objects aren’t compatible. You can try encapsulating the CUDA Fortran code into a library and then write an F77 interface routine, but it would be far simpler to compile all your Fortran source with PGI.

  • Mat