[SciPy-user] Are cf2py threadsafe and cf2py inplace incompatible?

Anand Patil anand.prabhakar.patil@gmail....
Mon Jun 23 17:12:56 CDT 2008


Hi all,

I'm trying to write a multithreaded function where each thread fills  
in a portion of an array. I'm on a MacBook Pro using Python 2.5 and  
the numpy subversion head. The following program produces intermittent  
seg faults:

---------------------


from f2py_test import test
from numpy import *
from threading import Thread, Lock
from copy import copy

D = empty((60,60))

n_threads = 4
threads = []

for i in xrange(n_threads):

     new_thread= Thread(target=test, args=(D,))
     threads.append(new_thread)

     new_thread.start()

[thread.join() for thread in threads]


-----------------

where f2py_test.f is just

-----------------


       SUBROUTINE test(D,nx)

cf2py intent(inplace) D
cf2py intent(hide) nx
cf2py threadsafe

       DOUBLE PRECISION D(nx,nx)
       INTEGER nx

! Writing to D would happen here.
! Each thread would get some of the columns.

       RETURN
       END


------------------


Is there any way I can make this safe without computing the pieces  
independently and copying them in in serial?

Thanks very much,
Anand


The relevant bits of the crash report are

Process:         Python [6796]
Path:            /Library/Frameworks/Python.framework/Versions/2.5/ 
Resources/Python.app/Contents/MacOS/Python
Identifier:      Python
Version:         ??? (???)
Code Type:       X86 (Native)
Parent Process:  bash [2950]

Date/Time:       2008-06-23 22:58:21.777 +0100
OS Version:      Mac OS X 10.5.3 (9D34)
Report Version:  6

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000039cc148
Crashed Thread:  3

...

Thread 3 Crashed:
0   multiarray.so                 	0x011c135b _strided_byte_copy + 427  
(arrayobject.c:350)
1   multiarray.so                 	0x011f071d _copy_from_same_shape +  
525 (arrayobject.c:978)
2   multiarray.so                 	0x012086eb _array_copy_into + 1195  
(arrayobject.c:1134)
3   distances.so                  	0x031d0453 array_from_pyobj + 2179  
(fortranobject.c:660)
4   distances.so                  	0x031cd5aa f2py_rout_distances_test  
+ 170 (distancesmodule.c:233)
5   distances.so                  	0x031cee54 fortran_call + 68  
(fortranobject.c:323)
6   org.python.python             	0x0019b5d2 PyObject_Call + 50
7   org.python.python             	0x0022a9e4 PyEval_EvalFrameEx + 15492
8   org.python.python             	0x0022d445 PyEval_EvalFrameEx + 26341
9   org.python.python             	0x0022d445 PyEval_EvalFrameEx + 26341
10  org.python.python             	0x0022dba5 PyEval_EvalCodeEx + 1845
11  org.python.python             	0x001bf4ce function_call + 446
12  org.python.python             	0x0019b5d2 PyObject_Call + 50
13  org.python.python             	0x001a3732 instancemethod_call + 354
14  org.python.python             	0x0019b5d2 PyObject_Call + 50
15  org.python.python             	0x00225c26  
PyEval_CallObjectWithKeywords + 118
16  org.python.python             	0x0026277f t_bootstrap + 63
17  libSystem.B.dylib             	0x93ff06f5 _pthread_start + 321
18  libSystem.B.dylib             	0x93ff05b2 thread_start + 34

...

Thread 3 crashed with X86 Thread State (32-bit):
   eax: 0x00000000  ebx: 0x011c11bb  ecx: 0x039cc148  edx: 0x00000000
   edi: 0x00000021  esi: 0x03c39008  ebp: 0xb0184098  esp: 0xb0184080
    ss: 0x0000001f  efl: 0x00010293  eip: 0x011c135b   cs: 0x00000017
    ds: 0x0000001f   es: 0x0000001f   fs: 0x0000001f   gs: 0x00000037
   cr2: 0x039cc148



More information about the SciPy-user mailing list