Right now I am learning about parallel programming in C with openmp and now I have stumbled upon the following problem. I have a simple for loop which I want to parallelize. Using openmp, I thought the following code should do the job
unsigned long int teller_groot;
int boel = 0;
int k = 0;
int l = 1;
unsigned long int sum2;
int thread_id;
int nloops;
#pragma omp parallel private(thread_id, nloops)
{
sum2 = 0;
#pragma omp for
for (teller_groot=1000000; teller_groot<1000000000000; teller_groot++)
{
boel = 0;
for (int i = 0; i < 78498; i++)
{
if (floor(teller_groot / array[i]) == teller_groot / array[i])
{
boel = 1;
break;
}
}
if (boel == 0)
{
sum2 = sum2 + teller_groot;
}
if (sum2 >= 1000000000)
{
sum2 = sum2 - 1000000000;
}
if (k == 10000000)
{
printf("%d, ", l);
l++;
k = 0;
}
k++;
}
thread_id = omp_get_thread_num();
printf("Thread %d performed %d iterations of the loop.\n", thread_id, nloops);
}
The code
if (k == 10000000)
{
printf("%d, ",l);
l++;
k = 0;
}
k++;
is just for me to know how far in the loop we are. If I run the program, it doesn't print anything, meaning it does not calculate anything. What is wrong with the code then? Thanks.
printfperformed?