Quantcast
Channel: Clusters and HPC Technology
Viewing all articles
Browse latest Browse all 927

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

$
0
0

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

Viewing all articles
Browse latest Browse all 927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>