I want to optimize the performance of my previous code:
using BenchmarkTools
function discrete_integrate(xvec::Vector, y1vec::Vector, y2vec::Vector, y3vec::Vector)
s = zero(promote_type(eltype(xvec), eltype(y1vec), eltype(y2vec), eltype(y3vec)))
for i in 1:length(xvec)-1
s += (y1vec[i+1] * y2vec[i+1] * y3vec[i+1] + y1vec[i] * y2vec[i] * y3vec[i]) * (xvec[i+1] - xvec[i])
end
0.5 * s
end
function funF2(matSlωJ::Array{ComplexF64,3}, Zvec::Vector, ωvec::Vector, nJ::Int64, lm::Int64)
resmat = zeros(ComplexF64, nJ, nJ, 2lm + 1, 2lm + 1)
@sync for l1 = -lm:lm, l2 = -lm:lm
idx1 = lm + l1 + 1
idx2 = lm + l2 + 1
Threads.@spawn for j1 = 1:nJ, j2 = 1:nJ
resmat[j1, j2, idx1, idx2] = discrete_integrate(ωvec, Zvec, conj.(matSlωJ[idx1, :, j1]), matSlωJ[idx2, :, j2])
end
end
resmat
end
function funF3(matSlωJ::Array{ComplexF64,3}, Zvec::Vector, ωvec::Vector, nJ::Int64, lm::Int64)
resmat = zeros(ComplexF64, nJ, nJ, 2lm + 1, 2lm + 1)
nω = length(ωvec)
@sync for l1 = -lm:lm, l2 = -lm:lm
idx1 = lm + l1 + 1
idx2 = lm + l2 + 1
Threads.@spawn for j1 = 1:nJ, j2 = 1:nJ
s = zero(ComplexF64)
for i in 1:(nω-1)
tmpy1 = Zvec[i] * conj.(matSlωJ[idx1, i, j1]) * matSlωJ[idx2, i, j2]
tmpy2 = Zvec[i+1] * conj.(matSlωJ[idx1, i+1, j1]) * matSlωJ[idx2, i+1, j2]
s += (tmpy1 + tmpy2) * (ωvec[i+1] - ωvec[i])
end
resmat[j1, j2, idx1, idx2] = 0.5 * s
end
end
resmat
end
matS = rand(ComplexF64, 5, 1000, 60);
impedance = rand(1000);
ωvec = collect(range(0.0, step=0.01, length=1000));
# @benchmark funF2($matS, $impedance, $ωvec, 60, 2)
# @benchmark funF3($matS, $impedance, $ωvec, 60, 2)
I ran @benchmark funF2($matS, $impedance, $ωvec, 60, 2)
and my PC was fine. But as soon as I run @benchmark funF3($matS, $impedance, $ωvec, 60, 2)
, the screen will definitely go black immediately, and all the peripherals plugged into the back of the computer case will power off. The hard drive indicator light inserted into the front panel of the computer case, memory module RGB light, and fan are all working. Moreover, pressing the shutdown button at this time will not shut down. But when the power switch is turned off and immediately turned back on, it automatically turns on.
It has been tested on different machines, and other machines do not go black, so it is not a problem with the code. I have tested with different Julia versions on the same machine, but the screen still goes black, so it is not a bug in the Julia version. So it should be a hardware problem.
But what hardware problem is that? Did funF3
bring more pressure than funF2
to memory module or CPU?
And I have wiped the connecting finger of memory module. It didn’t work.
This is my computer hardware information: