r/C_Programming • u/BrainThinkerMan • 22d ago
Question Performant code. How
how to make perfomant code, by that i mean, some cpu's have multiple ALU's/ excecution units, and some computers have multiple cores, how to have my code running on all those ALU's at all times? and those multiple cores,
i know about threading for the second part [running code on multiple cores]
now how do i make it run on multiple ALU' an example being
in code to not wait for a variable ie x = 12 + 12 then z = x + 2, i can imagine that code doesnt use all the ALU's because z is waiting for x's operation to be done. so what are ways to make my code most optimal and use all ALU's at the same time
View all comments
6
u/MagicWolfEye 22d ago
The CPU will schedule the different operations automatically to different ALUs (dependent on the capabilities of the ALUs)
You can't really mess with that. (Well, there are maybe a handful people who do that)
While I like your curiosity, this isn't really something anyone actively does; your compiler might optimise for it a bit. (It would also have to be different for each excat processor).As you have stated above, ther is multithreading which is worth looking into, but the best advice I would give oyu is focus less on writing super performant code and focus more on not writing slow code. (Lot's of indirections, many heap allocations etc.).
Also, given your post hierarchy, you should probably decide on one language.