1.安装 visual studio2015+ivf2017update4
2.安装Windows SDK 10,这一步取决于第三步安装PGI时是否提示需要安装WindowsSDK
3.安装PGI CE 18.4
注意事项:
1.三个软件必须安装在同一个盘下,否则安装后的PGI CE 无法编译。因为Windows10 SDK似乎只能安装在C盘,所以可能这些都需要安装再C盘中,3个软件一共需要30GB左右的内存。
2.PGI CE 读取代码的默认路径为C:\Users\Administrator,所以必须将所用代码f.90文件拷贝到该路径下才可以进行后续操作
&&&&补充一下,可以在自己指定的路径里面进行编译,这时需将安装目录C:\Program Files\PGICE\win64\18.4中的pgi.bat拷贝到你的代码目录下面,再双击打开,在这个界面进行编译链接即可。
3.本文介绍的PGI CE 采用命令行编译,工作都在DOS界面上进行,不集成到VS环境中
安装后桌面的图标如图所示
打开PGI CE 后界面如图所示
PGI CE 采用命令行编译,先在VS中写好代码,得到代码的f.90文件,再用PGI CE 命令行编译。
PGI$ pgf95 sample2_1.f90 -Mcuda
编译成功后会生成sample2_1.exe文件,再用命令行运行
PGI$ ./sample2_1.exe
运行测试程序的结果如图所示
sample2_1代码如下
program device
use cudafor
implicit none
type(cudaDeviceProp)::prop
integer::ndevices=0,i,ierr
ierr=cudaGetDeviceCount(ndevices)
if (ndevices==0) then
print *,'no cuda find'
stop
else if (ndevices==1) then
write(*,"(/,'one cuda devices found',/)")
else
write(*,"(/,i0,‘cuda devices found’,/)") ndevices
endif
do i=0,ndevices-1
write(*,"('device number:',i0)") i
ierr=cudaGetDeviceproperties(prop,i)
if (ierr .eq. 0 ) then
write (*,"('GetDeviceproperties for devices ',i0,':passed')")i
else
write (*,"('GetDeviceproperties for devices ',i0,':failed')")i
endif
write(*,"(' device name :',a)") trim(prop%name)
write(*,"(' compute capability :',i0,'.',i0)") prop%major,prop%minor
write(*,"(' number of multiprocessors:',i0)") prop%multiprocessorcount
write(*,"('max threads per multiprocessor:',i0)") prop%maxthreadspermultiprocessor
write(*,"('global memory (GB)',f9.3,/)") prop%totalglobalmem/1024.0**3
write(*,"('execution configuration limits')")
write(*,"('max grid dims:',2(i0,' x '),i0)") prop%maxgridsize
write(*,"('max block dims:',2(i0,' x '),i0)") prop%maxthreadsdim
write(*,"('max threads per block:',i0,/)") prop%maxthreadsperblock
enddo
end
sample2_1是获取本机支持的CUDA的GPU卡