Search code examples
cparallel-processingiohpc

Is continually writing to a file detrimental to the performance of a program?


Imagine a parallel "high performance program" that reads in files, each process performs a task on the input data and then each process writes an output for the task to a single shared output file before repeating this procedure.

In terms of performance, is it inefficient to write the outputs to a file as each process finishes a task?

Would it be more efficient to store the results in an array and write the array to an output file at the end?


Solution

  • This is problem where full IO disk read write has to be exploited without delays from client processes or threads. If Std C library calls are used it uses memory buffer that gets flushed at newline or fflush() call is made. If the data is not big enough using array is efficient that can be written to file at the end so performance demanding task will not suffer IO delays.