File tree 2 files changed +48
-0
lines changed
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ using LoopVectorization: @tvectorize
2
+
1
3
function eval_exp (N)
2
4
a = range (0 , stop= 2 * pi , length= N)
3
5
A = Matrix {ComplexF64} (undef, N, N)
@@ -12,11 +14,31 @@ function eval_exp(N)
12
14
13
15
end
14
16
17
+ function eval_exp_tvectorize (N)
18
+ a = range (0 , stop= 2 * pi , length= N)
19
+ A = Matrix {ComplexF64} (undef, N, N)
20
+
21
+ _A = reinterpret (reshape, Float64, A)
22
+ @tvectorize for j in 1 : N, i in 1 : N
23
+ x = sqrt (a[i]^ 2 + a[j]^ 2 )
24
+ prefac = exp (- x)
25
+ s, c = sincos (100 * x)
26
+
27
+ _A[1 ,i,j] = prefac * c
28
+ _A[2 ,i,j] = prefac * s
29
+ end
30
+ return A
31
+ end
32
+
15
33
eval_exp (5 )
16
34
print (string (" running loop on " , Threads. nthreads (), " threads \n " ))
17
35
for N in 1000 : 1000 : 10000
18
36
@time begin
19
37
A = eval_exp (N)
20
38
end
39
+
40
+ @time begin
41
+ A = eval_exp_tvectorize (N)
42
+ end
21
43
end
22
44
Original file line number Diff line number Diff line change
1
+ using LoopVectorization: @tvectorize
2
+
3
+ function eval_exp_tvectorize (N)
4
+ a = range (0 , stop= 2 * pi , length= N)
5
+ A = Matrix {ComplexF64} (undef, N, N)
6
+
7
+ _A = reinterpret (reshape, Float64, A)
8
+ @avs thread= true @tvectorize for j in 1 : N, i in 1 : N
9
+ x = sqrt (a[i]^ 2 + a[j]^ 2 )
10
+ prefac = exp (- x)
11
+ s, c = sincos (100 * x)
12
+
13
+ _A[1 ,i,j] = prefac * c
14
+ _A[2 ,i,j] = prefac * s
15
+ end
16
+ return A
17
+ end
18
+
19
+ eval_exp_tvectorize (5 )
20
+ print (string (" running loop on " , Threads. nthreads (), " threads \n " ))
21
+ for N in 1000 : 1000 : 10000
22
+ @time begin
23
+ A = eval_exp_tvectorize (N)
24
+ end
25
+ end
26
+
You can’t perform that action at this time.
0 commit comments