If I launch a background process that uses MPI as follows:
system("start \"\" cmd /k \"cd <path> && mpiexec -n 1 <exe> &\"");
it works fine, but the entire output is shown in the command prompt at the end of the program. I would like to see the output immediately as it is being printed. How do I do that? Note that if I don't use mpiexec
in the command, I correctly get the output as soon as it happens.
Sample:
#include <iostream>
#include <windows.h>
#include <mpi.h>
#include <cstdio>
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
printf("test A\n");
Sleep(2000);
printf("test B\n");
Sleep(2000);
printf("test C\n");
Sleep(2000);
MPI_Finalize();
return 0;
}
Edit: Using fflush(stdout)
to flush the output after every print statement fixes the issue (as mentioned in the comments). However I would like to know if there is any other way to fix this, since this would require changing thousands of print statements in the code.