Mutlithread functions within for loop

Hello everyone, im kinda new to julia (self learning since a few weeks).

I am wondering how to use multithreading properly for functions within a for loop like:

A = … (some 3d array)
B = …(some 3d array)

for i in 1:100
update_A!(A,…)
update_B!(B,…)
end

in each of the update functions a 3x nested loop is performed. However, the execution order of update_A and update_B doesnt matter.
I hope to improve the performance by multithread function A and B somehow.

P.S. Multi processing is no real option, since the inputs are shared and large.
So, allocating these to another process takes too much time and memory.

Thanks in advance for any help

mhh i guess

function update()
@sync @Threads.threads for i in 1:1
update_A!(A,…)
update_B!(B,…)

end

for i in 1:100
update()

end

works out.

Well without knowing what these functions do there isn’t much we can do/say to help you. So I’ll just point you to the Julia manual on using @threads.

Be sure that you have no data races and avoid using threadid(). Also you don’t need @sync in front of @threads.

For future posts I’ll also point you to this topic :slight_smile:

For multithreading with shared memory, I recommend you to have a look at this post

If you’d like more concrete help, I’d advise you to share a minimal working example so we can see more clearly what you have in mind.