Jan Bierbaum wrote:
Hi Marvin!

  
Essentially, until you call MPI_Init_thread, the Linux socket command
will return 0 for all ranks except rank 0.  This seems to me like a
problem.
    
Indeed. 'socket' should not return 0. Quoting from its manpage:

| On success, a file descriptor for the new socket is returned. On
| error, -1 is returned, and errno is set appropriately.

FD 0 is already taken by STDIN, so you should never get that return
value unless you close STDIN first.

  

The above statement is not necessarily true. I have worked on systems, namely Crays, where stdin, stdout, and stderr were all closed when the program starts, so calling socket() three times in a row would return 0, 1 and 2. MRNet (which we use in our product) contains the following code that is executed during startup:

    // Make sure any data sockets we create have descriptors != {1,2}
    // to avoid nasty bugs where fprintf(stdout/stderr) writes to data sockets.
    int fd;
    while( (fd = socket( AF_INET, SOCK_STREAM, 0 )) <= 2 ) {
        /* Code for closing descriptor on exec*/
        int fdflag = fcntl(fd, F_GETFD );
        if( fdflag == -1 )
        {
            // failed to retrive the fd  flags
            fprintf(stderr, "F_GETFD failed!\n");
        }
        int fret = fcntl( fd, F_SETFD, fdflag | FD_CLOEXEC );
        if( fret == -1 )
        {
            // we failed to set the fd flags
            fprintf(stderr, "F_SETFD failed!\n");
        }

        if( fd == -1 ) break;
    }
    if( fd > 2 ) XPlat::SocketUtils::Close(fd);

Of course the irony above is that if it hits an error, it prints to stderr :-)

Cheers, John D.
  
Given the following code sample...
    
[...]
  
*The application returns output this with mpirun.
    
Works for me:

| $ mpirun  -np 2 ./test-socket
| Pre Socket: 10
| MPI_Init
| Pre Socket: 6
| MPI_Init
| Post Socket: 14
| Post Socket: 15
|
| $ mpirun  -np 3 ./test-socket
| Pre Socket: 10
| MPI_Init
| Pre Socket: 6
| MPI_Init
| Pre Socket: 6
| MPI_Init
| Post Socket: 14
| Post Socket: 15
| Post Socket: 10


  
I am running this code sample using Red-Hat Enterprise Linux 7.1 with
mpich
    
[...]
  
    Version:                                 3.0.4
    
For me it's MPICH 3.1.4 on Debian 8 and I get similar results with MPICH
3.1rc on a local cluster. Taking into account the weird return value you
get from 'socket' ... maybe your system is the problem.


Regards, Jan
_______________________________________________
discuss mailing list     discuss@mpich.org
To manage subscription options or unsubscribe:
https://lists.mpich.org/mailman/listinfo/discuss