I made a program which calculates the fibonacci sequence. I executed it with different numbers of threads (eg. 1, 2, 10) but the execution time remained almost the same (about 0.500 seconds).
I'm using CodeBlocks on Ubuntu and the GNU GCC compiler. In CodeBlocks I linked the library gomp and defined the flag -fopenmp for the compiler.
#include <omp.h> #include <stdio.h> #include <stdlib.h> int main() { int i, n=1000, a[n]; omp_set_num_threads(4); for(i=0; i<n; i++) { a[i] = 1 + (rand() % ( 50 - 1 + 1 ) ); } fibo(n, a); return 0; } void fibo(int sizeN, int n[]) { int i; #pragma omp parallel for for(i=0; i<sizeN; i++) { int a = 0, b = 1, next, c; printf("n = %i\n", n[i]); for (c=0; c<=n[i]; c++) { if (c <= 1) { next = c; } else { next = a + b; a = b; b = next; } printf("%d\n",next); } } } Does anybody have an idea?
How can I make sure that OpenMP really works (is installed)?
( 50 - 1 + 1 )is50every day :)