TA的每日心情 | 怒 2025-9-22 22:19 |
|---|
签到天数: 1183 天 [LV.10]大乘
|
5#

楼主 |
发表于 2022-9-24 23:54:10
|
只看该作者
本帖最后由 雷达 于 2022-9-24 23:57 编辑 9 E$ ]7 d% ]9 ~" {
5 ~4 e; ~, n& g# g5 B/ \
2 R( R5 s6 [ {: t; g4 svoid xcorr(comp* outcomp, comp* A, int lenA, comp* B, int lenB)) @& `* x' L, d, N3 ]
{
& @' B' t/ b' P& q comp temp, xtimesy;8 ]$ C4 a" ?7 D8 A, n1 B+ q4 g
xtimesy.re = 0;
9 w6 z* V! C' z% |0 K& L xtimesy.im = 0;" u& N" f. ]( f+ \8 d
int j0 = lenB - 1;9 o0 m' p9 f3 h8 z, E D7 r) D, V
int i, j, i1, reali;+ T1 `% O1 a7 _7 B7 x
if (lenA % 2 == 1)
3 e- N+ o2 ^7 O& M reali = lenA + 1;/ ~' {1 q8 ?4 g* t S
else& {) [6 J9 w1 C& F2 S
reali = lenA;* ~. i. x* }/ _& d
reali /= 2; U# d; d% \8 R' B5 o
C) L0 U( D. C" I5 O/ v9 i7 @ int nconv = reali + lenB;
/ Y- L1 @! |/ e6 o8 f% T: {; e& C, Q //#pragma omp parallel for. Q! D. g$ X6 d7 C7 x
for (i = reali; i < nconv; i++)
7 W& t! t5 [- V {2 a4 U$ g& J" X
temp.re = 0;
" M) w9 k e; m" F+ H, y9 e/ F temp.im = 0;
: ^) {0 o: X, E- o5 F: O- f i1 = i;) v4 K1 Z# M; D q8 Y
for (j = j0; j >= 0; j--). r; C6 i1 ~& {
{( a3 F* U) N. P7 o" u7 M4 i
/* floating date operation *// v4 H& _7 b9 E# H& b2 m5 V" }
}
# G. ~; [% h/ g3 d" \, I y }7 p, _2 d7 h5 r& Y1 K% ~
}
/ I* y, P4 ^2 x: t, E( l, L& D! o; V+ r& ^, }
xcorr函数代码如上,comp是复数struct, 做过长度为11、19两个矢量的测试,和octave结果完全一样
# l; Y: Z0 t) s) ^) R: X
. ^" ^5 e: V8 n$ ^ I, D红色部分是内循环,现在其内部操作都comment out 了, j0大概是 6000。( Q. {" b- R* e1 F' h o- @6 v
现在call xcorr 100次,耗时78s.
- {+ q& c* o# Z# |/ a( t4 X, x) ]& C' U" D; C
如果把红色部分内循环本身完全comment out, call xcorr 1000次,耗时 <1s. $ B7 ^, ]" a2 E; q# z7 z K8 n* y
1 T. e/ o. W) U. X9 _ |
|