Hello!

I have a parallel program, and when I try to save data, I encounter the following error. Should I use channels when saving data to a file? Or is the problem solved in some other way?

Thank you for your help

Fragment of code:

```
Threads.@threads for p2_index_range in eachindex(p2_range)
u0_start_2d = SVector{6}(matrix_u0_end[1, p2_index_range, :]);
for p1_index_range in eachindex(p1_range)
p1_index_range == 1 && continue
loc_params = copy(params);
loc_params[index_p1] = p1_range[p1_index_range];
loc_params[index_p2] = p2_range[p2_index_range];
prob = ODEProblem(sys, u0_start_2d, tspan, loc_params);
sol = solver(prob, integ_set);
if sol.retcode == ReturnCode.MaxIters
exitcode = 1;
end
u0_end_2d = sol[end];
matrix_u0_start[p1_index_range, p2_index_range, :] = u0_start_2d;
matrix_u0_end[p1_index_range, p2_index_range, :] = u0_end_2d;
matrix_params[p1_index_range, p2_index_range, :] = [loc_params[index_p1], loc_params[index_p2]]
u0_start_2d = u0_end_2d;
if exitcode == 1
exit();
end;
end
jldsave(filename_matrix_u0_start; matrix_u0_start);
jldsave(filename_matrix_u0_end; matrix_u0_end);
jldsave(filename_matrix_params; matrix_params);
end
```

Errors:

```
ERROR: TaskFailedException
nested task error: ArgumentError: attempted to truncate a file that was already open
Stacktrace:
[1] jldopen(fname::String, wr::Bool, create::Bool, truncate::Bool, iotype::Type{JLD2.MmapIO}; fallback::Type{IOStream}, compress::Bool, mmaparrays::Bool, typemap::Dict{String, Any}, parallel_read::Bool)
@ JLD2 ~/.julia/packages/JLD2/IsVcY/src/JLD2.jl:334
[2] jldopen(fname::String, mode::String; iotype::Type, kwargs::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:compress,), Tuple{Bool}}})
@ JLD2 ~/.julia/packages/JLD2/IsVcY/src/JLD2.jl:444
[3] jldopen(::Function, ::String, ::Vararg{String}; kws::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:compress, :iotype), Tuple{Bool, DataType}}})
@ JLD2 ~/.julia/packages/JLD2/IsVcY/src/loadsave.jl:2
[4] jldopen
@ ~/.julia/packages/JLD2/IsVcY/src/loadsave.jl:1 [inlined]
[5] #jldsave#81
@ ~/.julia/packages/JLD2/IsVcY/src/loadsave.jl:243 [inlined]
[6] jldsave (repeats 2 times)
@ ~/.julia/packages/JLD2/IsVcY/src/loadsave.jl:240 [inlined]
[7] macro expansion
@ ~/work/repo_ds/dynamical-systems/TM6_glial_ECM/dia of LSE/inheritance/includes/parallel_map_u0s.jl:132 [inlined]
[8] (::var"#16#threadsfor_fun#27"{var"#16#threadsfor_fun#26#28"{typeof(TM6_glial_ECM), Vector{Float64}, Tuple{Float64, Float64}, NamedTuple{(:alg, :adaptive, :abstol, :reltol), Tuple{Vern9{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Bool, Float64, Float64}}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, String, String, String, Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}, Int64, Int64, Base.OneTo{Int64}}})(tid::Int64; onethread::Bool)
@ Main ./threadingconstructs.jl:200
[9] #16#threadsfor_fun
@ ./threadingconstructs.jl:167 [inlined]
[10] (::Base.Threads.var"#1#2"{var"#16#threadsfor_fun#27"{var"#16#threadsfor_fun#26#28"{typeof(TM6_glial_ECM), Vector{Float64}, Tuple{Float64, Float64}, NamedTuple{(:alg, :adaptive, :abstol, :reltol), Tuple{Vern9{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Bool, Float64, Float64}}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, String, String, String, Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}, Int64, Int64, Base.OneTo{Int64}}}, Int64})()
@ Base.Threads ./threadingconstructs.jl:139
...and 3 more exceptions.
Stacktrace:
[1] threading_run(fun::var"#16#threadsfor_fun#27"{var"#16#threadsfor_fun#26#28"{typeof(TM6_glial_ECM), Vector{Float64}, Tuple{Float64, Float64}, NamedTuple{(:alg, :adaptive, :abstol, :reltol), Tuple{Vern9{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Bool, Float64, Float64}}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, String, String, String, Array{Float64, 3}, Array{Float64, 3}, Array{Float64, 3}, Int64, Int64, Base.OneTo{Int64}}}, static::Bool)
@ Base.Threads ./threadingconstructs.jl:157
[2] macro expansion
@ ./threadingconstructs.jl:205 [inlined]
[3] paralel_2pmap(sys::Function, params::Vector{Float64}, u0_initial::SVector{6, Float64}, tspan::Tuple{Float64, Float64}, integ_set::NamedTuple{(:alg, :adaptive, :abstol, :reltol), Tuple{Vern9{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Bool, Float64, Float64}}, control_params::Vector{Any}, p1_range::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, p2_range::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
@ Main ~/work/repo_ds/dynamical-systems/TM6_glial_ECM/dia of LSE/inheritance/includes/parallel_map_u0s.jl:103
[4] top-level scope
@ ~/work/repo_ds/dynamical-systems/TM6_glial_ECM/dia of LSE/inheritance/src/main.jl:49
```