Parallel for nested loop with inner loop first, and then outer loop

Hi, I am wondering how could I use @spawn to parallelize the nested loops, and to run the inner loop in parallel first, and then run the outer loop in parallel after that. Thanks

Using Threads.nthreads(), you can find the number of thread Julia has. You can then calculate how many iterations of outer loop you want to run at once. Be careful though, spawning task takes resource and if the iteration is fast, spawning a new task for every iteration in the inner loop might not be a good might not be a good idea. Also be careful of false sharing among other things.

Thank you for your reply. I have added Threads.@threads in the outer loop, but it looks like only for outer loop. But since my inner loop is time consuming, I am wondering that how could I just multithreading my inner loop? Thanks