int MPID_nem_tcp_connect_to_root (const char *business_card, MPIDI_VC_t *new_vc) { int mpi_errno = MPI_SUCCESS; struct in_addr addr; MPID_nem_tcp_vc_area *vc_tcp = VC_TCP(new_vc); MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_TCP_CONNECT_TO_ROOT); MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_TCP_CONNECT_TO_ROOT); /* vc is already allocated before reaching this point */ mpi_errno = MPID_nem_tcp_get_addr_port_from_bc(business_card, &addr, &vc_tcp->sock_id.sin_port); vc_tcp->sock_id.sin_addr.s_addr = addr.s_addr; if (mpi_errno) MPIR_ERR_POP(mpi_errno); mpi_errno = MPIDI_GetTagFromPort(business_card, &new_vc->port_name_tag); if (mpi_errno) MPIR_ERR_POP(mpi_errno); mpi_errno = MPID_nem_tcp_connect(new_vc); if (mpi_errno) MPIR_ERR_POP(mpi_errno); fn_exit: MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_TCP_CONNECT_TO_ROOT); return mpi_errno; fn_fail: goto fn_exit; }
static int MPIDI_Close_port(const char *port_name) { int mpi_errno = MPI_SUCCESS; int port_name_tag; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CLOSE_PORT); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CLOSE_PORT); mpi_errno = MPIDI_GetTagFromPort(port_name, &port_name_tag); MPIR_ERR_CHKANDJUMP(mpi_errno, mpi_errno, MPI_ERR_OTHER,"**argstr_port_name_tag"); free_port_name_tag(port_name_tag); fn_exit: MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CLOSE_PORT); return mpi_errno; fn_fail: goto fn_exit; }
static int MPIDI_Create_inter_root_communicator_connect(const char *port_name, MPID_Comm **comm_pptr, MPIDI_VC_t **vc_pptr) { int mpi_errno = MPI_SUCCESS; MPID_Comm *tmp_comm; MPIDI_VC_t *connect_vc = NULL; int port_name_tag; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CREATE_INTER_ROOT_COMMUNICATOR_CONNECT); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CREATE_INTER_ROOT_COMMUNICATOR_CONNECT); /* Connect to the root on the other side. Create a temporary intercommunicator between the two roots so that we can use MPI functions to communicate data between them. */ mpi_errno = MPIDI_CH3_Connect_to_root(port_name, &connect_vc); if (mpi_errno != MPI_SUCCESS) { MPIU_ERR_POP(mpi_errno); } /* extract the tag from the port_name */ mpi_errno = MPIDI_GetTagFromPort( port_name, &port_name_tag); if (mpi_errno != MPIU_STR_SUCCESS) { MPIU_ERR_POP(mpi_errno); } mpi_errno = MPIDI_CH3I_Initialize_tmp_comm(&tmp_comm, connect_vc, 1, port_name_tag); if (mpi_errno != MPI_SUCCESS) { MPIU_ERR_POP(mpi_errno); } *comm_pptr = tmp_comm; *vc_pptr = connect_vc; fn_exit: MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CREATE_INTER_ROOT_COMMUNICATOR_CONNECT); return mpi_errno; fn_fail: goto fn_exit; }
static int MPIDI_Create_inter_root_communicator_accept(const char *port_name, MPID_Comm **comm_pptr, MPIDI_VC_t **vc_pptr) { int mpi_errno = MPI_SUCCESS; MPID_Comm *tmp_comm; MPIDI_VC_t *new_vc = NULL; MPID_Progress_state progress_state; int port_name_tag; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CREATE_INTER_ROOT_COMMUNICATOR_ACCEPT); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CREATE_INTER_ROOT_COMMUNICATOR_ACCEPT); /* extract the tag from the port_name */ mpi_errno = MPIDI_GetTagFromPort( port_name, &port_name_tag); if (mpi_errno != MPIU_STR_SUCCESS) { MPIU_ERR_POP(mpi_errno); } /* FIXME: Describe the algorithm used here, and what routine is user on the other side of this connection */ /* dequeue the accept queue to see if a connection with the root on the connect side has been formed in the progress engine (the connection is returned in the form of a vc). If not, poke the progress engine. */ MPID_Progress_start(&progress_state); for(;;) { MPIDI_CH3I_Acceptq_dequeue(&new_vc, port_name_tag); if (new_vc != NULL) { break; } mpi_errno = MPID_Progress_wait(&progress_state); /* --BEGIN ERROR HANDLING-- */ if (mpi_errno) { MPID_Progress_end(&progress_state); MPIU_ERR_POP(mpi_errno); } /* --END ERROR HANDLING-- */ } MPID_Progress_end(&progress_state); mpi_errno = MPIDI_CH3I_Initialize_tmp_comm(&tmp_comm, new_vc, 0, port_name_tag); if (mpi_errno != MPI_SUCCESS) { MPIU_ERR_POP(mpi_errno); } *comm_pptr = tmp_comm; *vc_pptr = new_vc; MPIU_DBG_MSG_FMT(CH3_CONNECT,VERBOSE,(MPIU_DBG_FDEST, "new_vc=%p", new_vc)); fn_exit: MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CREATE_INTER_ROOT_COMMUNICATOR_ACCEPT); return mpi_errno; fn_fail: goto fn_exit; }
int MPIDI_CH3_Connect_to_root(const char* port_name, MPIDI_VC_t** new_vc) { int mpi_errno = MPI_SUCCESS; int str_errno; char ifname[MAX_HOST_DESCRIPTION_LEN]; MPIDI_VC_t *vc; MPIDI_CH3_Pkt_cm_establish_t pkt; MPID_Request * sreq; int seqnum; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3_CONNECT_TO_ROOT); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3_CONNECT_TO_ROOT); *new_vc = NULL; if (!MPIDI_CH3I_Process.has_dpm) return MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**notimpl", 0); str_errno = MPIU_Str_get_string_arg(port_name, MPIDI_CH3I_HOST_DESCRIPTION_KEY, ifname, MAX_HOST_DESCRIPTION_LEN); if (str_errno != MPIU_STR_SUCCESS) { /* --BEGIN ERROR HANDLING */ if (str_errno == MPIU_STR_FAIL) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**argstr_missinghost"); } else { /* MPIU_STR_TRUNCATED or MPIU_STR_NONEM */ MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**argstr_hostd"); } /* --END ERROR HANDLING-- */ } vc = MPIU_Malloc(sizeof(MPIDI_VC_t)); if (!vc) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**nomem"); } MPIDI_VC_Init(vc, NULL, 0); mpi_errno = MPIDI_CH3I_CM_Connect_raw_vc(vc, ifname); if (mpi_errno) { MPIU_ERR_POP(mpi_errno); } while (vc->ch.state != MPIDI_CH3I_VC_STATE_IDLE) { mpi_errno = MPID_Progress_test(); /* --BEGIN ERROR HANDLING-- */ if (mpi_errno != MPI_SUCCESS) { MPIU_ERR_POP(mpi_errno); } } /* fprintf(stderr, "[###] vc state to idel, now send cm_establish msg\n") */ /* Now a connection is created, send a cm_establish message */ /* FIXME: vc->mrail.remote_vc_addr is used to find remote vc * A more elegant way is needed */ MPIDI_Pkt_init(&pkt, MPIDI_CH3_PKT_CM_ESTABLISH); MPIDI_VC_FAI_send_seqnum(vc, seqnum); MPIDI_Pkt_set_seqnum(&pkt, seqnum); pkt.vc_addr = vc->mrail.remote_vc_addr; mpi_errno = MPIDI_GetTagFromPort(port_name, &pkt.port_name_tag); if (mpi_errno != MPIU_STR_SUCCESS) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**argstr_port_name_tag"); } mpi_errno = MPIDI_CH3_iStartMsg(vc, &pkt, sizeof(pkt), &sreq); if (mpi_errno != MPI_SUCCESS) { MPIU_ERR_SETANDJUMP1(mpi_errno,MPI_ERR_OTHER,"**fail", "**fail %s", "Failed to send cm establish message"); } if (sreq != NULL) { if (sreq->status.MPI_ERROR != MPI_SUCCESS) { mpi_errno = MPIR_Err_create_code(sreq->status.MPI_ERROR, MPIR_ERR_FATAL, FCNAME, __LINE__, MPI_ERR_OTHER, "**fail", 0); MPID_Request_release(sreq); goto fn_fail; } MPID_Request_release(sreq); } *new_vc = vc; fn_fail: MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3_CONNECT_TO_ROOT); return mpi_errno; }