#include #include #include double fibonacci(double x) { if (x <= 1) return(1); return(fibonacci(x-1) + fibonacci(x-2)); } double factorial(double x) { if ((int)x == 0) return(1); return(x * factorial(x-1)); } void main(int argc, char **argv ) { double x=40; double a1,a2,s1,s2,e1,e2; #pragma omp parallel sections { #pragma omp section { s1 = omp_get_wtime(); a1 = fibonacci(x); e1 = omp_get_wtime(); printf("thread:%d Fibonacci of %0.f = %0.f in %0.5f\n",omp_get_thread_num(),x,a1,e1-s1); } #pragma omp section { s2 = omp_get_wtime(); a2 = factorial(x); e2 = omp_get_wtime(); printf("thread:%d Factorial of %0.f = %0.f in %0.5f\n",omp_get_thread_num(),x,a2,e2-s2); } } }