I have written a multi threading program in c using openmp. The program has around 400 parallelized functions calls. These functions have some printf functions to print some debug informations. I have observed that by removing these printf functions the run time of program increases from 1.2 secs to 1.6 secs. I am observing these phenomena consistently. How can this be possible?
Share
Do the parallel function calls depend on each other in any way? Since you are not likely running this across 400 cores, there will be some overhead in the context switches as various threads get scheduled. It is possible that the printf results in yielding the CPU (while it writes to stdout), and by chance that it is a good place to yield the CPU (i.e. it is not at that point blocking any other thread).
I work on a multi-process application, that occasionally does synchronous writes to disk. One thing I’ve seen is that getting rid of all the synchronous writes increases the speed of that process, but at the cost of the overall system not running as smoothly. Instead we just ensure to avoid writing whilst holding any semaphore locks.
If processes are always pausing waiting for a synchronous write to finish, and if it isn’t blocking anything else, everything gets a chance to run with very low latency, and the overall system is quite a bit faster.