2004-01-21 03:05:46 +03:00
|
|
|
/*
|
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
|
|
|
|
|
|
|
#include "mpi.h"
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "mpi/c/bindings.h"
|
2004-06-16 05:41:01 +04:00
|
|
|
#include "communicator/communicator.h"
|
2004-08-08 23:20:19 +04:00
|
|
|
#include "mca/ns/base/base.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
|
2004-04-20 22:50:43 +04:00
|
|
|
#include "mpi/c/profile/defines.h"
|
|
|
|
#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;
|
2004-09-17 20:30:40 +04:00
|
|
|
ompi_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);
|
|
|
|
name = ompi_name_server.get_proc_name_string (&(myproc[0]->proc_name));
|
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
|
|
|
|
2004-09-17 20:30:40 +04:00
|
|
|
port_proc_name = ompi_name_server.convert_string_to_process_name(rname);
|
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 )
|
|
|
|
{
|
|
|
|
size_t s_num;
|
|
|
|
ssize_t a;
|
|
|
|
char *c_ptr;
|
|
|
|
int ret = OMPI_SUCCESS;
|
|
|
|
|
|
|
|
s_num = (size_t) len;
|
|
|
|
c_ptr = buf;
|
|
|
|
|
|
|
|
do {
|
|
|
|
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 */
|
|
|
|
fprintf (stderr,"read_socket: error while reading from socket"
|
|
|
|
" error:%s", strerror (errno) );
|
|
|
|
return ( OMPI_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s_num -= (size_t) a;
|
|
|
|
c_ptr += a;
|
|
|
|
} while ( s_num > 0 );
|
|
|
|
|
|
|
|
|
|
|
|
if ( s_num < 0 ) {
|
|
|
|
fprintf (stderr, "read_socket: more data read then available");
|
|
|
|
ret = OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ompi_socket_recv (int fd, char *buf, int len )
|
|
|
|
{
|
|
|
|
size_t s_num;
|
|
|
|
ssize_t a;
|
|
|
|
char *c_ptr;
|
|
|
|
int ret = OMPI_SUCCESS;
|
|
|
|
|
|
|
|
s_num = (size_t) len;
|
|
|
|
c_ptr = buf;
|
|
|
|
|
|
|
|
do {
|
|
|
|
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 */
|
|
|
|
fprintf (stderr,"read_socket: error while reading from socket"
|
|
|
|
" error:%s", strerror (errno) );
|
|
|
|
return ( OMPI_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s_num -= (size_t) a;
|
|
|
|
c_ptr += a;
|
|
|
|
} while ( s_num > 0 );
|
|
|
|
|
|
|
|
|
|
|
|
if ( s_num < 0 ) {
|
|
|
|
fprintf (stderr, "read_socket: more data read then available");
|
|
|
|
ret = OMPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|