I am new to Julia and want to multithread a portion of my code in Julia. Below is the code I have written, but it is throwing an error. Could anyone please help me in this regard?
t2new = SharedArray{Float64}(nocc,nocc,nvir,nvir)
#for (i,j) in pair_ls
Threads.@threads for i in 1:nocc
for j in 1:i
@fastmath tau_ij_ = @views tau[i,j,:,:]
@inbounds begin
@tensoropt (k=>x, t=>100x, d=>100x, c=>100x, a=>100x, b=>100x) begin
ttmp1[k,t,c] = Lov_T120[k,d,t]*tau_ij_[c,d]
ttmp2[k,a] = ttmp1[k,t,c]*Lvv_df[t,a,c]
temp[a,b] = (-t1[k,b]*ttmp2[k,a])
ttmp3[k,t,d] = Lov_T120[k,c,t]*tau_ij_[c,d]
ttmp4[k,b] = ttmp3[k,t,d]*Lvv_df[t,b,d]
temp[a,b] -= t1[k,a]*ttmp4[k,b]
end
Threads.atomic_add!(t2new[i,j,:,:], temp)
if i != j
Threads.atomic_add!(t2new[j,i,:,:], transpose(temp))
end
end #@inbounds
end
end
JULIA: TaskFailedException
Stacktrace:
[1] wait
@ ./task.jl:345 [inlined]
[2] threading_run(fun::var"#141#threadsfor_fun#3"{var"#141#threadsfor_fun#1#4"{Matrix{Float64}, Array{Float64, 3}, Array{Float64, 3}, UnitRange{Int64}}}, static::Bool)
@ Base.Threads ./threadingconstructs.jl:38
[3] macro expansion
@ ./threadingconstructs.jl:89 [inlined]
[4] update_cc_amps(t1::Matrix{Float64}, t2::Array{Float64, 4}, eris::PyObject, ovov::Array{Float64, 4}, oovv::Array{Float64, 4}, ovvv::Array{Float64, 4}, ovoo::Array{Float64, 4}, oooo::Array{Float64, 4}, fock::Matrix{Float64}, foo::Matrix{Float64}, fov::Matrix{Float64}, fvo::Matrix{Float64}, fvv::Matrix{Float64}, Lov_df::Array{Float64, 3}, Lvv_df::Array{Float64, 3}, Loo_df::Array{Float64, 3})
@ Main ~/bagh_install/bagh_1/bagh/bagh_code/ccsd/ccsd_incr4_multhreading.jl:459
[5] macro expansion
@ ./timing.jl:262 [inlined]
[6] cc_iter(t1::Matrix{Float64}, t2::Array{Float64, 4}, eris::PyObject, cc_input::PyObject)
@ Main ~/bagh_install/bagh_1/bagh/bagh_code/ccsd/ccsd_incr4_multhreading.jl:231
[7] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base ./essentials.jl:729
[8] invokelatest(::Any, ::Any, ::Vararg{Any})
@ Base ./essentials.jl:726
[9] _pyjlwrap_call(f::Function, args_::Ptr{PyCall.PyObject_struct}, kw_::Ptr{PyCall.PyObject_struct})
@ PyCall ~/.julia/packages/PyCall/twYvK/src/callback.jl:28
[10] pyjlwrap_call(self_::Ptr{PyCall.PyObject_struct}, args_::Ptr{PyCall.PyObject_struct}, kw_::Ptr{PyCall.PyObject_struct})
@ PyCall ~/.julia/packages/PyCall/twYvK/src/callback.jl:44
nested task error: MethodError: no method matching atomic_add!(::Matrix{Float64}, ::Matrix{Float64})
Stacktrace:
[1] macro expansion
@ ~/bagh_install/bagh_1/bagh/bagh_code/ccsd/ccsd_incr4_multhreading.jl:475 [inlined]
[2] (::var"#141#threadsfor_fun#3"{var"#141#threadsfor_fun#1#4"{Matrix{Float64}, Array{Float64, 3}, Array{Float64, 3}, UnitRange{Int64}}})(tid::Int64; onethread::Bool)
@ Main ./threadingconstructs.jl:84
[3] #141#threadsfor_fun
@ ./threadingconstructs.jl:51 [inlined]
[4] (::Base.Threads.var"#1#2"{var"#141#threadsfor_fun#3"{var"#141#threadsfor_fun#1#4"{Matrix{Float64}, Array{Float64, 3}, Array{Float64, 3}, UnitRange{Int64}}}, Int64})()
@ Base.Threads ./threadingconstructs.jl:30>```