2004-06-17 01:34:42 +04: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.
|
2006-08-24 20:38:08 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2006-02-07 06:32:36 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
2004-11-28 23:09:25 +03:00
|
|
|
* 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.
|
2007-06-12 20:25:26 +04:00
|
|
|
* Copyright (c) 2007 Cisco, Inc. All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
2006-02-07 06:32:36 +03:00
|
|
|
*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Additional copyrights may follow
|
2006-02-07 06:32:36 +03:00
|
|
|
*
|
2004-06-17 01:34:42 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-09-13 00:25:01 +04:00
|
|
|
#include "ompi/communicator/communicator.h"
|
|
|
|
#include "ompi/proc/proc.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/constants.h"
|
2006-02-07 06:32:36 +03:00
|
|
|
#include "ompi/mca/pml/pml.h"
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
#include "orte/dss/dss.h"
|
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
|
|
|
#include "orte/mca/ns/ns.h"
|
|
|
|
#include "orte/mca/gpr/gpr.h"
|
|
|
|
#include "orte/mca/rml/rml_types.h"
|
2004-06-17 01:34:42 +04:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
static opal_mutex_t ompi_port_lock;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
#define OMPI_COMM_PORT_KEY "ompi-port-name"
|
|
|
|
|
2004-09-17 14:11:22 +04:00
|
|
|
|
|
|
|
int ompi_open_port(char *port_name)
|
2004-06-17 01:34:42 +04:00
|
|
|
{
|
2004-09-17 14:11:22 +04:00
|
|
|
ompi_proc_t **myproc=NULL;
|
|
|
|
char *name=NULL;
|
|
|
|
size_t size=0;
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_rml_tag_t lport_id=0;
|
|
|
|
int rc;
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2004-09-17 14:11:22 +04:00
|
|
|
/*
|
|
|
|
* The port_name is equal to the OOB-contact information
|
|
|
|
* and an integer. The reason for adding the integer is
|
|
|
|
* to make the port unique for multi-threaded scenarios.
|
|
|
|
*/
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2004-09-17 14:11:22 +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 14:11:22 +04:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_LOCK(&ompi_port_lock);
|
2005-03-14 23:57:21 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_ns.assign_rml_tag(&lport_id, NULL))) {
|
2006-02-07 06:32:36 +03:00
|
|
|
OPAL_THREAD_UNLOCK(&ompi_port_lock);
|
2005-03-14 23:57:21 +03:00
|
|
|
return rc;
|
|
|
|
}
|
2005-07-04 02:45:48 +04:00
|
|
|
OPAL_THREAD_UNLOCK(&ompi_port_lock);
|
2004-09-17 14:11:22 +04:00
|
|
|
|
|
|
|
sprintf (port_name, "%s:%d", name, lport_id);
|
|
|
|
free ( myproc );
|
|
|
|
free ( name );
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2004-06-17 01:34:42 +04:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
2004-09-17 14:11:22 +04:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
/* takes a port_name and separates it into the process_name
|
2004-09-17 14:11:22 +04:00
|
|
|
and the tag
|
|
|
|
*/
|
2006-02-07 06:32:36 +03:00
|
|
|
char *ompi_parse_port (char *port_name, orte_rml_tag_t *tag)
|
2004-06-17 01:34:42 +04:00
|
|
|
{
|
2004-09-17 14:11:22 +04:00
|
|
|
char tmp_port[MPI_MAX_PORT_NAME], *tmp_string;
|
|
|
|
|
|
|
|
tmp_string = (char *) malloc (MPI_MAX_PORT_NAME);
|
|
|
|
if (NULL == tmp_string ) {
|
2006-02-07 06:32:36 +03:00
|
|
|
return NULL;
|
2004-09-17 14:11:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
strncpy (tmp_port, port_name, MPI_MAX_PORT_NAME);
|
|
|
|
strncpy (tmp_string, strtok(tmp_port, ":"), MPI_MAX_PORT_NAME);
|
2005-03-14 23:57:21 +03:00
|
|
|
sscanf( strtok(NULL, ":"),"%d", (int*)tag);
|
2004-12-23 18:33:16 +03:00
|
|
|
|
2004-09-17 14:11:22 +04:00
|
|
|
return tmp_string;
|
2004-06-17 01:34:42 +04:00
|
|
|
}
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
/*
|
2004-06-17 01:34:42 +04:00
|
|
|
* publish the port_name using the service_name as a token
|
|
|
|
* jobid and vpid are used later to make
|
|
|
|
* sure, that only this process can unpublish the information.
|
|
|
|
*/
|
2006-02-07 06:32:36 +03:00
|
|
|
int ompi_comm_namepublish ( char *service_name, char *port_name )
|
2004-06-17 01:34:42 +04:00
|
|
|
{
|
2005-03-14 23:57:21 +03:00
|
|
|
orte_gpr_value_t *value;
|
|
|
|
int rc;
|
2004-09-17 14:11:22 +04:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_gpr.create_value(&value, ORTE_GPR_TOKENS_AND | ORTE_GPR_OVERWRITE,
|
|
|
|
OMPI_NAMESPACE_SEGMENT, 1, 1))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
value->tokens[0] = strdup(service_name);
|
2005-04-12 23:54:45 +04:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_gpr.create_keyval(&(value->keyvals[0]), OMPI_COMM_PORT_KEY, ORTE_STRING, port_name))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2005-03-14 23:57:21 +03:00
|
|
|
OBJ_RELEASE(value);
|
2006-02-07 06:32:36 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_gpr.put(1, &value))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
OBJ_RELEASE(value);
|
|
|
|
return rc;
|
2004-06-17 01:34:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
char* ompi_comm_namelookup ( char *service_name )
|
|
|
|
{
|
2005-03-14 23:57:21 +03:00
|
|
|
char *token[2], *key[2];
|
|
|
|
orte_gpr_keyval_t **keyvals=NULL;
|
|
|
|
orte_gpr_value_t **values;
|
2006-08-15 23:54:10 +04:00
|
|
|
orte_std_cntr_t cnt=0;
|
2005-03-14 23:57:21 +03:00
|
|
|
char *stmp=NULL;
|
|
|
|
int ret;
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
token[0] = service_name;
|
|
|
|
token[1] = NULL;
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
key[0] = strdup(OMPI_COMM_PORT_KEY);
|
2004-09-17 14:11:22 +04:00
|
|
|
key[1] = NULL;
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
ret = orte_gpr.get(ORTE_GPR_TOKENS_AND, OMPI_NAMESPACE_SEGMENT,
|
|
|
|
token, key, &cnt, &values);
|
|
|
|
if (ORTE_SUCCESS != ret) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if ( 0 < cnt && NULL != values[0] ) { /* should be only one, if any */
|
|
|
|
keyvals = values[0]->keyvals;
|
2006-08-24 20:38:08 +04:00
|
|
|
stmp = strdup((const char*)keyvals[0]->value->data);
|
2005-03-14 23:57:21 +03:00
|
|
|
OBJ_RELEASE(values[0]);
|
2004-06-17 01:34:42 +04:00
|
|
|
}
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
return (stmp);
|
2004-06-17 01:34:42 +04:00
|
|
|
}
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
/*
|
2004-06-17 01:34:42 +04:00
|
|
|
* delete the entry. Just the process who has published
|
2006-02-07 06:32:36 +03:00
|
|
|
* the service_name, has the right to remove this
|
2004-06-17 01:34:42 +04:00
|
|
|
* service. Will be done later, by adding jobid and vpid
|
|
|
|
* as tokens
|
|
|
|
*/
|
|
|
|
int ompi_comm_nameunpublish ( char *service_name )
|
|
|
|
{
|
2005-03-14 23:57:21 +03:00
|
|
|
char *token[2];
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
token[0] = service_name;
|
|
|
|
token[1] = NULL;
|
2006-02-07 06:32:36 +03:00
|
|
|
#if 0
|
2005-03-14 23:57:21 +03:00
|
|
|
return orte_gpr.delete_entries(ORTE_GPR_TOKENS_AND,
|
|
|
|
OMPI_NAMESPACE_SEGMENT,
|
2006-02-07 06:32:36 +03:00
|
|
|
token, NULL);
|
2005-04-12 23:54:45 +04:00
|
|
|
#endif
|
|
|
|
return OMPI_SUCCESS;
|
2004-06-17 01:34:42 +04:00
|
|
|
}
|