How to broadcast already defined function to all worker processes in jupyter?

Hello everyone,

I am a beginner for Julia. When I use Distributed to speed up my program, I found such a problem: I have defined a large number of functions and constants in Jupyter, if I need to use Distributed, then I must add @everywhere before each function, which is inconvenient and not conducive to code portability.

So, how to broadcast already defined function to all worker processes in jupyter? And don’t need to modify the previous definition. If the previous function must be redefined, it will be sad.

For the constants, I can use

@async @everywhere constant0, constant1

to broadcast. But for the functions, this will not succeed.

I hope someone can guide me. Thank you very much!

I believe usually what people do is do:

@everywhere include("<file>.jl")

So that everything in the file is loaded into all the instances. So put your startup code in one file (or files), your implementation in other files, then have your startup code load the implementation onto all instances using the @everywhere include.

This assumes that all instances have access to the source files…

1 Like