OpenACC parallel】的更多相关文章

▶ 使用 kernels 导语并行化 for 循环 ● 同一段代码,使用 kernels,parallel 和 parallel + loop 进行对比 #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;…
OpenACC: openacc 可以用于fortran, c 和 c++程序,可以运行在CPU或者GPU设备. openacc的代码就是在原有的C语言基础上进行修改,通过添加:compiler directives 编译器指令(pragmas): #pragma 来标示. cuda 中有 __syncthreads()来进行线程同步,目前的OpenAcc还没有线程同步机制. OpenAcc device model OpenAcc excute model parallel loops 下面地…
▶ 书上第十三章,用一系列步骤优化一个云水参数化方案.用于熟悉 Fortran 以及 OpenACC 在旗下的表现 ● 代码,文件较多,放在一起了 ! main.f90 PROGRAM main USE m_config, ONLY: nstop USE m_physics, ONLY: physics USE m_io, ONLY: write_output USE m_setup, ONLY: initialize, cleanup USE m_timing, ONLY: start_tim…
▶ 书上第四章,用一系列步骤优化曼德勃罗集的计算过程. ● 代码 // constants.h ; ; ; ; const double xmin=-1.7; ; const double ymin=-1.2; const double ymax=1.2; const double dx = (xmax - xmin) / WIDTH; const double dy = (ymax - ymin) / HEIGHT; // mandelbrot.h #pragma acc routine se…
▶ 按书上的步骤使用不同的导语优化矩阵乘法 ● 所有的代码 #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 的原子操作,用到了 C++ 的一个高精度计时器 ● 代码,直接的原子操作 #include <iostream> #include <cstdlib> #include <chrono> #define ATOMIC using namespace std; using namespace std::chrono; int main() { high_resolution_clock::time_point t1 = high_resolution_…
▶ 书上的代码,逐步优化绘制 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…
▶ 书上的计算圆周率的简单程序,主要是使用了自定义函数 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <openacc.h> #define N 100 #pragma acc routine seq float ff(const float x) { return 4.0f / (1.0f + x * x); } int main() { const float h =…
▶ 使用 routine 构件创建的自定义函数,在并行调用上的差别 ● 代码,自定义一个 sqab 函数,使用内建函数 fabsf 和 sqrtf 计算一个矩阵所有元素绝对值的平方根 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <openacc.h> #define ROW 8 #define COL 64 #pragma acc routine vector void…