Created
November 3, 2016 17:23
-
-
Save skymansandy/10eaaf4fd39bcdb81d78d059fe8e4c3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<omp.h> | |
int fibonacci(int n) | |
{ | |
if(n<2) | |
return n; | |
else | |
return fibonacci(n-1)+fibonacci(n-2); | |
} | |
int main() | |
{ | |
int fibnumber[100],i,j,n; | |
printf("Please Enter the series limit\n"); | |
scanf("%d",&n); | |
#pragma omp parallel num_threads(2) | |
{ | |
#pragma omp critical | |
if(omp_get_thread_num()==0) | |
{ | |
printf("There are %d threads\n", omp_get_num_threads()); | |
printf("Thread %d generating numbers..\n", omp_get_thread_num()); | |
for(i=0;i<n;i++) | |
fibnumber[i]=fibonacci(i); | |
} | |
else | |
{ | |
printf("Thread %d Printing numbers..\n", omp_get_thread_num()); | |
for(j=0;j<n;j++) | |
printf("%d\t", fibnumber[j]); | |
} | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment