2004-01-21 03:05:46 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-10-15 23:31:47 +04:00
|
|
|
* $HEADER$
|
2004-01-21 03:05:46 +03:00
|
|
|
*/
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-21 03:05:46 +03:00
|
|
|
#include <stdio.h>
|
2004-08-08 23:20:19 +04:00
|
|
|
#include <string.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-08-08 23:20:19 +04:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-08-08 23:20:19 +04:00
|
|
|
#include <sys/types.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2004-08-08 23:20:19 +04:00
|
|
|
#include <sys/socket.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-08-08 23:20:19 +04:00
|
|
|
#include <errno.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2004-08-08 23:20:19 +04:00
|
|
|
#include <netinet/in.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-01-21 03:05:46 +03:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/mpi/c/bindings.h"
|
2005-09-12 13:17:44 +04:00
|
|
|
#include "orte/mca/ns/ns.h"
|
|
|
|
#include "ompi/proc/proc.h"
|
2004-01-21 03:05:46 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES
|
2004-01-21 03:05:46 +03:00
|
|
|
#pragma weak MPI_Comm_join = PMPI_Comm_join
|
|
|
|
#endif
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if OMPI_PROFILING_DEFINES
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/mpi/c/profile/defines.h"
|
2004-04-20 22:50:43 +04:00
|
|
|
#endif
|
|
|
|
|
2004-07-30 06:58:53 +04:00
|
|
|
static const char FUNC_NAME[] = "MPI_Comm_join";
|
2004-06-23 00:21:35 +04:00
|
|
|
|
2004-08-08 23:20:19 +04:00
|
|
|
static int ompi_socket_send (int fd, char *buf, int len );
|
|
|
|
static int ompi_socket_recv (int fd, char *buf, int len );
|
2004-06-23 00:21:35 +04:00
|
|
|
|
2004-06-16 05:41:01 +04:00
|
|
|
int MPI_Comm_join(int fd, MPI_Comm *intercomm)
|
|
|
|
{
|
2004-09-17 20:30:40 +04:00
|
|
|
int rc, tag=OMPI_COMM_JOIN_TAG;
|
2004-08-08 23:20:19 +04:00
|
|
|
size_t size;
|
2004-09-17 20:30:40 +04:00
|
|
|
uint32_t len, rlen, llen, lrlen;
|
|
|
|
int send_first=1;
|
2004-08-08 23:20:19 +04:00
|
|
|
char *rname, *name;
|
|
|
|
|
|
|
|
ompi_proc_t **myproc=NULL;
|
2004-08-05 20:32:13 +04:00
|
|
|
ompi_communicator_t *newcomp;
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_process_name_t *port_proc_name=NULL;
|
2004-06-17 01:35:31 +04:00
|
|
|
|
2004-06-16 05:41:01 +04:00
|
|
|
if ( MPI_PARAM_CHECK ) {
|
2004-06-23 00:21:35 +04:00
|
|
|
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
|
2004-06-18 23:02:52 +04:00
|
|
|
|
2004-07-30 06:58:53 +04:00
|
|
|
if ( NULL == intercomm ) {
|
2004-06-16 05:41:01 +04:00
|
|
|
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
|
2004-06-23 00:21:35 +04:00
|
|
|
FUNC_NAME);
|
2004-07-30 06:58:53 +04:00
|
|
|
}
|
2004-06-16 05:41:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sendrecv OOB-name (port-name) through the socket connection.
|
|
|
|
Need to determine somehow how to avoid a potential deadlock
|
2004-07-27 02:21:20 +04:00
|
|
|
here. */
|
2004-08-08 23:20:19 +04:00
|
|
|
myproc = ompi_proc_self (&size);
|
2005-03-14 23:57:21 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_ns.get_proc_name_string (&name, &(myproc[0]->proc_name)))) {
|
|
|
|
return rc;
|
|
|
|
}
|
2004-09-17 20:30:40 +04:00
|
|
|
llen = strlen(name)+1;
|
|
|
|
len = htonl(llen);
|
2004-08-08 23:20:19 +04:00
|
|
|
|
|
|
|
ompi_socket_send( fd, (char *) &len, sizeof(uint32_t));
|
|
|
|
ompi_socket_recv (fd, (char *) &rlen, sizeof(uint32_t));
|
|
|
|
|
2004-09-17 20:30:40 +04:00
|
|
|
lrlen = ntohl(rlen);
|
|
|
|
rname = (char *) malloc (lrlen);
|
2004-08-08 23:20:19 +04:00
|
|
|
if ( NULL == rname ) {
|
|
|
|
*intercomm = MPI_COMM_NULL;
|
|
|
|
return MPI_ERR_INTERN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assumption: socket_send should not block, even if the socket
|
|
|
|
is not configured to be non-blocking, because the message length are
|
|
|
|
so short. */
|
2004-09-17 20:30:40 +04:00
|
|
|
ompi_socket_send (fd, name, llen);
|
|
|
|
ompi_socket_recv (fd, rname, lrlen);
|
2004-08-08 23:20:19 +04:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_ns.convert_string_to_process_name(&port_proc_name, rname))) {
|
|
|
|
return rc;
|
|
|
|
}
|
2004-08-05 20:32:13 +04:00
|
|
|
rc = ompi_comm_connect_accept (MPI_COMM_SELF, 0, port_proc_name,
|
2004-09-17 14:12:31 +04:00
|
|
|
send_first, &newcomp, tag);
|
2004-06-16 05:41:01 +04:00
|
|
|
|
2004-08-08 23:20:19 +04:00
|
|
|
|
|
|
|
free ( name );
|
|
|
|
free ( rname);
|
2004-09-17 20:30:40 +04:00
|
|
|
free ( port_proc_name );
|
2004-08-08 23:20:19 +04:00
|
|
|
free ( myproc );
|
|
|
|
|
2004-06-17 01:35:31 +04:00
|
|
|
*intercomm = newcomp;
|
2004-08-05 20:32:13 +04:00
|
|
|
OMPI_ERRHANDLER_RETURN (rc, MPI_COMM_SELF, rc, FUNC_NAME);
|
2004-01-21 03:05:46 +03:00
|
|
|
}
|
2004-08-08 23:20:19 +04:00
|
|
|
|
|
|
|
|
|
|
|
static int ompi_socket_send (int fd, char *buf, int len )
|
|
|
|
{
|
2005-02-09 19:25:38 +03:00
|
|
|
int num;
|
2004-08-08 23:20:19 +04:00
|
|
|
size_t s_num;
|
|
|
|
ssize_t a;
|
|
|
|
char *c_ptr;
|
|
|
|
int ret = OMPI_SUCCESS;
|
|
|
|
|
2005-02-09 19:25:38 +03:00
|
|
|
num = (size_t) len;
|
2004-08-08 23:20:19 +04:00
|
|
|
c_ptr = buf;
|
|
|
|
|
|
|
|
do {
|
2005-02-09 19:25:38 +03:00
|
|
|
s_num = (size_t) num;
|
2004-08-08 23:20:19 +04:00
|
|
|
a = write ( fd, c_ptr, s_num );
|
|
|
|
if ( a == -1 ) {
|
|
|
|
if ( errno == EINTR ) {
|
|
|
|
/* Catch EINTR on, mainly on IBM RS6000 */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#ifdef __SR8000
|
|
|
|
else if ( errno == EWOULDBLOCK ) {
|
|
|
|
/*Catch EWOULDBLOCK on Hitachi SR8000 */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if ( errno == EAGAIN ) {
|
|
|
|
/* Catch EAGAIN on Hitachi SR8000 */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
/* Another error occured */
|
2006-03-16 12:42:46 +03:00
|
|
|
fprintf (stderr,"ompi_socket_send: error while writing to socket"
|
2004-08-08 23:20:19 +04:00
|
|
|
" error:%s", strerror (errno) );
|
2006-03-16 12:42:46 +03:00
|
|
|
return MPI_ERR_OTHER;
|
2004-08-08 23:20:19 +04:00
|
|
|
}
|
|
|
|
}
|
2005-02-09 19:25:38 +03:00
|
|
|
num -= a;
|
|
|
|
c_ptr += a;
|
|
|
|
} while ( num > 0 );
|
2004-08-08 23:20:19 +04:00
|
|
|
|
|
|
|
|
2005-02-09 19:25:38 +03:00
|
|
|
if ( num < 0 ) {
|
2006-03-16 12:42:46 +03:00
|
|
|
fprintf (stderr, "ompi_socket_send: more data written then available");
|
|
|
|
ret = MPI_ERR_INTERN;
|
2004-08-08 23:20:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ompi_socket_recv (int fd, char *buf, int len )
|
|
|
|
{
|
2005-02-09 19:25:38 +03:00
|
|
|
int num;
|
2004-08-08 23:20:19 +04:00
|
|
|
size_t s_num;
|
|
|
|
ssize_t a;
|
|
|
|
char *c_ptr;
|
2006-03-16 12:42:46 +03:00
|
|
|
int ret = MPI_SUCCESS;
|
2004-08-08 23:20:19 +04:00
|
|
|
|
2005-02-09 19:25:38 +03:00
|
|
|
num = len;
|
2004-08-08 23:20:19 +04:00
|
|
|
c_ptr = buf;
|
|
|
|
|
|
|
|
do {
|
2005-02-09 19:25:38 +03:00
|
|
|
s_num = (size_t ) num;
|
2004-08-08 23:20:19 +04:00
|
|
|
a = read ( fd, c_ptr, s_num );
|
|
|
|
if ( a == -1 ) {
|
|
|
|
if ( errno == EINTR ) {
|
|
|
|
/* Catch EINTR on, mainly on IBM RS6000 */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#ifdef __SR8000
|
|
|
|
else if ( errno == EWOULDBLOCK ) {
|
|
|
|
/*Catch EWOULDBLOCK on Hitachi SR8000 */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if ( errno == EAGAIN ) {
|
|
|
|
/* Catch EAGAIN on Hitachi SR8000 */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
/* Another error occured */
|
2006-03-16 12:42:46 +03:00
|
|
|
fprintf (stderr,"ompi_socket_recv: error while reading from socket"
|
2004-08-08 23:20:19 +04:00
|
|
|
" error:%s", strerror (errno) );
|
2006-03-16 12:42:46 +03:00
|
|
|
return MPI_ERR_OTHER;
|
2004-08-08 23:20:19 +04:00
|
|
|
}
|
|
|
|
}
|
2005-02-09 19:27:27 +03:00
|
|
|
num -= a;
|
|
|
|
c_ptr += a;
|
2005-02-09 19:25:38 +03:00
|
|
|
} while ( num > 0 );
|
2004-08-08 23:20:19 +04:00
|
|
|
|
2005-02-09 19:25:38 +03:00
|
|
|
if ( num < 0 ) {
|
2006-03-16 12:42:46 +03:00
|
|
|
fprintf (stderr, "ompi_socket_recv: more data read then available");
|
|
|
|
ret = MPI_ERR_INTERN;
|
2004-08-08 23:20:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|