Numerical ComputationParallel Computing
Parallel computing involves decomposing a computational task into subtasks which may be performed concurrently.
The problem of adding the numbers in an array is readily parallelizable, since we can subdivide the array, sum the values in each smaller array, and add up the resulting sums at the end.
You can start a Julia session with worker processes via
julia -p n and loading the distributed computing tools with
pmap(f,A)applies the function
fto each element of the collection
A, taking advantage of the available worker processes. For example, to check the primality of the positive integers up to 100,000 in parallel:
using Distributed, Primes pmap(isprime,2:100_000)
(op)is an operator, then
@distributed (op) for ... endassigns a subrange of the given
forloop to each worker. The values returned by the body of the loop are combined using the operator
op. For example, to sum a million random Gaussians in parallel fashion:
using Distributed @distributed (+) for i=1:1_000_000 randn() end
Congratulations! You have finished the Data Gymnasia numerical computation course.