Groups 176 of 99+ julia-users › Array within a function not know on worker 7 posts by 3 authors digxx 12 8 15 As far as I understood everywhere lets every worker know about some function for example everywhere f x x. 2 Now my function additionally accesses to some big array for example everywhere f x sum x. r ,2 where r could be sth like r zeros 1,100 r 1,: 1:100 When I now call the function the worker doesnt know about r, but variables like r do not need an everywhere,right? How can I achieve this ? Pieterjan Robbe 12 9 15 I have been struggling with this issue as well. Unfortunately, Julia does not have shared memory parallelisation yet , so there is no 'nice' solution for this. You could of course construct your function like everywhere f x,r sum x. r,2 But, if you don't want to pass the array r every time you call the function, you can write a separate file, say myFile-jl that contains r collect 1:100 f x sum x. r Next, include the file on all processors, like everywhere include myFile-jl then you can do a ones 100 r spawnat 2 f a fetch r which gives 5.187378 as result. Unfortunately, this means that every processor will contain its own copy of the array r, which does not make sense if you are running your code on a multicore machine with only one physical memory. Luckily, there is something like Shared Arrays for this. Tim Holy 12 9 15 Re: julia-users Re: Array within a function not know on worker On Wednesday, December 09, 2015 01:11:13 AM Pieterjan Robbe wrote: I have been struggling with this issue as well. Unfortunately, Julia does not have shared memory parallelisation Not true. See http: docs.julialang.org en stable manual parallel-computing shared-arrays yet https: github.com JuliaLang julia issues 1790 , so there is no 'nice' solution for this. You could of course construct your function like everywhere f x,r sum x. r,2 But, if you don't want to pass the array r every time you call the function, you can write a separate file, say myFile-jl that contains r collect 1:100 f x sum x. r Next, include the file on all processors, like everywhere include myFile-jl then you can do a ones 100 r spawnat 2 f a fetch r which gives 5.187378 as result. Unfortunately, this means that every processor will contain its own copy of the array r, which does not make sense if you are running your code on a multicore machine with only one physical memory. Luckily, there is something like Shared Arrays http: docs.julialang.org en latest stdlib parallel Base.SharedArray for this. digxx 12 10 15 Re: julia-users Re: Array within a function not know on worker Not quite sure what you mean with SharedArrays!? Ok, I know what a SharedArray is but even if I specify r as a SharedArray like r SharedArray Float64,1,100 r 1,: collect 1:100 it doesnt work. So what in particular are you refering to to get it run? Apart from what was already mentioned as workaround by P.Robbe digxx 12 10 15 Re: julia-users Re: Array within a function not know on worker 2 other questions: is the function fzero not defined for parallelism? and is it necessary to define calculate the r in the separate file i want to include? Because id like to do the calculation of this array r in the main file only once since but then again when I do it, the function included as a separate file doesnt know about r. On the other hand I try to calculate this r in the separate file it includes running serial loops which give an error but when I run this loop in the main file everything seems fine. digxx 12 10 15 Re: julia-users Re: Array within a function not know on worker Maybe to clarify: The first question regarding fzero: I have this fzero in the serial loop but it doesnt work in a separate file, though parallel loop in the main file with fzero DOES work. digxx 12 10 15 Re: julia-users Re: Array within a function not know on worker ok sorry, needed an additional using Roots though I called it in the main function already.