Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.
2226 Discussions

MPI_Finalize() won't finalize if stdout and stderr are redirected via freopen

Fanny_D_
Beginner
1,160 Views

Hi,

I have a problem using Intel MPI (5.1 Update 3) and redirection of stdout and stderr.

When launched with multiple processes, if both stdout and stderr are redirected in (two different) files, then every processes will get stucked in MPI_Finalize(), waiting indefinitely. But if only stdout or stderr is redirected, then there is no problem and the program stops normaly.

I'm working on windows 7 with intel MPI (5.1 Update 3) on Visual Studio 2013.

I have the same issue when compiling with Intel C++ compiler (16.0.0.20150815).

Thanks for your help!

Below is a simple code that fails on my computer with 2 processes (mpiexec -np 2 mpitest.exe)

#include <iostream>
#include <string>
#include <mpi.h>
int main(int argc, char *argv[])
{
    int ierr = MPI_Init(&argc, &argv);  
    int rank, size;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);    

    printf("[%d/%d] This is printed on screen\n", rank, size-1);

    // redirect the outputs and errors if necessary
    std::string log_file = "log_" + std::to_string(rank) + ".txt";
    std::string error_file = "err_" + std::to_string(rank) + ".txt";
    //If one of the two following line is commented, then everything works fine
    freopen(log_file.c_str(), "w", stdout);
    freopen(error_file.c_str(), "w", stderr);

    printf("[%d/%d] This is printed on the logfile\n", rank, size - 1);    

    ierr = MPI_Finalize();
    return 0;
}
0 Kudos
3 Replies
Michael_Intel
Moderator
1,160 Views

Hello,

I can reproduce the issue on my Linux machine. Will update you soon.

Best regards,

Michael

 

0 Kudos
Michael_Intel
Moderator
1,160 Views

Hello,

The issue exists on both Linux and Windows and has been escalated to the engineering teams. The problem is related to the way how the output streams are propagated through all the ranks and proxies towards rank 0.

Therefore I will let you know when there is an update on the issue.

In the meantime, please redirect the output externally before the application starts.

Best regards,

Michael

0 Kudos
Michael_Intel
Moderator
1,160 Views

Hello,

Brief update - the product fix is going into the upcoming IMPI 2017.0.1 version.

Best regards,

Michael

0 Kudos
Reply