Compiling OpenACC and Fortran for R on Windows

Hello!
I have a small Fortran subroutine with OpenACC statements. I would like to compile this as a DLL to be used in R (on Windows 10). Here is the code:

subroutine test2(y,n)
real x(1000),y(1000)
integer n,i


open(file=“buzz.txt”,unit=1)
do i = 1,n
read(1,*)x(i)
enddo

!$acc kernels
do i=1,n
y(i) = x(i) + 5.0
enddo
!$acc end kernels

end subroutine test2

I have tried all kinds of options with pgf90, but I keep getting the error message that the program does not work with Windows or is compiled incorrectly.

Any suggestions much appreciated.
Thanks,
Erin

Hi Erin,

What are the error messages that you are seeing? In general you should add the !DEC$ ATTRIBUTES DLLEXPORT :: to the routine you’d like to export, and from there specify the -Mmakedll option.

My program will compile. But when I use “dyn.load(‘test2.dll’)” in R, I get the “Not a Win32 application” error

Thanks,
Erin

I added the statement that you suggested.

Here are the results.


pgf90 -acc -c test2.f90 -o test2.o
PGI$ pgf90 -acc -Mmakedll test2.o -o test2.dll
Creating library test2.lib and object test2.exp
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_enter referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_dataenterstart referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_dataonb referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_dataenterdone referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_computestart referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_launch referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_computedone referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_dataexitstart referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_dataoffb2 referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_dataexitdone referenced in function test2
test2.o : error LNK2019: unresolved external symbol _pgi_uacc_noversion referenced in function test2
test2.dll : fatal error LNK1120: 11 unresolved externals

Thanks,
Erin

Hi Erin,

The OpenACC runtime libraries don’t get implicitly added with “-Mmakedll” so you need to include them by hand. Plus just like shard objects on Linux, you need to compile with “nordc”.

For example:

 PGGI$ pgf90 -acc -Mmakedll test.obj -o test.dll -ta=tesla:nordc  "$PGI/win64/18.1/lib/acc_init_link_cuda.obj" "$PGI/win64/18.1/lib/libaccapi.lib" "$PGI/win64/18.1/lib/libaccg.lib" "$PGI/win64/18.1/lib/libaccn.lib" "$PGI/win64/18.1/lib/libaccg2.lib" "$PGI/win64/18.1/lib/libcudadevice.lib" "$PGI/win64/18.1/lib/pgc14.lib" "$PGI/win64/18.1/lib/libnspgc.lib" -defaultlib:legacy_stdio_definitions -defaultlib:oldnames
   Creating library test.lib and object test.exp

Hello again!

I got things to compile, thanks to Mat.

The dyn.load in R works. But now I’m getting:
Accelerator Fatal Error: No CUDA device code available

What am I doing wrong now?

Here are the compile/link statements:
pgf90 -acc -c test2.f90 -o test2.obj -Lc:/progra~1/PGICE/win64/18.4/lib/pgc14.dll -Lc:/progra~1/PGICE/win64/18.4/
lib/pgf90.dll
PGI$ pgf90 -acc -Mmakedll test2.obj -o test2.dll -ta=tesla:nordc “$PGI/win64/18.4/lib/acc_init_link_cuda.obj” “$PGI/wi
n64/18.4//lib/libaccapi.lib” “$PGI/win64/18.4/lib/libaccg.lib” “$PGI/win64/18.4/lib/libaccn.lib” “$PGI/win64/18.4/lib/l
ibaccg2.lib” “$PGI/win64/18.4/lib/libcudadevice.lib” “$PGI/win64/18.4/lib/pgc14.lib” “$PGI/win64/18.4/lib/libnspgc.lib”
-defaultlib:legacy_stdio_definitions -defaultlib:oldnames -Lc:/progra~1/PGICE/win/18.4/lib/pgc14.dll -Lc:/progra~1/PGI
CE/win64/18.4/lib/pgf90.dll
Creating library test2.lib and object test2.exp
PGI$


Thanks for any help!!!

e