21 lines
451 B
C
21 lines
451 B
C
|
#include <stdio.h>
|
||
|
#include <omp.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
int main(int argc, const char *argv[])
|
||
|
{
|
||
|
int sum = 0;
|
||
|
|
||
|
// The line below is just shorthand for a
|
||
|
// loop directive inside a parallel block
|
||
|
#pragma omp parallel for num_threads(2)
|
||
|
for (int i = 0; i < 10000; i++) {
|
||
|
// TODO: prevent this from causing race conditions
|
||
|
// use a critical section
|
||
|
sum++;
|
||
|
}
|
||
|
|
||
|
printf("sum: %d\n", sum);
|
||
|
return 0;
|
||
|
}
|