Segmentation fault in omp program

Hi,
I am trying to compile the following omp program but its generating segmentation fault.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

//compute the sum of two arrays in parallel 
#include <stdio.h>
#include <omp.h>
#define N 1000000
#define CHUNKSIZE 10000
int main(void) { 
  double a[N], b[N], c[N];
  long i, chunk;

  /* Initialize arrays a and b */
  for (i = 0; i < N; i++) {
    a[i] = i * 2.0;
    b[i] = i * 3.0;
  }
  chunk = CHUNKSIZE;

  #pragma omp parallel shared(a, b, c, chunk) private(i)
  { 
    #pragma omp for schedule (dynamic, chunk)             
    for (i = 0; i < N; i++) {
      c[i] = a[i] + b[i];
      printf ("%lf\n", c[10]);
    }
  }

}


The output is:

$ gcc -fopenmp sumArr.c
$ ./a.out
Segmentation fault (core dumped)


Some body please guide me.

Zulfi.
Be aware that stack space is finite.
Usually just a few MB, compared to the GB of memory you have for other purposes.

So perhaps
static double a[N], b[N], c[N];
Hi,
Thanks. I reduced the size of N and it removed the error.
God bless you.

Zulfi.
Registered users can post here. Sign in or register to post.