r/C_Programming • u/BugsOfBunnys • Sep 15 '26
Question OpenMP bug??
Hello, I know this is not exactly the place for this, but it is C code. I am writing a bit of C code to search a large space of numbers, but I noticed the loop never ran. I asked ChatGPT cause I thought I was going crazy, but found that this bottom example code does not run the loop.
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
int main() {
uint64_t count = 0;
#pragma omp parallel for schedule(dynamic) reduction(+ : count)
for (uint64_t n = 1; n < UINT64_MAX; ++n)
++count;
printf("%llu\n", (unsigned long long)count);
}
It noticed it breaks with the dynamic scheduler. If you use the default static it seems to work. Any ideas on what is happening?
View all comments
Show parent comment
1
u/BugsOfBunnys Sep 16 '26
I believe it is the case that the compiler does optimize the loop out. I am working with other code for a compute server, got lazy and decided to search the whole space and exit when I find a value. The thing is, when you change the max range to something smaller, let us say 350, you get an output computed by the loop. It seems that with such a large value, the loop is removed completely.