icp/oer/courses/c-openmp/sections/01-introduction/05-private/solution.c

25 lines
524 B
C

#include <stdio.h>
#include <unistd.h>
#include <omp.h>
int main(int argc, const char *argv[])
{
// We use two threads for this exercise
omp_set_num_threads(2);
// The variable is declared outside the parallel section
int i;
// The variable needs to be private to get the full output
#pragma omp parallel private(i)
{
i = 5;
while(i <= 10) {
printf("Iteration %d in thread: %d\n", i, omp_get_thread_num());
i++;
}
}
return 0;
}