Skip to content

Instantly share code, notes, and snippets.

@felixjung
Created June 16, 2014 12:37
Show Gist options
  • Save felixjung/b5a25f059d5d51647422 to your computer and use it in GitHub Desktop.
Save felixjung/b5a25f059d5d51647422 to your computer and use it in GitHub Desktop.
Parallel for loop in Julia
# Prepare parallel computing
n_cpu_reserve = 4 # Number of CPUs not to use
n_cpu = length(Sys.cpu_info()) # Obtain number of CPUs
n_workers = n_cpu - n_cpu_reserve # Set number of CPUs for computation
addprocs(n_workers - length(workers())) # Add additional CPUs if necessary
# Create a standard array for our task
my_array = dzeros((1000, 1000), workers(), [1, length(workers())])
@parallel for i = 1:size(my_array, 1)
for j = 1:size(my_array, 2)
my_array[j, i] = rand()
end
end
####
# Errors generated by this code
# ...
# in no method setindex!(DArray{Float64,2,Array{Float64,2}},Float64,Int64,Int64)
#####
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment