▶ 在 windows 10 上搭建 OpenACC 环境

● 安装顺序:Visual Studio(PGI 18.04 不支持 VS 2017,PGI 19.04 已经支持到 VS 2019 啦!);CUDA Toolkite(https://developer.nvidia.com/cuda-downloads);PGI 编译器(https://www.pgroup.com/products/community.htm?*utm*_campaign=CE&utm_source=dev_nvidia_oacc&utm_medium=web_link&utm_term=*get_ce_text*)

● PGI 自带的 pgaccinfo.exe 抓取设备信息:

CUDA Driver Version:           

Device Number:
Device Name: GeForce GTX
Device Revision Number: 6.1
Global Memory Size:
Number of Multiprocessors:
Concurrent Copy and Execution: Yes
Total Constant Memory:
Total Shared Memory per Block:
Registers per Block:
Warp Size:
Maximum Threads per Block:
Maximum Block Dimensions: , ,
Maximum Grid Dimensions: x x
Maximum Memory Pitch: 2147483647B
Texture Alignment: 512B
Clock Rate: MHz
Execution Timeout: Yes
Integrated Device: No
Can Map Host Memory: Yes
Compute Mode: default
Concurrent Kernels: Yes
ECC Enabled: No
Memory Clock Rate: MHz
Memory Bus Width: bits
L2 Cache Size: bytes
Max Threads Per SMP:
Async Engines:
Unified Addressing: Yes
Managed Memory: Yes
Concurrent Managed Memory: No
Preemption Supported: Yes
PGI Default Target: -ta=tesla:cc60

● 编写代码

 #include <stdio.h>
#include <openacc.h> int main()
{
#ifdef _OPENACC
printf("%d device found!\n", acc_get_num_devices(acc_device_not_host));
#else
printf("OpenACC not support.\n");
#endif
getchar();
return ;
}

● 直接在 Visual Studio 2015 编译遇到了一些问题,最后是用 PGI 的命令行来进行编译的,这里只记录一下问题。先是要求添加 openacc.h 的路径(C:\Program Files\PGICE\win64\18.4\include),然后报错:

严重性    代码    说明                            项目            文件                                                行
错误 C1021 无效的预处理器命令“include_next” OpenACCProject c:\program files\pgice\win64\18.4\include\sal.h

  这是因为在 <sal.h> 中第 28 行有  #include_next <sal.h>  ,意思是该 <sal.h> 中没有找到对应的头文件,要求预处理器去包含搜索路径的下一个 <sal.h>。但是 include_next 不是标准 C 的预处理器语句,在 Visual Studio 中无法执行(据说有办法解决,看起来有点麻烦,https://stackoverflow.com/questions/24638855/how-to-use-arduino-with-microsoft-visual-studio-due-to-include-next-precompil)。如果将该头文件中

 ...
#if defined __PGI_TOOLS14
#include <sal14.h>
...

  前面强行添上  #include <sal4.h> (该目录下确实有 <sal14.h> 这个头文件)并删除 #include_next 行,则会引起 vadefs.h 中的相同类型的错误,再把 vadefs.h 中

 ...
#if defined __PGI_TOOLS12
#include <vadefs12.h>
...

  前面强行添上  #include <C:/Program Files/PGICE/win64/18.4/include_acc/OT_14/vadefs.h> ,则没有了 #include_next 错误,但会有链接阶段报错:

严重性    代码        说明            项目            文件                                                行
错误 LNK1158 无法运行“rc.exe” OpenACCProject D:\Code\OpenACC\OpenACCProject\OpenACCProject\LINK

  说到底这是 MS 编译器不支持 OpenACC 的原因,缺少宏 _OPENACC 的定义

● 代码在 PGI 的命令行中正确的编译和执行

 PGI Community Edition 18.4
Microsoft Windows [版本 10.0.17134.1]
(c) Microsoft Corporation。保留所有权利。 C:\Users\cuan>D: D:\>cd D:\Code\OpenACC\OpenACCProject\OpenACCProject D:\Code\OpenACC\OpenACCProject\OpenACCProject>pgcc -o main-no-acc.exe main.c D:\Code\OpenACC\OpenACCProject\OpenACCProject>main-no-acc.exe
OpenACC not support. D:\Code\OpenACC\OpenACCProject\OpenACCProject>pgcc -acc -o main.exe main.c D:\Code\OpenACC\OpenACCProject\OpenACCProject>main.exe
device found! D:\Code\OpenACC\OpenACCProject\OpenACCProject>

▶ 在 Ubuntu16.04LTS 上搭建 OpenACC 环境

● 安装顺序:CUDA Toolkite(https://developer.nvidia.com/cuda-downloads);PGI 编译器(https://www.pgroup.com/products/community.htm?*utm*_campaign=CE&utm_source=dev_nvidia_oacc&utm_medium=web_link&utm_term=*get_ce_text*)

cuan@CUAN:~/pgilinux-2019-194-x86-64$ sudo su
root@CUAN:/home/cuan/pgilinux-2019-194-x86-64# ./install Welcome to the PGI Linux installer! You are installing PGI 2019 version 19.4 for Linux.
Please note that all Trademarks and Marks are the properties
of their respective owners. Press enter to continue... # 回车 NVIDIA ... Do you accept these terms? (accept,decline) # accept ... 1 Single system install
2 Network install Please choose install option: # ... Installation directory? [/opt/pgi] # /usr/local/pgi ... JRE Press enter to continue... # 回车 ... Do you accept these terms? (accept,decline) # accept ... Do you wish to update/create links in the 2019 directory? (y/n) # y ... MPI ... Do you want to install Open MPI onto your system? (y/n) # y
Do you want to enable NVIDIA GPU support in Open MPI? (y/n) # y ... License Key Management ... Do you wish to obtain permanent license key or configure license service? (y/n) # y ... Press enter to continue... # 回车 ... 1 Generate or update a license key for this computer
** Option 1 IS NOT AVAILABLE.
Requires properly configurd curl and internet access.
2 Configure and start a license service on this computer
4 I have a functioning license key - what type is it? (beta)
5 Quit What do you want to do? # Please enter the location of the license key file.
For example: /usr/local/pgi/license.dat
Answer? # /usr/local/pgi/license.dat Should license services start when the system boots? (y/n) # y
Master daemon (lmgrd) is not running
Vendor daemon (pgroud) is not running The PGI license tool can be re-started by running the script located at: /usr/local/pgi/linux86-64-llvm/19.4/bin/pgi_license_tool The license key file is located at /usr/local/pgi/license.dat. ...

● 添加路径到 .bashrc,并执行 source .bashrc

#for pgi
export PATH=$PATH:/usr/local/pgi/linux86-/18.4/bin
export MANPATH=$MANPATH:/usr/local/pgi/linux86-/18.4/man
export LM_LICENSE_FILE=/usr/local/pgi/license.dat

● 编写代码同上,编译执行:

cuan@CUAN:~$ pgcc --version

pgcc 18.4- -bit target on x86- Linux -tp haswell
PGI Compilers and Tools
Copyright (c) , NVIDIA CORPORATION. All rights reserved.
cuan@CUAN:~$ cd Temp/
cuan@CUAN:~/Temp$ pgcc -o main-no-acc.exe main.c
cuan@CUAN:~/Temp$ pgcc -acc -o main.exe main.c
cuan@CUAN:~/Temp$ ./main-no-acc.exe
OpenACC not support. cuan@CUAN:~/Temp$ ./main.exe
device found! cuan@CUAN:~/Temp$

● 几个坑:

■ linux 上要先装了 gcc/g++ 才能安装 pgi, apt-get install build-essential

■ .bashrc 中加入 export 时,等号两边不能有空格

■ 误删了 .bashrc,从备份中去找, cp /etc/skel/.bashrc ~/

■ 在 Win10 WSL 上安装有点问题,核心问题是 Nvidia 的驱动安装不了,而 CUDA SDK 对其有依赖,强行安装 pgi 以后可以正常用 pgcc 编译,但是运行如上的代码时总是显示 0 device found! 它到底有没有调用 CUDA 核进行计算有待进一步探究,暂时折腾不动了

■ 删除 cygwin 用的 .bat,就是获得其文件的所有权。参考【https://www.cnblogs.com/litifeng/p/9996909.html】

 SET DIRECTORY_NAME="D:\cygwin64"
C:\windows\system32\TAKEOWN /f %DIRECTORY_NAME% /r /d y
C:\windows\system32\ICACLS %DIRECTORY_NAME% /grant administrators:F /t
PAUSE

OpenACC Hello World的更多相关文章

  1. 7.OpenACC

    OpenACC: openacc 可以用于fortran, c 和 c++程序,可以运行在CPU或者GPU设备. openacc的代码就是在原有的C语言基础上进行修改,通过添加:compiler di ...

  2. PGI Compiler for OpenACC Output Syntax Highlighting

    PGI Compiler for OpenACC Output Syntax Highlighting When use the PGI compiler to compile codes with ...

  3. OpenACC 云水参数化方案

    ▶ 书上第十三章,用一系列步骤优化一个云水参数化方案.用于熟悉 Fortran 以及 OpenACC 在旗下的表现 ● 代码,文件较多,放在一起了 ! main.f90 PROGRAM main US ...

  4. OpenACC 绘制曼德勃罗集

    ▶ 书上第四章,用一系列步骤优化曼德勃罗集的计算过程. ● 代码 // constants.h ; ; ; ; const double xmin=-1.7; ; const double ymin= ...

  5. OpenACC 梯度下降法求解线性方程的优化

    ▶ 书上第二章,用一系列步骤优化梯度下降法解线性方程组.才发现 PGI community 编译器不支持 Windows 下的 C++ 编译(有 pgCC 命令但是不支持 .cpp 文件,要专业版才支 ...

  6. OpenACC 优化矩阵乘法

    ▶ 按书上的步骤使用不同的导语优化矩阵乘法 ● 所有的代码 #include <iostream> #include <cstdlib> #include <chrono ...

  7. OpenACC 简单的原子操作

    ▶ OpenACC 的原子操作,用到了 C++ 的一个高精度计时器 ● 代码,直接的原子操作 #include <iostream> #include <cstdlib> #i ...

  8. OpenACC 与 CUDA 的相互调用

    ▶ 按照书上的代码完成了 OpenACC 与CUDA 的相互调用,以及 OpenACC 调用 cuBLAS.便于过程遇到了很多问题,注入 CUDA 版本,代码版本,计算能力指定等,先放在这里,以后填坑 ...

  9. OpenACC Julia 图形

    ▶ 书上的代码,逐步优化绘制 Julia 图形的代码 ● 无并行优化(手动优化了变量等) #include <stdio.h> #include <stdlib.h> #inc ...

  10. OpenACC 异步计算

    ▶ 按照书上的例子,使用 async 导语实现主机与设备端的异步计算 ● 代码,非异步的代码只要将其中的 async 以及第 29 行删除即可 #include <stdio.h> #in ...

随机推荐

  1. LuoguP4389 付公主的背包【生成函数+多项式exp】

    题目背景 付公主有一个可爱的背包qwq 题目描述 这个背包最多可以装10^5105大小的东西 付公主有n种商品,她要准备出摊了 每种商品体积为Vi,都有10^5105件 给定m,对于s\in [1,m ...

  2. 51Nod 1058: N的阶乘的长度(斯特林公式)

    1058 N的阶乘的长度  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 输入N求N的阶乘的10进制表示的长度.例如6! = 720,长度为3. Inp ...

  3. test20181015 B君的第二题

    题意 分析 考场85分 用multiset暴力,由于教练的机子飞快,有写priority_queue水过了的人. #include<cstdlib> #include<cstdio& ...

  4. git的使用方法学习

    1.git常用命令: git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致.同时,将当前的工作区内容保存到Git栈中. git stash p ...

  5. day8 python学习 集合 深浅拷贝

    1.内存地址: 字符串在20位以内,没有空格,没有特殊字符的情况下,同样的字符串内存地址是一样的 2.元组中:在只有一个值的时在后边加逗号和没有逗号的区别 t1=(1) 不加逗号这个值是什么类型就打印 ...

  6. gitlab怎么删除创建的项目

    在gitlab新建了一个项目,怎么将此项目删除呢?打开这个工程,点击右上角的“settings”拉到最下面,有个show them to me,点击~在下拉选项的最后,有个remove框,点击即可以彻 ...

  7. hdu 6305 RMQ Similar Sequence——概率方面的思路+笛卡尔树

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6305 看题解,得知: 0~1内随机取实数,取到两个相同的数的概率是0,所以认为 b 序列是一个排列. 两个 ...

  8. POJ1135 Domino Effect

    题目:http://poj.org/problem?id=1135 只是求以1为起点的最短路罢了.稍稍判断一下在边上的情况. 多亏提醒:毒数据——n==1!一定要dis [ k ] >= ans ...

  9. Angular 4 父组件调用子组件中的方法

    1. 创建工程 ng new demo3 2. 创建子组件 ng g component child 3. 在子组件中定义方法greeting 4. 父组件html(第三行是模板中调用子组件的方法) ...

  10. Maven 项目报告插件

    Maven 项目报告插件,都是对于前面生成的项目站点的内容丰富,因此都是基于项目站点的,生成的命令和生成项目站点一致(mvn site),项目报告插件的配置和一般插件不同,是在 project-> ...