I am trying to add OpenMP parallelization to a working code (just to a single for
loop), however I cannot get rid of a segmentation fault. The problem arises from this line:
pos += sprintf(com + pos, "%d ", i);
com
is a character array, and I tried defining it as char com[255]
or char *com = malloc(255*sizeof(char))
, both inside and before the for
loop. I added private(com)
to #pragma omp parallel for
directive when I defined com
before the loop. I also tried initializing it and using firstprivate
. (pos
is an integer, initialized to 0
)
When I do not add -fopenmp
everything works fine, but with -fopenmp
it gives segfault. What am I missing?