OpenACC kernels】的更多相关文章

▶ 使用 kernels 导语并行化 for 循环 ● 一重循环 #include <stdio.h> #include <time.h> #include <openacc.h> * * ; int main() { int i, j, k, a[row], b[row], c[row]; clock_t time; ; i < row; i++) a[i] = b[i] = i; #ifdef _OPENACC time = clock(); #pragma…
OpenACC: openacc 可以用于fortran, c 和 c++程序,可以运行在CPU或者GPU设备. openacc的代码就是在原有的C语言基础上进行修改,通过添加:compiler directives 编译器指令(pragmas): #pragma 来标示. cuda 中有 __syncthreads()来进行线程同步,目前的OpenAcc还没有线程同步机制. OpenAcc device model OpenAcc excute model parallel loops 下面地…
▶ 书上第二章,用一系列步骤优化梯度下降法解线性方程组.才发现 PGI community 编译器不支持 Windows 下的 C++ 编译(有 pgCC 命令但是不支持 .cpp 文件,要专业版才支持),以后 OpenACC - C++ 全盘转向 Ubuntu 中. ● 代码 // matrix.h #pragma once #include <cstdlib> struct matrix { unsigned int num_rows; unsigned int nnz; unsigned…
▶ 按书上的步骤使用不同的导语优化矩阵乘法 ● 所有的代码 #include <iostream> #include <cstdlib> #include <chrono> #define SIZE 1024 using namespace std; using namespace std::chrono; double a[SIZE][SIZE], b[SIZE][SIZE], c[SIZE][SIZE], d[SIZE][SIZE];// 四个数组放入 main 里…
▶ 按照书上的代码完成了 OpenACC 与CUDA 的相互调用,以及 OpenACC 调用 cuBLAS.便于过程遇到了很多问题,注入 CUDA 版本,代码版本,计算能力指定等,先放在这里,以后填坑. ● 代码,OpenACC 调用 CUDA // kernel.cu __global__ void saxpy_kernel(const int n, const float a, float *x, float *y) { int id = blockIdx.x * blockDim.x +…
▶ 书上的代码,逐步优化绘制 Julia 图形的代码 ● 无并行优化(手动优化了变量等) #include <stdio.h> #include <stdlib.h> #include <openacc.h> #define N (1024 * 8) int julia(const float cre, const float cim, float zre, float zim, const int maxIter)// 计算单点迭代次数 { float zre2 =…
▶ 按照书上的例子,使用 async 导语实现主机与设备端的异步计算 ● 代码,非异步的代码只要将其中的 async 以及第 29 行删除即可 #include <stdio.h> #include <stdlib.h> #include <openacc.h> #define N 10240000 #define COUNT 200 // 多算几次,增加耗时 int main() { int *a = (int *)malloc(sizeof(int)*N); int…
▶ 使用Jacobi 迭代求泊松方程的数值解 ● 使用 data 构件,强行要求 u0 仅拷入和拷出 GPU 各一次,u1 仅拷入GPU 一次 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <openacc.h> #if defined(_WIN32) || defined(_WIN64) #include <C:\Program Files (x86)\Window…
▶ 书中第4章,数据管理部分的代码和说明 ● 代码,关于 copy,copyin,copyout,create #include <stdio.h> #include <openacc.h> int main() { ; int a[length], b[length], c[length],d[length]; ; i < length; a[i] = b[i] = c[i] = ); { #pragma acc kernels create(d) ; i < len…
▶ 使用Jacobi 迭代求泊松方程的数值解 ● 首次使用 OpenACC 进行加速,使用动态数组,去掉了误差控制 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <openacc.h> #if defined(_WIN32) || defined(_WIN64) #include <C:\Program Files (x86)\Windows Kits\\Includ…