Currently I'm learning about C and OpenMP. I wrote the following program:
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#define N 960
int main (int argc, char *argv[])
{
int nthreads, tid, i, j;
double a[N][N];
/* Fork a team of threads */
#pragma omp parallel shared(nthreads) private(i,tid,a)
{
tid = omp_get_thread_num();
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
printf("Thread %d starting...\n", tid);
#pragma omp for
for (i=0; i<N; i++)
{
for (j=0; j<N; j++)
{
a[i][j] = tid + i + j;
}
}
}
}
When I compile the code it compiles. I use in a Linux terminal:
gcc name.c -o name -lm -fopenmp
When I want to excecute the program I get a segmentation error. I searched for a definition:
A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed
I don't really see how I try to access a memory that is not allowed. Could I please get feedback on why I get a segmentation error?