📄 test10.c
字号:
// !hpf$ processors q(2, 3)
//
// !hpf$ template s(25, 20)
// !hpf$ distribute s(block, cyclic(5)) onto q ! boring cyclic !!
//
// real res(15, 10)
// !hpf$ align res(i, j) with s(20 - j, i)
//
// !hpf$ processors p(3, 2)
//
// !hpf$ template t(50, 20)
// !hpf$ distribute t(cyclic, block) onto p
//
// integer a(15, 20)
//
// !hpf$ align a(i, j) with t(5 + 2 * i, j)
//
// !hpf$ processors r(6)
//
// real b(20, 10)
// !hpf$ distribute b(*, block) onto r
//
// integer i, j, k
//
// do i = 1, 15
// do j = 1, 20
// a(i, j) = i * j
// end do
// end do
//
// do j = 1, 20
// do k = 1, 10
// b(j, k) = 1.0 / (j + k)
// end do
// end do
//
// res = matmul(a, b)
//
// do i = 1, 15
// print "(10f7.2)", res(i, :)
// end do
//
// end
#include <stdio.h>
#include "ad++.h"
#include "admacros.h"
void main(int argc, char* argv[]) {
AdlibInit(argc, argv) ;
Procs2 q(2, 3) ;
Range s1(25, q.dim(0), BLK) ;
Range s2(20, q.dim(1), CYC, 5) ;
Range x = s2.subrng(15, 0) ;
Range y = s1.subrng(10, 18, -1) ;
Array2<float> res(q, x, y) ;
Procs2 p(3, 2) ;
Range t1(50, p.dim(0), CYC) ;
Range t2(20, p.dim(1), BLK) ;
Range i = t1.subrng(15, 6, 2) ;
Range j = t2.subrng(20, 0) ;
Array2<int> a(p, i, j) ;
Procs1 r(6) ;
Range u(20) ;
Range v(10, r.dim(0), BLK) ;
Array2<float> b(r, u, v) ;
on(p) {
where(i) {
where(j) {
a(i, j) = (i + 1) * (j + 1) ;
} erewh(j) ;
} erewh(i) ;
} no(p) ;
on(r) {
where(u) {
where(v) {
b(u, v) = 1.0 / (u + 1 + v + 1) ;
} erewh(v) ;
} erewh(u) ;
} no(r) ;
// res = matmul(a, b)
Range z(20) ;
Array2<int> tmp1(q, x, z) ;
Array2<float> tmp2(q, z, y) ;
remap(tmp1, a) ;
remap(tmp2, b) ;
on(q) {
where(x) {
where(y) {
res(x, y) = 0.0 ;
for(int i = 0 ; i < 20 ; i++) {
Subscript s(z(i)) ;
res(x, y) += tmp1(x, s) * tmp2(s, y) ;
}
} erewh(y) ;
} erewh(x) ;
} no(q) ;
aprintf("%7.2f%*N", res, y.size()) ;
AdlibFinalize() ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -