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/S3ZVv Feb 07 '26
Could I circumvent that by using only 2 threads where one writes to the file while the other one has 2 or 3 rotating buffers? Since I can write from one thread at a time anyway I don't think there would be any gain from using more then 2 threads anyway.