jit doesn't like threading?!?

Asked by Thomas Fraunholz

Hi,
I tried to distribute my computations on several threads using the python threading module. Everything works fine using a single thread. But it seems to me that jit is somehow confused by adding an additional thread. As I am not quite well informed about the jit module I would like to know if somebody has already seen this before or knows about this constraint. It would help a lot if somebody knows for sure that this should work fine (or perhaps not).
Thanks a lot!
Thomas

--------
> python main.py
Thread-1 working!
Thread-2 working!
Solving linear variational problem.
Solving linear variational problem.
3 cells out of 6 marked for refinement (50.0%).
Number of cells increased from 6 to 10 (66.7% increase).
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File ".../methods.py", line 74, in run
    eta, eta_list = afem_estimate(param, mesh, u_h, f)
  File ".../methods.py", line 206, in afem_estimate
    eta_E = assemble(eta_e, mesh=space.mesh())
  File "/usr/lib/python2.7/dist-packages/dolfin/fem/assembling.py", line 157, in assemble
    common_cell=common_cell)
  File "/usr/lib/python2.7/dist-packages/dolfin/fem/form.py", line 54, in __init__
    common_cell)
  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 62, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 139, in jit
    return jit_compile(form, parameters=p, common_cell=common_cell)
  File "/usr/lib/python2.7/dist-packages/ffc/jitcompiler.py", line 73, in jit
    return jit_form(object, parameters, common_cell)
  File "/usr/lib/python2.7/dist-packages/ffc/jitcompiler.py", line 102, in jit_form
    module = instant.import_module(jit_object, cache_dir=cache_dir)
  File "/usr/lib/python2.7/dist-packages/instant/cache.py", line 156, in import_module
    return check_disk_cache(modulename, cache_dir, moduleids)
  File "/usr/lib/python2.7/dist-packages/instant/cache.py", line 126, in check_disk_cache
    release_lock(lock)
  File "/usr/lib/python2.7/dist-packages/instant/locking.py", line 46, in release_lock
    lockname = _lock_names[lock.fileno()]
ValueError: I/O operation on closed file

Solving linear variational problem.
5 cells out of 10 marked for refinement (50.0%).
Number of cells increased from 10 to 18 (80.0% increase).
Solving linear variational problem.
8 cells out of 18 marked for refinement (44.4%).
Number of cells increased from 18 to 30 (66.7% increase).
Solving linear variational problem.
12 cells out of 30 marked for refinement (40.0%).
Number of cells increased from 30 to 57 (90.0% increase).

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Thomas Fraunholz
Solved:
Last query:
Last reply:
Revision history for this message
Martin Sandve Alnæs (martinal) said :
#1

You're probably right, and there are probably other
Python parts of FEniCS that are not threadsafe.

The thing is, Python threads are not really concurrent,
so you may not get the speedup you're looking for
anyway without significant work... Therefore, thread
safety has not really been an issue.

However, the jit is designed to work with multiple
processes. Maybe you'll have better luck with
the multiprocessing module, or just use the existing
MPI support.

Martin

On 30 August 2011 10:35, Thomas Fraunholz
<email address hidden> wrote:
> New question #169569 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/169569
>
> Hi,
> I tried to distribute my computations on several threads using the python threading module. Everything works fine using a single thread. But it seems to me that jit is somehow confused by adding an additional thread. As I am not quite well informed about the jit module I would like to know if somebody has already seen this before or knows about this constraint. It would help a lot if somebody knows for sure that this should work fine (or perhaps not).
> Thanks a lot!
> Thomas
>
>
> --------
>> python main.py
> Thread-1 working!
> Thread-2 working!
> Solving linear variational problem.
> Solving linear variational problem.
> 3 cells out of 6 marked for refinement (50.0%).
> Number of cells increased from 6 to 10 (66.7% increase).
> Exception in thread Thread-1:
> Traceback (most recent call last):
>  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
>    self.run()
>  File ".../methods.py", line 74, in run
>    eta, eta_list = afem_estimate(param, mesh, u_h, f)
>  File ".../methods.py", line 206, in afem_estimate
>    eta_E = assemble(eta_e, mesh=space.mesh())
>  File "/usr/lib/python2.7/dist-packages/dolfin/fem/assembling.py", line 157, in assemble
>    common_cell=common_cell)
>  File "/usr/lib/python2.7/dist-packages/dolfin/fem/form.py", line 54, in __init__
>    common_cell)
>  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 62, in mpi_jit
>    return local_jit(*args, **kwargs)
>  File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 139, in jit
>    return jit_compile(form, parameters=p, common_cell=common_cell)
>  File "/usr/lib/python2.7/dist-packages/ffc/jitcompiler.py", line 73, in jit
>    return jit_form(object, parameters, common_cell)
>  File "/usr/lib/python2.7/dist-packages/ffc/jitcompiler.py", line 102, in jit_form
>    module = instant.import_module(jit_object, cache_dir=cache_dir)
>  File "/usr/lib/python2.7/dist-packages/instant/cache.py", line 156, in import_module
>    return check_disk_cache(modulename, cache_dir, moduleids)
>  File "/usr/lib/python2.7/dist-packages/instant/cache.py", line 126, in check_disk_cache
>    release_lock(lock)
>  File "/usr/lib/python2.7/dist-packages/instant/locking.py", line 46, in release_lock
>    lockname = _lock_names[lock.fileno()]
> ValueError: I/O operation on closed file
>
> Solving linear variational problem.
> 5 cells out of 10 marked for refinement (50.0%).
> Number of cells increased from 10 to 18 (80.0% increase).
> Solving linear variational problem.
> 8 cells out of 18 marked for refinement (44.4%).
> Number of cells increased from 18 to 30 (66.7% increase).
> Solving linear variational problem.
> 12 cells out of 30 marked for refinement (40.0%).
> Number of cells increased from 30 to 57 (90.0% increase).
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Thomas Fraunholz (sleater) said :
#2

Thanks for the helpfull advice! Multiprocessing works fine.