Parallel programming loops

Hi
I am new to parallel programming concept and I do not know how to make this piece of my code runs parallel

``````
scatter([Person[i]["x"] for i in 1:Npopulations], [Person[i]["y"] for i in1:Npopulations],legend=false, color = [Person[i]["color"] for i in 1:Npopulations])

``````

Could you post a simplified example that illustrates your problem? It is easiest to help if it is possible for one of us to paste the code into our Julia REPL and see the problem without having to edit anything (test it in your own REPL to make sure that you have no typos in it). You could also try to post this in the â€śGeneral Usageâ€ť forum as it sounds like quite an advanced question.

just edited it.

Okay, it still does not run in a newly started Julia, what I meant was something like the code shown below. Is this a good example of what you want to parallelize?:

``````using Plots, Random

x=collect(1:1000)
anim = @animate for ist=1:100
y=rand(1000)
scatter(x, y)
end
gif(anim,"rand.gif", fps=3)
``````

I canâ€™t answer this for you, but there was a post about it in 2020 Animation with threads in Plots.jl? . I would recommend that you post in â€śGeneral Usageâ€ť and see if anyone there can help. Use a title like â€ścan I parallelize animated gifs?â€ť.

Try creating arrays to store the results first and then use Threads.@threads on the for loop:

``````x = Vector{Any}(undef, Npopulations)
y = similar(x)
colors = Vector{Any}(undef, Npopulations)
x[i] = Person[i]["x"]
y[i] = Person[i]["y"]
colors[i] = Person[i]["color"]
end
scatter(x, y,legend=false, color = colors)
``````

Be sure to change the type Any to the appropriate type, this is for speed so each element isnâ€™t boxed. You should make sure that all elements of x and y are the same type. Each element of colours should have matching types too.

From the looks of this, it doesnâ€™t seem like doing this in parallel will speed it up by much, but it will create the intermediate arrays in parallel, but since there doesnâ€™t appear to be any significant processing (other than a dictionary lookup which is pretty fast), you may actually experience a slowdown, and the code is now harder to read and less maintainable.