Skip to content

Instantly share code, notes, and snippets.

@skymansandy
Created November 3, 2016 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skymansandy/10eaaf4fd39bcdb81d78d059fe8e4c3d to your computer and use it in GitHub Desktop.
Save skymansandy/10eaaf4fd39bcdb81d78d059fe8e4c3d to your computer and use it in GitHub Desktop.
#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