This is absolutely confusing!
-
I’m putting a temporary hold on the WSL project. WSL is being wonky at the moment.
-
Windows with Fortran/C++. I am making a little bit of progress. Here is a Fortran subroutine, a C++ subroutine that compiles nicely with gfortran/g++ and works on R.
subroutine fpsub1(a,b)
real a,b
a=1.0
b=2.0
call cppfunction(a,b)
end subroutine fpsub1
extern “C” {
void cppfunction_(float *a, float *b);
}
void cppfunction_(float *a, float *b) {
*a=5.0;
*b=6.0;
}
C:\updateR>gfortran -c fpsub1.f90 -o fpsub1.o -fPIC
C:\updateR>g++ -c cppfunction.cpp -o cppfunction.o
C:\updateR>gfortran -shared -o fpsub1.dll fpsub1.o cppfunction.o -lstdc++
Now run in R:
dyn.load(“fpsub1.dll”)
.Fortran(“fpsub1”,a=as.single(0.0),b=as.single(0.0))
$a
[1] 5
attr(,“Csingle”)
[1] TRUE
$b
[1] 6
attr(,“Csingle”)
[1] TRUE
So far so good.
Now I put a little OpenACC in
subroutine fnvsub1(a,b,x,n)
!DEC$ ATTRIBUTES DLLEXPORT :: fnvsub1
implicit none
real :: a,b,x(n)
integer :: n, i
a=1.0
b=2.0
call cppfunction(a,b)
!$acc parallel
do i=1,n
x(i) = 2*i + 1
enddo
!$acc end parallel
end subroutine fnvsub1
I used the same cppfunction.
But the pgfortran is balking in the linking:
C:\updateR>pgfortran -c -acc -Minfo=accel fnvsub1.90 -ta=tesla:nordc,cuda10.1 -o fnvsub1.obj
C:\updateR>g++ -c cppfunction.cpp -o cppfunction.o
C:\updateR>pgfortran -o fnvsub1.dll fnvsub1.obj cppfunction.o -acc -Minfo=accel -ta=tesla:nordc,cuda10.1
Creating library fnvsub1.lib and object fnvsub1.exp
f90main.obj : error LNK2019: unresolved external symbol MAIN_ referenced in function main
fnvsub1.dll : fatal error LNK1120: 1 unresolved externals
./fnvsub1.exf: error STP001: cannot open file
C:\updateR>pgfortran -o fnvsub1.dll fnvsub1.obj cppfunction.o -acc -Minfo=accel -ta=tesla:nordc,cuda10.1 -lstdc++
LINK : fatal error LNK1104: cannot open file ‘libstdc++.lib’
./fnvsub1.exf: error STP001: cannot open file
I have a feeling that I'm really close...
Thanks.