Hello everyone, as the title shows, fortran write MPI parallel program, part of the program I rewritten into cudaFortran program running on the GPU, .cuf, then compile, use mpif90 to compile mpifortran program, pgf90 compile to compile cudafortran program, There is no problem compiling, but the link fails. I want to know how to implement MPI+cudafortran hashing.
The procedure is as follows:
!--------------------------------------------------------
program hello_world
include 'mpif.h'
integer ierr,num_procs,myid
integer a(2,2),b(2),c(2)
a=2
b=1
c=0
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,num_procs,ierr)
print*,"Hello world!I'm process",myid,"out of",
& num_procs,"processes."
call add(a,b,c)
if(myid.eq.0)then
print*,'c=',c(1),c(2)
endif
call MPI_FINALIZE(ierr)
end program hello_world
----------------------------------------------------------------------------
subroutine add(a,b,c)
use cudafor
use a_m
implicit none
integer a(2,2),b(2),c(2)
integer,device::a_d(2,2),b_d(2),c_d(2)
a_d=a
b_d=b
c_d=c
call add1<<<1,2>>>(a_d,b_d,c_d)
a=a_d
b=b_d
c=c_d
end subroutine add
-------------------------------------------------------------------
module a_m
use cudafor
contains
attributes(global) subroutine add1(a_d,b_d,c_d)
implicit none
integer,device::a_d(2,2)
integer,device::b_d(2)
integer,device::c_d(2)
integer ii
ii=threadIdx%x
if(ii.le.2)then
c_d(ii)=a_d(ii,ii)*b_d(ii)
endif
return
end subroutine add1
end module a_m
--------------------------------------------------------------
makefile:
CUDA_INSTALL_PATH=/home/myfan/PGI/linux86-64/18.4
MPI_INSTALL_PATH=/opt/mpich2-1.4.1p1
PGF90=$(CUDA_INSTALL_PATH)/bin/pgf90
MPIF90=$(MPI_INSTALL_PATH)/bin/mpif90
LDFLAGS= -L$(CUDA_INSTALL_PATH)/lib
LIB=
FFILES=hello_world.f90
CUFILES=a_m.cuf add.cuf
OBJECTS=hello_world.o a_m.o add.o
EXENAME= test.x
ALL:
$(MPIF90) -c $(FFILES)
$(PGF90) -c $(CUFILES)
$(MPIF90) -o $(EXENAME) $(LDFLAGS) $(LIB) $(OBJECTS)
CLEAN:
rm -f *.o $(exename) *.mod
Compile without problems, link out the problem:
a_m.o: In function a_m_add1_': a_m.cuf:(.text+0x32): undefined reference to
cudaSetupArgumentâ
a_m.cuf:(.text+0x47): undefined reference to cudaSetupArgument' a_m.cuf:(.text+0x5c): undefined reference to
cudaSetupArgumentâ
a_m.cuf:(.text+0x68): undefined reference to cudaLaunch' a_m.o: In function
__âŠacc_cuda_funcreg_constructor_1ENDâ:
a_m.cuf:(.text+0xb8): undefined reference to __pgi_cuda_register_fat_binary' a_m.cuf:(.text+0x10c): undefined reference to
cudaRegisterFunctionâ
a_m.o: In function .STATICS4': a_m.cuf:(.data+0x110): undefined reference to
cudadeviceâ
a_m.cuf:(.data+0x118): undefined reference to cudafor_' a_m.cuf:(.data+0x120): undefined reference to
iso_c_bindingâ
a_m.cuf:(.data+0x128): undefined reference to pgi_acc_common_' a_m.o:(.init+0xb): undefined reference to
Mcuda_compiledâ
add.o: In function add_': (.text+0x2a): undefined reference to
pgf90_dev_auto_alloc04â
add.o: In function add_': (.text+0x3f): undefined reference to
pgf90_dev_auto_alloc04â
add.o: In function add_': (.text+0x54): undefined reference to
pgf90_dev_auto_alloc04â
add.o: In function add_': /home/myfan/test/mpi/./add.cuf:7: undefined reference to
pgf90_dev_copyinâ
/home/myfan/test/mpi/./add.cuf:7: undefined reference to pgf90_dev_copyin' /home/myfan/test/mpi/./add.cuf:7: undefined reference to
pgf90_dev_copyinâ
/home/myfan/test/mpi/./add.cuf:7: undefined reference to __pgiLaunchKernel' /home/myfan/test/mpi/./add.cuf:7: undefined reference to
pgf90_dev_copyoutâ
/home/myfan/test/mpi/./add.cuf:7: undefined reference to pgf90_dev_copyout' /home/myfan/test/mpi/./add.cuf:7: undefined reference to
pgf90_dev_copyoutâ
/home/myfan/test/mpi/./add.cuf:7: undefined reference to pgf90_dev_auto_dealloc' /home/myfan/test/mpi/./add.cuf:7: undefined reference to
pgf90_dev_auto_deallocâ
/home/myfan/test/mpi/./add.cuf:7: undefined reference to pgf90_dev_auto_dealloc' add.o: In function
.C1_379â:
add.cuf:(.data+0x28): undefined reference to cudafor_' add.cuf:(.data+0x38): undefined reference to
iso_c_binding_â
add.cuf:(.data+0x40): undefined reference to pgi_acc_common_' add.cuf:(.data+0x48): undefined reference to
f90_compiledâ
add.o:(.init+0x1): undefined reference to `Mcuda_compiledâ
make: *** [ALL] Error 1
It should be a problem with lib. I didnât put the lib library in my makefile. But which library should be linked specifically, how to get it or not, I want to ask.
And Can someone give me a reference Makefile?