Created
June 16, 2014 12:37
-
-
Save felixjung/b5a25f059d5d51647422 to your computer and use it in GitHub Desktop.
Parallel for loop in Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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