|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mpiimpl.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* -- Begin Profiling Symbol Block for routine MPI_Comm_join */
|
|
Packit Service |
c5cf8c |
#if defined(HAVE_PRAGMA_WEAK)
|
|
Packit Service |
c5cf8c |
#pragma weak MPI_Comm_join = PMPI_Comm_join
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
|
|
Packit Service |
c5cf8c |
#pragma _HP_SECONDARY_DEF PMPI_Comm_join MPI_Comm_join
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_CRI_DUP)
|
|
Packit Service |
c5cf8c |
#pragma _CRI duplicate MPI_Comm_join as PMPI_Comm_join
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_WEAK_ATTRIBUTE)
|
|
Packit Service |
c5cf8c |
int MPI_Comm_join(int fd, MPI_Comm * intercomm) __attribute__ ((weak, alias("PMPI_Comm_join")));
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
/* -- End Profiling Symbol Block */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Prototypes for local functions */
|
|
Packit Service |
c5cf8c |
PMPI_LOCAL int MPIR_fd_send(int, void *, int);
|
|
Packit Service |
c5cf8c |
PMPI_LOCAL int MPIR_fd_recv(int, void *, int);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
|
|
Packit Service |
c5cf8c |
the MPI routines */
|
|
Packit Service |
c5cf8c |
#ifndef MPICH_MPI_FROM_PMPI
|
|
Packit Service |
c5cf8c |
#undef MPI_Comm_join
|
|
Packit Service |
c5cf8c |
#define MPI_Comm_join PMPI_Comm_join
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_ERRNO_H
|
|
Packit Service |
c5cf8c |
#include <errno.h> /* needed for read/write error codes */
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_WINDOWS_H
|
|
Packit Service |
c5cf8c |
#define SOCKET_EINTR WSAEINTR
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_SYS_SOCKET_H
|
|
Packit Service |
c5cf8c |
#include <sys/socket.h>
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
#define SOCKET_EINTR EINTR
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
PMPI_LOCAL int MPIR_fd_send(int fd, void *buffer, int length)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int result, num_bytes;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
while (length) {
|
|
Packit Service |
c5cf8c |
/* The expectation is that the length of a join message will fit
|
|
Packit Service |
c5cf8c |
* in an int. For Unixes that define send as returning ssize_t,
|
|
Packit Service |
c5cf8c |
* we can safely cast this to an int. */
|
|
Packit Service |
c5cf8c |
num_bytes = (int) send(fd, buffer, length, 0);
|
|
Packit Service |
c5cf8c |
/* --BEGIN ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
if (num_bytes == -1) {
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_WINDOWS_H
|
|
Packit Service |
c5cf8c |
result = WSAGetLastError();
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
result = errno;
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
if (result == SOCKET_EINTR)
|
|
Packit Service |
c5cf8c |
continue;
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
return result;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
length -= num_bytes;
|
|
Packit Service |
c5cf8c |
buffer = (char *) buffer + num_bytes;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
PMPI_LOCAL int MPIR_fd_recv(int fd, void *buffer, int length)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int result, num_bytes;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
while (length) {
|
|
Packit Service |
c5cf8c |
/* See discussion on send above for the cast to int. */
|
|
Packit Service |
c5cf8c |
num_bytes = (int) recv(fd, buffer, length, 0);
|
|
Packit Service |
c5cf8c |
/* --BEGIN ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
if (num_bytes == -1) {
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_WINDOWS_H
|
|
Packit Service |
c5cf8c |
result = WSAGetLastError();
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
result = errno;
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
if (result == SOCKET_EINTR)
|
|
Packit Service |
c5cf8c |
continue;
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
return result;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
length -= num_bytes;
|
|
Packit Service |
c5cf8c |
buffer = (char *) buffer + num_bytes;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef FUNCNAME
|
|
Packit Service |
c5cf8c |
#define FUNCNAME MPI_Comm_join
|
|
Packit Service |
c5cf8c |
#undef FCNAME
|
|
Packit Service |
c5cf8c |
#define FCNAME MPL_QUOTE(FUNCNAME)
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPI_Comm_join - Create a communicator by joining two processes connected by
|
|
Packit Service |
c5cf8c |
a socket.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameters:
|
|
Packit Service |
c5cf8c |
. fd - socket file descriptor
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Output Parameters:
|
|
Packit Service |
c5cf8c |
. intercomm - new intercommunicator (handle)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Notes:
|
|
Packit Service |
c5cf8c |
The socket must be quiescent before 'MPI_COMM_JOIN' is called and after
|
|
Packit Service |
c5cf8c |
'MPI_COMM_JOIN' returns. More specifically, on entry to 'MPI_COMM_JOIN', a
|
|
Packit Service |
c5cf8c |
read on the socket will not read any data that was written to the socket
|
|
Packit Service |
c5cf8c |
before the remote process called 'MPI_COMM_JOIN'.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N ThreadSafe
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N Fortran
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N Errors
|
|
Packit Service |
c5cf8c |
.N MPI_SUCCESS
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_ARG
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPI_Comm_join(int fd, MPI_Comm * intercomm)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int mpi_errno = MPI_SUCCESS, err;
|
|
Packit Service |
c5cf8c |
MPIR_Comm *intercomm_ptr;
|
|
Packit Service |
c5cf8c |
char *local_port, *remote_port;
|
|
Packit Service |
c5cf8c |
MPIR_CHKLMEM_DECL(2);
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_COMM_JOIN);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_INITIALIZED_ORDIE();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_COMM_JOIN);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* ... body of routine ... */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_CHKLMEM_MALLOC(local_port, char *, MPI_MAX_PORT_NAME, mpi_errno, "local port name",
|
|
Packit Service |
c5cf8c |
MPL_MEM_DYNAMIC);
|
|
Packit Service |
c5cf8c |
MPIR_CHKLMEM_MALLOC(remote_port, char *, MPI_MAX_PORT_NAME, mpi_errno, "remote port name",
|
|
Packit Service |
c5cf8c |
MPL_MEM_DYNAMIC);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPL_VG_MEM_INIT(local_port, MPI_MAX_PORT_NAME * sizeof(char));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Open_port_impl(NULL, local_port);
|
|
Packit Service |
c5cf8c |
MPIR_ERR_CHKANDJUMP((mpi_errno != MPI_SUCCESS), mpi_errno, MPI_ERR_OTHER, "**openportfailed");
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
err = MPIR_fd_send(fd, local_port, MPI_MAX_PORT_NAME);
|
|
Packit Service |
c5cf8c |
MPIR_ERR_CHKANDJUMP1((err != 0), mpi_errno, MPI_ERR_INTERN, "**join_send", "**join_send %d",
|
|
Packit Service |
c5cf8c |
err);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
err = MPIR_fd_recv(fd, remote_port, MPI_MAX_PORT_NAME);
|
|
Packit Service |
c5cf8c |
MPIR_ERR_CHKANDJUMP1((err != 0), mpi_errno, MPI_ERR_INTERN, "**join_recv", "**join_recv %d",
|
|
Packit Service |
c5cf8c |
err);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_ERR_CHKANDJUMP2((strcmp(local_port, remote_port) == 0), mpi_errno, MPI_ERR_INTERN,
|
|
Packit Service |
c5cf8c |
"**join_portname", "**join_portname %s %s", local_port, remote_port);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (strcmp(local_port, remote_port) < 0) {
|
|
Packit Service |
c5cf8c |
MPIR_Comm *comm_self_ptr;
|
|
Packit Service |
c5cf8c |
MPIR_Comm_get_ptr(MPI_COMM_SELF, comm_self_ptr);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Comm_accept_impl(local_port, NULL, 0, comm_self_ptr, &intercomm_ptr);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
MPIR_Comm *comm_self_ptr;
|
|
Packit Service |
c5cf8c |
MPIR_Comm_get_ptr(MPI_COMM_SELF, comm_self_ptr);
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Comm_connect_impl(remote_port, NULL, 0, comm_self_ptr, &intercomm_ptr);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Close_port_impl(local_port);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
MPIR_ERR_POP(mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_OBJ_PUBLISH_HANDLE(*intercomm, intercomm_ptr->handle);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* ... end of body of routine ... */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
fn_exit:
|
|
Packit Service |
c5cf8c |
MPIR_CHKLMEM_FREEALL();
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_COMM_JOIN);
|
|
Packit Service |
c5cf8c |
MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
|
|
Packit Service |
c5cf8c |
return mpi_errno;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
fn_fail:
|
|
Packit Service |
c5cf8c |
/* --BEGIN ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_ERROR_CHECKING
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
mpi_errno =
|
|
Packit Service |
c5cf8c |
MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER,
|
|
Packit Service |
c5cf8c |
"**mpi_comm_join", "**mpi_comm_join %d %p", fd, intercomm);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Err_return_comm(NULL, FCNAME, mpi_errno);
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
}
|