Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jupyter Notebook multithreading #882

Open
lzxnl opened this issue Oct 23, 2019 · 6 comments
Open

Jupyter Notebook multithreading #882

lzxnl opened this issue Oct 23, 2019 · 6 comments

Comments

@lzxnl
Copy link

lzxnl commented Oct 23, 2019

I'm running Jupyter Notebooks on Julia 1.2 and if I use Base.Threads, set Threads.nthreads() = 12, confirm that it's 12, and then run something simple like
for i in 1:100
println(Threads.threadid())
end
I always get a long stream of 1s. Any attempt to multithread results in no change to performance as only one thread is ever in use. However, running the same code in Juno/Atom does print out different threadids. Does anyone have ideas?

@lzxnl lzxnl changed the title Jupyter Notebook multithreadimg Jupyter Notebook multithreading Oct 23, 2019
@twavv
Copy link
Contributor

twavv commented Jan 28, 2020

There's no way to start more Julia threads at runtime, unfortunately. Beyond that,

Threads.nthread() = 12

is not really idiomatic Julia. All it does is overwrite the function that calls into Julia's internals to determine the number of threads so that it just returns the number 12 - it doesn't actually increase the number of threads in any way. Typically, the kinds of APIs that do that kind of thing will look like Threads.set_nthreads!(12) (but, as I mentioned, that doesn't exist in Julia).

If you want to do multithreading in Julia with Jupyter, you have to create a new kernelspec.

using IJulia
IJulia.installkernel("Julia 12 Threads", env=Dict(
    "JULIA_NUM_THREADS" => "12",
))

Then you can create a new notebook using that kernel (or change the kernel of an existing notebook in the Kernel > Change Kernel menu) and run code as you expect.

Threads.@threads for i in 1:10
    println(Threads.threadid())
end

outputs (on my machine)

5
3
6
4
8
7
2
9
1
10

@stevengj
Copy link
Member

We should update the installkernel command to provide a way to set custom environment variables...

@twavv
Copy link
Contributor

twavv commented Feb 5, 2020

Also, #854 has kind of been left to rot a bit and could be solved at the same time.

@stevengj
Copy link
Member

stevengj commented Feb 5, 2020

#854 is orthogonal to adding support for specifying environment vars, and combining unrelated changes into a single PR is not a good way to speed things up.

@twavv
Copy link
Contributor

twavv commented Feb 5, 2020

Fair enough. Both are related to installkernel but the actual features don't depend on each-other.

@nilshg
Copy link

nilshg commented Sep 26, 2024

This can be closed - installkernel allows for adding kernels with multiple threads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants