20 lines
509 B
C
20 lines
509 B
C
#include <omp.h> // load Open-MP library
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main() {
|
|
int N = 5;
|
|
int num;
|
|
|
|
#pragma omp parallel for private(num) // start Open-MP section
|
|
// here the program (1 thread) is split into multiple threads
|
|
// each thread has its own copy of i (loop) and num (private)
|
|
// all threads share N (by default, because defined outside)
|
|
for (int i = 0; i < N; i++) {
|
|
num = omp_get_thread_num();
|
|
printf("Thread %d does iteration %d\n", num, i);
|
|
}
|
|
|
|
return 0;
|
|
}
|