1

I have been having a problem with multithreading in Julia that I have managed to break down to the simple example:

The script

using PyCall, PyPlot
@pyimport numpy as np
N = 1000
a = np.zeros(N)
Threads.@threads for i in 1:length(a)
    #println("hello from thread ",Threads.threadid())
    a[i] = sin(i*pi/N)
end
plt.plot(a)

runs, whereas

using PyCall, PyPlot
@pyimport numpy as np
N = 1000
a = np.zeros(N)
Threads.@threads for i in 1:length(a)
    #println("hello from thread ",Threads.threadid())
    a[i] = np.sin(i*pi/N)
end
plt.plot(a)

does not. Instead the jupyter kernel dies. So apparently there is a problem using functions from pyimport inside of a parallel loop in Julia? The loop also runs well with numpy call in serial.

I am using jupyter lab on a redhat cluster. Using 32 threads. Running Julia 1.7.1

Oyvach
  • 11
  • 2

1 Answers1

0

I managed to get the example to run in parallel by using Julia's distributed package instead of the threading.

Then

Using Distributed
N = 1000
a = np.zeros(N)
function sinmake(i)
    a[i] = np.sin(i*pi/N)
end
pmap(sinmake,1:N)
plt.plot(a)

It would be nice to be able to use python packages in thread-parallelism as well, but this solves my problem for now.

Oyvach
  • 11
  • 2