/* compile with -fopenmp */
#include <stdio.h>
static void
sum(long i, long j, long *out) {
if (i>j)
return;
if (i==j) {
(*out)++;
} else {
long m=(i+j)/2;
#pragma omp task
sum(i,m,out);
sum(m+1,j, out);
#pragma omp taskwait
}
}
int main(int argc, char** argv){
long x = 0;
#pragma omp parallel
{
sum(1,10000, &x);
}
printf("x = %ld\n", x);
}