1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

#define PARALLEL_SIZE 4

int fibonacci(int n)
{
return n <= 2 ? 1 : fibonacci (n - 1) + fibonacci (n - 2);
}

int main()
{
#pragma omp parallel for
for (int i = 0; i < PARALLEL_SIZE; i++)
{
cout << fibonacci(50) << endl;
}
return 0;
}
1
2
3
4
5
6
7
build:
g++ -std=c++11 -c main.cpp -o main.o -fopenmp
g++ main.o -o main -fopenmp -lpthread

run:
export OMP_NUM_THREADS=4
./main