2010-04-23 09:51:29 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2011-06-24 00:38:02 +04:00
|
|
|
* Copyright (c) 2004-2011 The University of Tennessee and The University
|
2010-04-23 09:51:29 +04:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2010-08-09 23:28:56 +04:00
|
|
|
* Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
|
2013-02-28 21:31:47 +04:00
|
|
|
* Copyright (c) 2011 Cisco Systems, Inc. All rights reserved.
|
2014-02-09 06:10:31 +04:00
|
|
|
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
|
2010-04-23 09:51:29 +04:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "orte_config.h"
|
|
|
|
#include "orte/constants.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2010-07-13 10:33:07 +04:00
|
|
|
#include "opal/hash_string.h"
|
2010-04-23 09:51:29 +04:00
|
|
|
#include "opal/util/argv.h"
|
|
|
|
#include "opal/util/path.h"
|
|
|
|
#include "opal/mca/installdirs/installdirs.h"
|
|
|
|
|
|
|
|
#include "orte/util/show_help.h"
|
|
|
|
#include "orte/util/proc_info.h"
|
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
|
|
|
#include "orte/mca/routed/routed.h"
|
|
|
|
#include "orte/util/name_fns.h"
|
|
|
|
#include "orte/runtime/orte_globals.h"
|
|
|
|
#include "orte/util/nidmap.h"
|
2014-02-09 06:10:31 +04:00
|
|
|
#include "orte/util/session_dir.h"
|
2010-04-23 09:51:29 +04:00
|
|
|
|
|
|
|
#include "orte/mca/ess/ess.h"
|
|
|
|
#include "orte/mca/ess/base/base.h"
|
|
|
|
#include "orte/mca/ess/singleton/ess_singleton.h"
|
|
|
|
|
|
|
|
|
|
|
|
static int rte_init(void);
|
|
|
|
static int rte_finalize(void);
|
|
|
|
|
2013-03-28 01:09:41 +04:00
|
|
|
extern char *orte_ess_singleton_server_uri;
|
|
|
|
|
2010-04-23 09:51:29 +04:00
|
|
|
orte_ess_base_module_t orte_ess_singleton_module = {
|
|
|
|
rte_init,
|
|
|
|
rte_finalize,
|
|
|
|
orte_ess_base_app_abort,
|
|
|
|
NULL /* ft_event */
|
|
|
|
};
|
|
|
|
|
|
|
|
static int rte_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
2013-03-28 01:09:41 +04:00
|
|
|
char *param;
|
2010-07-13 10:33:07 +04:00
|
|
|
uint16_t jobfam;
|
|
|
|
uint32_t hash32;
|
|
|
|
uint32_t bias;
|
|
|
|
|
2010-04-23 09:51:29 +04:00
|
|
|
/* run the prolog */
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_ess_base_std_prolog())) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2010-07-13 10:33:07 +04:00
|
|
|
|
2013-03-28 01:09:41 +04:00
|
|
|
if (NULL != orte_ess_singleton_server_uri) {
|
2010-07-13 10:33:07 +04:00
|
|
|
/* we are going to connect to a server HNP */
|
2013-03-28 01:09:41 +04:00
|
|
|
if (0 == strncmp(orte_ess_singleton_server_uri, "file", strlen("file")) ||
|
|
|
|
0 == strncmp(orte_ess_singleton_server_uri, "FILE", strlen("FILE"))) {
|
2010-07-13 10:33:07 +04:00
|
|
|
char input[1024], *filename;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
/* it is a file - get the filename */
|
2013-03-28 01:09:41 +04:00
|
|
|
filename = strchr(orte_ess_singleton_server_uri, ':');
|
2010-07-13 10:33:07 +04:00
|
|
|
if (NULL == filename) {
|
|
|
|
/* filename is not correctly formatted */
|
|
|
|
orte_show_help("help-orterun.txt", "orterun:ompi-server-filename-bad", true,
|
2013-03-28 01:09:41 +04:00
|
|
|
"singleton", orte_ess_singleton_server_uri);
|
2010-07-13 10:33:07 +04:00
|
|
|
return ORTE_ERROR;
|
|
|
|
}
|
|
|
|
++filename; /* space past the : */
|
|
|
|
|
|
|
|
if (0 >= strlen(filename)) {
|
|
|
|
/* they forgot to give us the name! */
|
|
|
|
orte_show_help("help-orterun.txt", "orterun:ompi-server-filename-missing", true,
|
2013-03-28 01:09:41 +04:00
|
|
|
"singleton", orte_ess_singleton_server_uri);
|
2010-07-13 10:33:07 +04:00
|
|
|
return ORTE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open the file and extract the uri */
|
|
|
|
fp = fopen(filename, "r");
|
|
|
|
if (NULL == fp) { /* can't find or read file! */
|
|
|
|
orte_show_help("help-orterun.txt", "orterun:ompi-server-filename-access", true,
|
2013-03-28 01:09:41 +04:00
|
|
|
"singleton", orte_ess_singleton_server_uri);
|
2010-07-13 10:33:07 +04:00
|
|
|
return ORTE_ERROR;
|
|
|
|
}
|
|
|
|
if (NULL == fgets(input, 1024, fp)) {
|
|
|
|
/* something malformed about file */
|
|
|
|
fclose(fp);
|
|
|
|
orte_show_help("help-orterun.txt", "orterun:ompi-server-file-bad", true,
|
2013-03-28 01:09:41 +04:00
|
|
|
"singleton", orte_ess_singleton_server_uri, "singleton");
|
2010-07-13 10:33:07 +04:00
|
|
|
return ORTE_ERROR;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
input[strlen(input)-1] = '\0'; /* remove newline */
|
|
|
|
orte_process_info.my_hnp_uri = strdup(input);
|
|
|
|
} else {
|
2013-03-28 01:09:41 +04:00
|
|
|
orte_process_info.my_hnp_uri = strdup(orte_ess_singleton_server_uri);
|
2010-07-13 10:33:07 +04:00
|
|
|
}
|
|
|
|
/* save the daemon uri - we will process it later */
|
|
|
|
orte_process_info.my_daemon_uri = strdup(orte_process_info.my_hnp_uri);
|
|
|
|
/* for convenience, push the pubsub version of this param into the environ */
|
|
|
|
asprintf(¶m,"OMPI_MCA_pubsub_orte_server=%s",orte_process_info.my_hnp_uri);
|
|
|
|
putenv(param);
|
2013-10-04 06:58:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* indicate we are a singleton so orte_init knows what to do */
|
|
|
|
orte_process_info.proc_type |= ORTE_PROC_SINGLETON;
|
|
|
|
/* now define my own name */
|
|
|
|
/* hash the nodename */
|
|
|
|
OPAL_HASH_STR(orte_process_info.nodename, hash32);
|
2010-07-13 10:33:07 +04:00
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
bias = (uint32_t)orte_process_info.pid;
|
2010-07-13 10:33:07 +04:00
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
OPAL_OUTPUT_VERBOSE((5, orte_ess_base_framework.framework_output,
|
|
|
|
"ess:singleton: initial bias %ld nodename hash %lu",
|
|
|
|
(long)bias, (unsigned long)hash32));
|
2010-07-13 10:33:07 +04:00
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
/* fold in the bias */
|
|
|
|
hash32 = hash32 ^ bias;
|
2010-07-13 10:33:07 +04:00
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
/* now compress to 16-bits */
|
|
|
|
jobfam = (uint16_t)(((0x0000ffff & (0xffff0000 & hash32) >> 16)) ^ (0x0000ffff & hash32));
|
2010-07-13 10:33:07 +04:00
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
OPAL_OUTPUT_VERBOSE((5, orte_ess_base_framework.framework_output,
|
|
|
|
"ess:singleton:: final jobfam %lu",
|
|
|
|
(unsigned long)jobfam));
|
2010-07-13 10:33:07 +04:00
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
/* set the name - if we eventually spawn an HNP, it will use
|
|
|
|
* local jobid 0, so offset us by 1
|
|
|
|
*/
|
|
|
|
ORTE_PROC_MY_NAME->jobid = (0xffff0000 & ((uint32_t)jobfam << 16)) + 1;
|
|
|
|
ORTE_PROC_MY_NAME->vpid = 0;
|
2010-04-23 09:51:29 +04:00
|
|
|
|
|
|
|
orte_process_info.num_procs = 1;
|
2011-06-24 00:38:02 +04:00
|
|
|
if (orte_process_info.max_procs < orte_process_info.num_procs) {
|
|
|
|
orte_process_info.max_procs = orte_process_info.num_procs;
|
|
|
|
}
|
2010-04-23 09:51:29 +04:00
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
/* flag that we are not routing since we have no HNP */
|
|
|
|
orte_routing_is_enabled = false;
|
2010-04-23 09:51:29 +04:00
|
|
|
|
2014-02-09 06:10:31 +04:00
|
|
|
/* clear the session directory just in case there are
|
|
|
|
* stale directories laying around
|
|
|
|
*/
|
|
|
|
orte_session_dir_cleanup(ORTE_JOBID_WILDCARD);
|
|
|
|
|
2011-10-20 00:18:14 +04:00
|
|
|
/* use the std app init to complete the procedure */
|
2013-10-02 23:03:46 +04:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_ess_base_app_setup(true))) {
|
2010-04-23 09:51:29 +04:00
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2011-10-20 00:18:14 +04:00
|
|
|
|
|
|
|
/* if one was provided, build my nidmap */
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_util_nidmap_init(orte_process_info.sync_buf))) {
|
2010-04-23 09:51:29 +04:00
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2012-04-10 23:08:54 +04:00
|
|
|
|
|
|
|
/* set the collective ids */
|
|
|
|
orte_process_info.peer_modex = 0;
|
|
|
|
orte_process_info.peer_init_barrier = 1;
|
|
|
|
orte_process_info.peer_fini_barrier = 2;
|
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
/* to the best of our knowledge, we are alone */
|
|
|
|
orte_process_info.my_node_rank = 0;
|
|
|
|
orte_process_info.my_local_rank = 0;
|
|
|
|
|
2012-08-14 02:13:49 +04:00
|
|
|
/* set some envars */
|
|
|
|
putenv("OMPI_NUM_APP_CTX=1");
|
|
|
|
putenv("OMPI_FIRST_RANKS=0");
|
|
|
|
putenv("OMPI_APP_CTX_NUM_PROCS=1");
|
|
|
|
putenv("OMPI_MCA_orte_ess_num_procs=1");
|
|
|
|
|
2010-04-23 09:51:29 +04:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rte_finalize(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* deconstruct my nidmap and jobmap arrays */
|
|
|
|
orte_util_nidmap_finalize();
|
|
|
|
|
|
|
|
/* use the default procedure to finish */
|
|
|
|
if (ORTE_SUCCESS != (ret = orte_ess_base_app_finalize())) {
|
|
|
|
ORTE_ERROR_LOG(ret);
|
|
|
|
}
|
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
/* cleanup the environment */
|
|
|
|
unsetenv("OMPI_NUM_APP_CTX");
|
|
|
|
unsetenv("OMPI_FIRST_RANKS");
|
|
|
|
unsetenv("OMPI_APP_CTX_NUM_PROCS");
|
|
|
|
unsetenv("OMPI_MCA_orte_ess_num_procs");
|
|
|
|
unsetenv("OMPI_MCA_pubsub_orte_server"); // just in case it is there
|
2010-04-23 09:51:29 +04:00
|
|
|
|
2013-10-04 06:58:26 +04:00
|
|
|
return ret;
|
2010-04-23 09:51:29 +04:00
|
|
|
}
|