Julia has 3 kinds of parallelism.
The well known, safe, slowish and easyish, distributed parallelism, via pmap
, @spawn
and @remotecall
.
The wellish known, very safe, very easy, not-actually-parallelism, asynchronous parallelism via @async
.
And the more obscure, less documented, experimental, really unsafe, shared memory parallelism via @threads
.
It is the last we are going to talk about today.
I’m not sure if I can actually teach someone how to write threaded code.
Let alone efficient threaded code.
But this is me giving it a shot.
The example here is going to be fairly complex.
For a much simpler example of use,
on a problem that is more easily parallelizable,
see my recent stackoverflow post on parallelizing sorting.
(Spoilers: in the end I don’t manage to extract any serious performance gains from paralyzing this prime search. Unlike parallelizing that sorting. Paralising sorting worked out great)