-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathomp_bug4.c
More file actions
42 lines (34 loc) · 1.1 KB
/
omp_bug4.c
File metadata and controls
42 lines (34 loc) · 1.1 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/******************************************************************************
* FILE: omp_bug4.c
* DESCRIPTION:
* This very simple program causes a segmentation fault.
* AUTHOR: Blaise Barney 01/09/04
* LAST REVISED: 04/06/05
******************************************************************************/
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#define N 1048
int main (int argc, char *argv[])
{
int nthreads, tid, i, j;
double a[N][N];
/* Fork a team of threads with explicit variable scoping */
#pragma omp parallel shared(nthreads) private(i,j,tid,a)
{
/* Obtain/print thread info */
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);
/* Each thread works on its own private copy of the array */
for (i=0; i<N; i++)
for (j=0; j<N; j++)
a[i][j] = tid + i + j;
/* For confirmation */
printf("Thread %d done. Last element= %f\n",tid,a[N-1][N-1]);
} /* All threads join master thread and disband */
}