You are right, that makes it more conceptually difficult. The reason that I coded it this way is that the loops are both sometimes small, and run over a range that is not divisible by the number of threads. If it works properly, this should work faster without needing to construct a complicated iterable. The reason I thought it would work is because of Parallelize nested loop in v1.72. Just from trying printing threadid, mu and i anside of each line, it seems to divide the different combinations of parameters up OK.
Anyway, I have the same problem when parallellizing one loop, which I of course checked.
Also, all the MWE’s I have tried to build up until now with a similar structure have worked. My question is basically just where to look for a race condition in my large chunk of code. Could that occur, for example, if I have a global variable N which is constant but is used in the code? And could it happen if I pass the same parameter p to run_test in each loop? My guess is yes, but I would expect that a) they are rare, and b) julia has easy ways to program something to prevent this from happening, which I could sadly not find in the documentation. It seems to me that the compiler could also be clever enough to avoid these types of race conditions, but I just don’t know in which cases it does. I should have focused my question more in that direction.