Makefile for CUDA C and fortran codes

I have different fortran source files which i want to link with my CUDA C code.The makefile is as follows:
GOP = nvcc

COP = mpif90 -O3 -axW -ipo

COP = mpif90 -fast -r8

COP = mpif90 -O3 -tpp6 -r8 -static

PROG = ptee.out

DOTO = mod.o
create.o
displace.o
coulomb.o
lj.o
ee.o
erf.o
erfc.o
fourier.o
lrc.o
main.o
newmaxima.o
outfold.o
ran2.o
read.o
real.o
self.o
size.o
store.o
surf.o
weights.o
writedata.o
writehist.o
writeresults.o

(PROG): (DOTO) host.o
(COP) -o (PROG) $(DOTO) host.o -L/usr/local/cuda-2.2/cuda/lib -lcudart

host.o: host.cu
$(GOP) -c -O3 host.cu -l cutil -I/u/ac/vkumar/nvidia_samples/NVIDIA_CUDA-2.2_SDK/common/inc -L /u/ac/vkumar/nvidia_samples/NVIDIA_CUDA-2.2_SDK/lib -lcutil

mod.o: mod.f90
$(COP) -c mod.f90

coulomb.o: coulomb.f90
$(COP) -c coulomb.f90

create.o: create.f90
$(COP) -c create.f90

displace.o: displace.f90
$(COP) -c displace.f90

ee.o: ee.f90
$(COP) -c ee.f90

erf.o: erf.f90
$(COP) -c erf.f90

erfc.o: erfc.f90
$(COP) -c erfc.f90

fourier.o: fourier.f90
$(COP) -c fourier.f90

lj.o: lj.f90
$(COP) -c lj.f90

lrc.o: lrc.f90
$(COP) -c lrc.f90

main.o: main.f90
$(COP) -c main.f90

newmaxima.o: newmaxima.f90
$(COP) -c newmaxima.f90

outfold.o: outfold.f90
$(COP) -c outfold.f90

ran2.o: ran2.f90
$(COP) -c ran2.f90

read.o: read.f90
$(COP) -c read.f90

real.o: real.f90
$(COP) -c real.f90

self.o: self.f90
$(COP) -c self.f90

size.o: size.f90
$(COP) -c size.f90

store.o: store.f90
$(COP) -c store.f90

surf.o: surf.f90
$(COP) -c surf.f90

weights.o: weights.f90
$(COP) -c weights.f90

writedata.o: writedata.f90
$(COP) -c writedata.f90

writehist.o: writehist.f90
$(COP) -c writehist.f90

writeresults.o: writeresults.f90
$(COP) -c writeresults.f90

But when i make this,I get errors like:
host.cu(94): error: this declaration has no storage class or type specifier

host.cu(94): error: declaration is incompatible with “CUTBoolean cutDeleteTimer(unsigned
int)”
/u/ac/vkumar/nvidia_samples/NVIDIA_CUDA-2.2_SDK/common/inc/cutil.h(694): here

host.cu(110): error: this declaration has no storage class or type specifier

host.cu(110): error: declaration is incompatible with “cudaError_t cudaFree(void *)”
/usr/local/cuda-2.2/cuda/bin/…/include/cuda_runtime_api.h(106): here

host.cu(111): error: this declaration has no storage class or type specifier

host.cu(111): error: variable “cudaFree” has already been defined

host.cu(112): error: this declaration has no storage class or type specifier

host.cu(112): error: variable “cudaFree” has already been defined

host.cu(113): error: this declaration has no storage class or type specifier

host.cu(113): error: variable “cudaFree” has already been defined

host.cu(115): error: expected a declaration

What I do is build the Cuda stuff into a library and link the fortran code with the library. Sorta like this:

all: cudastuff fortranstuff

cudastuff:
rm -f lib$(LIBNAME).a #nvcc likes to /append/ to libraries if possible
nvcc (NVCCFLAGS) (CUDAINCLUDE) (CUDALIBS) -lib -o lib(LIBNAME).a ./cudacode/*.cu

fortranstuff:
gfortran (FORTRANFLAGS) -o tc3.run ./tc3/tc3.fpp ./tc3/random.t.f -L. -l(LIBNAME) -lcudart -lcuda

Good luck!

Hi QuantumTroll. Are you using the iso_c_binding module in your Fortran code(s)? If so, how has your experience been with it? Any particular difficulties?

MMB

This is not working.Giving me same errors,can you please tell

GOP = nvcc

COP = mpif90 -O3 -axW -ipo

COP = mpif90 -fast -r8

COP = mpif90 -O3 -tpp6 -r8 -static

LIBNAME = gpu

PROG = ptee.out

DOTO = mod.o \

   create.o         \

   displace.o       \

coulomb.o      \

lj.o          \

   ee.o       \

   erf.o         \

   erfc.o         \

   fourier.o         \

   lrc.o          \

   main.o           \

   newmaxima.o      \

   outfold.o           \

   ran2.o           \

   read.o           \

   real.o           \

   self.o           \

   size.o           \

   store.o          \

   surf.o           \

   weights.o        \

   writedata.o      \

   writehist.o      \

   writeresults.o  

cudastuff:

 $(GOP)-O3 -l cutil -I /u/ac/vkumar/nvidia_samples/NVIDIA_CUDA-2.2_SDK/common/inc -L /u/ac/vkumar/nvidia_samples/NVIDIA_CUDA-2.2_SDK/lib -lcutil -lib -o lib$(LIBNAME).a host.cu

fortranstuff:

$(COP) -o $(PROG) $(DOTO) -L. -l$(LIBNAME) -L /usr/local/cuda-2.2/cuda/lib -lcudart -lcuda

mod.o: mod.f90

$(COP) -c mod.f90

coulomb.o: coulomb.f90

$(COP) -c coulomb.f90

create.o: create.f90

$(COP) -c create.f90

displace.o: displace.f90

$(COP) -c displace.f90

ee.o: ee.f90

$(COP) -c ee.f90

erf.o: erf.f90

$(COP) -c erf.f90

erfc.o: erfc.f90

$(COP) -c erfc.f90

fourier.o: fourier.f90

$(COP) -c fourier.f90

lj.o: lj.f90

$(COP) -c lj.f90

lrc.o: lrc.f90

$(COP) -c lrc.f90

main.o: main.f90

$(COP) -c main.f90

newmaxima.o: newmaxima.f90

$(COP) -c newmaxima.f90

outfold.o: outfold.f90

$(COP) -c outfold.f90

ran2.o: ran2.f90

$(COP) -c ran2.f90

read.o: read.f90

$(COP) -c read.f90

real.o: real.f90

$(COP) -c real.f90

self.o: self.f90

$(COP) -c self.f90

size.o: size.f90

$(COP) -c size.f90

store.o: store.f90

$(COP) -c store.f90

surf.o: surf.f90

$(COP) -c surf.f90

weights.o: weights.f90

$(COP) -c weights.f90

writedata.o: writedata.f90

$(COP) -c writedata.f90

writehist.o: writehist.f90

$(COP) -c writehist.f90

writeresults.o: writeresults.f90

$(COP) -c writeresults.f90

Let me frame my question again.I want to compile MPI fortran codes with my CUDA C codes.Only one source file calls the CUDA kernel.People have done that for C language,what about compiling fortran codes and CUDA C with MPI ?