25 lines
513 B
C
25 lines
513 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
|
|
{
|
|
i = 5;
|
|
while(i <= 10) {
|
|
printf("Iteration %d in thread: %d\n", i, omp_get_thread_num());
|
|
i++;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|