First, take a look at this topic on how to format and phrase your question to get better help.
Mostly, it’s very helpful if you can post a minimal, working, self-contained example. It’s not clear from this code what main
does, how n
is supposed to be used in the loop, how often you’ll push to the vectors, if you actually intend to print for each iteration, etc.
Is @distributed
what you want (parallel computing), and not just @threads
(multiple threads in a single computer)? More details here.
Multi-threading is usually the last optimization step I do, since it tends to complicate the code, and for unoptimized code you can typically achieve much better speedups using other techniques. Is the rest of your code already optimized? Proper choice of data structures and algorithms, type stability, caching, vectorization where applicable?