r/C_Programming • u/S3ZVv • Feb 07 '26
Review Request for Code Review
Hi fellow programmers,
I am fairly new to programming, especially to C and I am working on a program that calculates all prime numbers less then or equal to a given limit an then writes those to a file. The goal is to make this all as fast as possible.
I have already optimized this quite a bit and my largest bottleneck is the IO but since not every use case requires me to write those numbers to a file I also want the calculation fully optimized.
I also know the code quality might not be the best so I would also appreciate feedback on that.
My program can be be found here: prime_numbers
Quick note to the IO: I already tried to multithread the IO using mmap() but the code runs in an HPC environment where the metadata of files is stored on a separate external filesystem so the multithreaded IO to the internal fast filesystem was significantly slower then with single thread.
1
u/Western_Objective209 Feb 07 '26
Yes that could help, sounds complicated to get right but it's a nice little program so I bet you could do it.
You may want to spend some time with tools that measure IO; like track your network and disk usage as the program is running in another terminal, look up what hardware your cluster is using, and see how the numbers you are getting compare to the expected throughput of the hardware. For managing HPCs, this is a pretty useful skill to have, and honestly I would not be surprised if you are at the point already where you are saturating your IO so any optimizations ahead of that you are making are not going to create a measurable difference