⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test9.c

📁 shpf 1.9一个并行编译器
💻 C
字号:

//   !hpf$ processors q(2, 3)
// 
//   !hpf$ template s(4, 100)
//   !hpf$ distribute s(block, cyclic(12)) onto q
// 
//   integer a(80)
//   real b(80)
//   !hpf$ align a(j) with s(*, 15 + j) 
//   !hpf$ align b(:) with a(:)
// 
//   double precision res
// 
//   do i = 1, 80
//     a(i) = i
//     b(i) = 1.0 / i
//   enddo
// 
//   res = dot_product(a, b)
// 
//   print *, res
// 
// end


#include "ad++.h"
#include "admacros.h"


void zeroFloat(void* dat) {
  *((float*) dat) = 0.0 ;
}

void accumProdIntFloat(void* acc, void* arg1, void* arg2) {
  *((float*) acc) += *((int*) arg1) * *((float*) arg2) ;
}

void accumFloat(void* acc, void* val) {
  *((float*) acc) += *((float*) val) ;
}


void main(int argc, char* argv[]) {
  AdlibInit(argc, argv) ;

  Procs2 q(2, 3) ;

  //Range x(4, q.dim(1), blk) ;
  Range y = Range(100, q.dim(1), CYC, 12).subrng(80, 15) ;

  Array1<int> a(q, y) ;
  Array1<float> b(q, y) ;

  on(q) {
    where(y) {
      a(y) = y + 1 ;
      b(y) = 1.0 / (y + 1) ;
    } erewh(y) ;
  } no(q) ;

  float res ;

  reduce2(sizeof(float), (char*) &res, a, b, 
          &zeroFloat, &accumProdIntFloat, &accumFloat) ;

  gprintf("%f\n", res) ;

  AdlibFinalize() ;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -