How to force writing output files in real-time?

Hello all !

One simple question. I use communication files to check the status of freefem programs from Matlab. For this I want to write in such communication files in real-time. I can see that it is usually not the case ; I assume that freefem stores the output in some buffer and writes only when there is a sufficient ammount of things to be written. This leads to some delay, especially in nohup mode.

So is there a way to force the writing (and closing) of files before continuing the program ?

If you scope the variable definition, it will be written at the end of its lifetime.

Not quite sure if I understood the question well, but how about flush it ? E.g., I often do something like this when I want to check the progress before simulation ends:

// open file in append mode
ofstream file("filename.txt",append); 
...
for(...){
      ... some calculations ...
      file << ... << endl; // write in the file
      if(...) file.flush;  // e.g. flush every five time steps
}

Seems to be working well for me.

if

1 Like

Thanks ! flush seems to be the precise thing I need !
Cheers
D