2

I have a problem using MPI 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 on visual studio 2013.

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;
}

EDIT : For those who are interested, we submit this error to the INTEL developper forum. They were able to reproduce the bug and are working to fix it. In the meantime, we redirect every stderr message on the stdout (ugly but working).

bertbk
  • 105
  • 7
  • I cannot reproduce your issue with Intel MPI 4.1 / 5.1 in combination with Intel compilers. Intel MPI / MPICH supports options `-outfile-pattern -errfile-pattern` that do what you want. – Zulan Mar 25 '16 at 16:16
  • Thanks for your reply. Do you mean by using these two options with mpiexec ? If yes, then I cannot use these options because the name of the outfile and errfile are automatically choosen by the program and are thus unknown before the execution... – bertbk Mar 28 '16 at 08:56

0 Answers0