0

I recently started learning openMP and I am trying to parallelize my code for convolution. Once I added #pragma to the for loop which is initializing the image array and there's no data dependency, the code broke and threw Segmentation fault (core dumped). I couldn't figure out what's wrong. Please help!

 // map values from original image to padded image #pragma omp parallel for schedule(static) for (size_t j = 0; j < n * n; j++) { size_t row = (j / n) + padding; size_t col = (j % n) + padding; size_t pos = (n + (padding * 2)) * row + col; padded_image[pos] = image[j]; } 
3
  • 1
    Where is output allocated / declared? Adding (or removing) code, and all of a sudden things break for no apparent reason, has all the earmarks of memory corruption. Commented Mar 16, 2020 at 20:04
  • You should provide the inputs for the function. It seems like your segfault happens because you are accessing memory which does not belong to you. Commented Mar 16, 2020 at 20:11
  • output is allocated in main() in another file. the code runs in sequential version but breaks in parallel version Commented Mar 16, 2020 at 20:40

1 Answer 1

1

The computed indices does not match with the allocated size. Indeed, the size of the allocated array padded_image does not depend on n while the accesses to the same in the targeted loop does. Regarding the loop, the size of the array should probably be: (n + (padding * 2)) * (n + (padding * 2)).

Please note that padded_image is not deleted. Moreover, modulus are very slow, please consider using two loops with an OpenMP clause collapse(2).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.