📄 level2.c
字号:
// PROGRAM MAIN
// REAL X(2:99), Y(100)
// !HPF$ PROCESSORS P(4)
// !HPF$ TEMPLATE TX(400),TY(-200:199)
// !HPF$ DISTRIBUTE TX(BLOCK) ONTO P
// !HPF$ DISTRIBUTE TY(BLOCK) ONTO P
// !HPF$ ALIGN X(i) WITH TX(2*i+1)
// !HPF$ ALIGN Y(i) WITH TY(3*i-150)
//
// FORALL (i=2:99) X(i) = 0
// FORALL (i=1:100) Y(i) = i
//
// FORALL (i=2:99) X(i) = Y(i+1) + Y(i-1)
//
// CALL FOO(X(2:98:2),Y(1:99:2))
// CALL FOO(X(3:99:2),Y(2:100:2))
//
// PRINT *, (X(i),i=2,99)
// END
//
// SUBROUTINE FOO(X,Y)
// REAL X(49), Y(50)
// !HPF$ INHERIT X,Y
//
// FORALL (i=1:49) X(i) = X(i) - Y(i) - Y(i+1)
//
// RETURN
// END
#include "ad++.h"
#include "admacros.h"
void foo(Array1<float> x, Array1<float> y) ;
void main(int argc, char* argv[]) {
AdlibInit(argc, argv) ;
Procs1 p(4) ;
on(p) {
Range itx(400, p.dim(0), BLK) ;
Range ix = itx.subrng(98, 4, 2) ;
Array1<float> x(ix) ;
Range ity(400, p.dim(0), BLK) ;
Range iy = ity.subrng(100, 56, 3) ;
Array1<float> y(iy) ;
where(ix)
x(ix) = 0 ;
erewh(ix) ;
where(iy)
y(iy) = iy + 1 ;
erewh(iy) ;
Array1<float> tmp1(ix), tmp2(ix) ;
remap(tmp1, y.sect(iy.subrng(98, 2))) ;
remap(tmp2, y.sect(iy.subrng(98, 0))) ;
where(ix)
x(ix) = tmp1(ix) + tmp2(ix) ;
erewh(ix) ;
foo(x.sect(ix.subrng(49, 0, 2)), y.sect(iy.subrng(50, 0, 2))) ;
foo(x.sect(ix.subrng(49, 1, 2)), y.sect(iy.subrng(50, 1, 2))) ;
aprintf("%12.2f\n", x) ;
} no(p) ;
AdlibFinalize() ;
}
void foo(Array1<float> x, Array1<float> y) {
Group p = x.grp() ;
Range ix = x.rng(0), iy = y.rng(0) ;
Array1<float> tmp1(p, ix), tmp2(p, ix), tmp3(p, ix) ;
copy(tmp1, x) ;
remap(tmp2, y.sect(iy.subrng(49, 0))) ;
remap(tmp3, y.sect(iy.subrng(49, 1))) ;
on(p) {
where(ix) {
x(ix) = tmp1(ix) - tmp2(ix) - tmp3(ix) ;
} erewh(ix) ;
} no(p) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -