-
Notifications
You must be signed in to change notification settings - Fork 935
Closed
Description
Thank you for taking the time to submit an issue!
Background information
What version of Open MPI are you using? (e.g., v4.1.6, v5.0.1, git branch name and hash, etc.)
v5.0.2
Describe how Open MPI was installed (e.g., from a source/distribution tarball, from a git clone, from an operating system distribution package, etc.)
Installed using DNF on Fedora 40 (KDE Spin)
If you are building/installing from a git clone, please copy-n-paste the output from git submodule status.
N/A
Please describe the system on which you are running
- Operating system/version: Fedora 40 (KDE Spin)
- Computer hardware: Framework 13
- Network type: N/A
Details of the problem
It appears to me that fflush(stdout) has no effect, where previously it would cause the stdout buffer to flush as one might expect.
#include <mpi.h>
#include <stdio.h>
void main(int argc, char** argv)
{
int num_procs, rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
printf("N = ");
fflush(stdout); // this should flush "N = " to the screen, prompting the user to input
int n;
scanf("%d", &n);
printf("bye\n");
}
MPI_Finalize();
}
Will hang with no output, instead of printing "N = " before running scanf at the root (rank 0 process).
On the other hand if I include a print containing a newline character, the stdout buffer is automatically flushed without issue.
#include <mpi.h>
#include <stdio.h>
void main(int argc, char** argv)
{
int num_procs, rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
printf("N = ");
printf("\n"); // this DOES flush the "N = ", but so SHOULD fflush(stdout); !
int n;
scanf("%d", &n);
printf("bye\n");
}
MPI_Finalize();
}
Programs were executed using mpirun -np 8 <binary_path>.
A zip file containing an equivalent project to these markdown blocks can be found here.
- PS: It seems to me (based on delays from printing) that
fflush(stdout)is completely broken (i.e. all the output is just flushed atMPI_Finalize, and an earlierfflush(stdout)has no actual effect), and I expect this is to do with output redirection done internally inmpirun, running our binaries withoutmpirundoesn't have this issue. But writing code that clearly verifies this is harder, and this is just what I have right now.
cherryblossom000