Hi all,

I have been working on a project that involves a Julia front-end calling a 
C back-end (it's a neural network simulator, in case you're wondering). 
 Since the C side is essentially a bunch of nested for-loops, I've been 
experimenting with using Cilk+ (via GCC5) to parallelize things.  Loading 
and running the C code from within a Julia session works just fine, both 
from the command-line and from Jupyter.  But using Cilk somehow messes with 
PyPlot.

Specifically, here is a minimal example that produces the problem I see in 
Jupyter (relevant code below):

In [1]: include("hello.jl")

hello 5
hello 0
hello 2
hello 1
hello 6
hello 3
hello 4
hello 7
hello 8
hello 9


In [2]: using PyPlot

Warning: error initializing module PyPlot:
ErrorException("Failed to pyimport("matplotlib"): PyPlot will not work until 
you have a functioning matplotlib module.

For automated Matplotlib installation, try configuring PyCall to use the Conda 
Python distribution within Julia.  Relaunch Julia and run:
      ENV["PYTHON"]=""
      Pkg.build("PyCall")
      using PyPlot

pyimport exception was: PyError (:PyImport_ImportModule) <type 
'exceptions.AttributeError'>
AttributeError('_ARRAY_API not found',)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 
180, in <module>
    from matplotlib.cbook import is_string_like
  File "/usr/local/lib/python2.7/site-packages/matplotlib/cbook.py", line 34, 
in <module>
    import numpy.ma as ma
  File "/usr/local/lib/python2.7/site-packages/numpy/ma/__init__.py", line 46, 
in <module>
    from . import core
  File "/usr/local/lib/python2.7/site-packages/numpy/ma/core.py", line 30, in 
<module>
    import numpy.core.umath as umath
")

The code:

hello.jl:
module hello ccall((:hello, "hello.dylib"), Void, (Cint,), 10) end#module 


hello.c:
/** compile with gcc -fcilkplus -dynamiclib -o hello.dylib hello.c 
-lcilkrts **/
#include <stdio.h> #include <cilk/cilk.h> #include <unistd.h> void 
hello(int n) { int i; cilk_for (i=1; i <= n; i++ ) { sleep(1.0); 
printf("hello %d\n",i); } }

I'm on a Mac (10.11) running Julia 0.4.3, PyPlot 2.1.1, and gcc 5.3.0 
(macports). My installation of PyPlot has been working just fine except for 
this particular issue.

Also, if I change the "cilk_for" in hello.c to "for" (but still link 
libcilkrts) then PyPlot would load and work just fine.

Any idea what's going on? I'm not sure this is a problem with Julia or 
PyPlot per se, but don't know enough about the ffi, the cilk runtime, or 
PyPlot/PyCall internals to figure this out.

Thanks for any pointers!

KL

Reply via email to