r/C_Programming • • 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?

0 Upvotes

16 comments sorted by

View all comments

Show parent comment

4

u/RealisticDuck1957 Sep 15 '26

I don't understand what the #pragma is supposed to do. But the loop being optimized away under one option is exactly what I was thinking.

1

u/FlippingGerman Sep 15 '26

It’s a compiler directive, using the OpenMP library to parallelise the for loop, adding together successive values of count (I think, I haven’t used it in a bit, and little then).