-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path2a.c
28 lines (28 loc) · 765 Bytes
/
2a.c
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
#include <stdio.h>
#include <omp.h>
int main()
{
int n, a[100], i;
omp_set_num_threads(2);
printf("Enter the no of terms uptill which you want to generate the Fibonnaci Series\n");
scanf("%d", &n);
a[0] = 0;
a[1] = 1;
#pragma omp parallel
{
#pragma omp single
for (i = 2; i < n; i++)
{
a[i] = a[i - 2] + a[i - 1];
printf("Id of thread involved in the computation of fib number %d is=%d\n", i + 1, omp_get_thread_num());
}
#pragma omp barrier
#pragma omp single
{
printf("The series is:\n");
for (i = 0; i < n; i++)
printf("%d \t Id of the thread displaying this number is = %d\n", a[i], omp_get_thread_num());
}
}
return 0;
}