I have some code that currently works in a shared memory environment with SharedArrays
structures that I want to migrate to using DistributedArrays
for a multi-node/distributed memory machine. Roughly, the key part of the code looks like:
f_vals = SharedArray{Float64}(n_samples);
path_avg = SharedArray{Float64}{n_steps}
@sync @distributed for i in 1:n_samples
path = generate_path(path_args); # generates a vector of size n_steps
f_vals[i] = f(path) # apply the scalar value function to this array
@. path_avg += path/n_samples; # compute the average path
end
I would like to compute these same quantities, in roughly the same way, using a for loop with DistributedArray
, but I haven’t found a good example of how to do this. Also, since the path_avg
variable is really represents a reduction across all processes, would that remain a SharedArray
? Note that other than this simple reduction, there is no interaction between the iterates. Thanks for any tips.