TA的每日心情 | 奋斗 4 天前 |
|---|
签到天数: 1184 天 [LV.10]大乘
|
5#

楼主 |
发表于 2022-9-24 23:54:10
|
只看该作者
本帖最后由 雷达 于 2022-9-24 23:57 编辑 4 E& E- O8 j) x$ e
0 m, W* x- x7 N k5 K( Q8 n) x& K8 h( g- x0 m, U6 c4 R" V! m
void xcorr(comp* outcomp, comp* A, int lenA, comp* B, int lenB)
2 }6 n+ ~- v1 Q* {: l* T; p3 _+ H" c{
1 i' z3 F- y* \+ ]' @8 n comp temp, xtimesy;
- j4 r |, [& s4 E3 X/ ~' a xtimesy.re = 0;
2 Z2 ~4 W6 g, H$ z: K xtimesy.im = 0;
6 O+ F- D; {& P: y, u( f int j0 = lenB - 1;7 A4 W" H/ n- k( Y, o
int i, j, i1, reali;
$ W* j# J% j- p9 D if (lenA % 2 == 1)
" O9 d% r6 l3 ]4 e/ A reali = lenA + 1;+ t: e8 L; G, I1 s6 H8 s
else* r8 F6 {1 l y
reali = lenA;7 w+ p8 q+ k7 V% A4 F1 z8 y& t
reali /= 2;
4 s/ q/ l5 j9 K8 l5 {+ |" ?% i6 V& {% q. H' U
int nconv = reali + lenB;
8 `( m6 g5 U5 d' K //#pragma omp parallel for
4 [* [) ]" `: i1 ]2 P for (i = reali; i < nconv; i++)0 @9 |4 C! j5 C- f- n% |! R+ l
{3 V, R2 D# x- K: ]
temp.re = 0;
! V$ W# e( }* x) S3 d& h+ W4 J* I temp.im = 0;( \& G# Y' ~" R+ i% M1 z
i1 = i;
) G# m, V, G+ l for (j = j0; j >= 0; j--)& \( g1 q0 L* b7 y( N6 s: p
{6 L2 n8 h1 h7 a; E( V
/* floating date operation */
5 {. `# W( Z0 w/ p8 ] }) q4 U9 i+ J3 S
}' ^' i: F/ Q8 J1 l; C
}
% H1 y( M, a( Y" C# r" a% x
- M# a4 N. S4 ]- `xcorr函数代码如上,comp是复数struct, 做过长度为11、19两个矢量的测试,和octave结果完全一样: `" x" H* o" s: j! T
( e2 |+ d0 P/ h; A
红色部分是内循环,现在其内部操作都comment out 了, j0大概是 6000。
& R; u3 A6 Y/ ~2 U# d8 n现在call xcorr 100次,耗时78s.+ P2 m/ N4 B8 o- y& A
3 z# h* @4 Q# g
如果把红色部分内循环本身完全comment out, call xcorr 1000次,耗时 <1s.
+ B T( c) r" n) I I) G8 W7 w; |+ M' X' V+ L& H" f% k/ o( R
|
|