pyccel: Segmentation fault when doing a "for reduction" with openmp
When pyccelizing a function that does a for reduction of two arrays with openmp, a segmentation fault occurs. The same code with only one array in the for reduction does not encounter this error.
As an example take a file pyccel_test.py with two functions mult_reduct1 and mult_reduct2:
def mult_reduct1(arr : 'float[:,:]', arr1 : 'float[:,:]'):
"""
Parameters:
2 arrays of the same size
"""
nx = arr.shape[1]
ny = arr.shape[0]
#$ omp parallel private (i, j)
#$ omp for reduction(+: arr1)
for i in range(nx):
j = i * i
arr1[i,0] = arr[i,0]**2
arr1[i,1] = arr[i,1]**2
#$ omp end parallel
def mult_reduct2(arr : 'float[:,:]', arr1 : 'float[:,:]', arr2 : 'float[:,:]'):
"""
Parameters:
3 arrays of the same size
"""
nx = arr.shape[1]
ny = arr.shape[0]
#$ omp parallel private (i, j)
#$ omp for reduction(+: arr1, arr2)
for i in range(nx):
j = i * i
arr1[i,0] = arr[i,0]**2
arr1[i,1] = arr[i,1]**2
arr2[i,0] = arr[i,0]**2
arr2[i,1] = arr[i,1]**2
#$ omp end parallel
which is pyccelized with the command pyccel --openmp pyccel_test.py. The pyccelization itself gives no errors.
When calling these functions in another python file with e.g.
import pyccel_test as pt
nx = 1000
ny = 1000
array = np.random.rand(nx,ny)
array1 = np.zeros(np.shape(array), dtype=float)
array2 = np.zeros(np.shape(array), dtype=float)
pt.mult_reduct1(array, array1)
print('\n results \n')
print(np.sum(array1))
pt.mult_reduct2(array, array1, array2)
print('\n results \n')
print(np.sum(array1))
print(np.sum(array2))
the output reads
results
674.2675057646197
Segmentation fault (core dumped)
I am using the newest pyccel version 1.5.2
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (13 by maintainers)
The good news is, I can reproduce this on my computer (Ubuntu gcc9.4) so I can play around and see if I find anything