2006-09-14 19:27:17 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2015-06-24 06:59:57 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
2006-09-14 19:27:17 +04:00
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2010-12-14 17:52:51 +03:00
|
|
|
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
|
2015-02-17 06:27:23 +03:00
|
|
|
* Copyright (c) 2015 Research Organization for Information Science
|
|
|
|
* and Technology (RIST). All rights reserved.
|
2006-09-14 19:27:17 +04:00
|
|
|
* $COPYRIGHT$
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2006-09-14 19:27:17 +04:00
|
|
|
* Additional copyrights may follow
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2006-09-14 19:27:17 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2006-09-24 22:40:55 +04:00
|
|
|
|
2006-09-14 19:27:17 +04:00
|
|
|
#include "orte_config.h"
|
2006-09-24 22:40:55 +04:00
|
|
|
|
2009-03-13 05:10:32 +03:00
|
|
|
#include <string.h>
|
2006-09-24 22:40:55 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
2006-09-25 19:32:54 +04:00
|
|
|
#include <time.h>
|
2006-09-24 22:40:55 +04:00
|
|
|
|
2013-03-28 01:09:41 +04:00
|
|
|
#include "opal/mca/base/mca_base_var.h"
|
2014-02-24 01:41:38 +04:00
|
|
|
#include "opal/util/alfg.h"
|
2006-09-14 19:27:17 +04:00
|
|
|
#include "opal/util/opal_environ.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
|
2009-03-13 05:10:32 +03:00
|
|
|
#include "orte/constants.h"
|
|
|
|
#include "orte/types.h"
|
2006-09-14 19:27:17 +04:00
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
|
|
|
|
|
|
|
#include "orte/util/pre_condition_transports.h"
|
|
|
|
|
|
|
|
/* some network transports require a little bit of information to
|
|
|
|
* "pre-condition" them - i.e., to setup their individual transport
|
|
|
|
* connections so they can generate their endpoint addresses. This
|
|
|
|
* function provides a means for doing so. The resulting info is placed
|
|
|
|
* into the app_context's env array so it will automatically be pushed
|
|
|
|
* into the environment of every MPI process when launched.
|
|
|
|
*/
|
|
|
|
|
2015-06-24 06:59:57 +03:00
|
|
|
static inline void orte_pre_condition_transports_use_rand(uint64_t* unique_key) {
|
2014-02-25 03:18:35 +04:00
|
|
|
opal_rng_buff_t rng;
|
2014-02-24 01:41:38 +04:00
|
|
|
opal_srand(&rng,(unsigned int)time(NULL));
|
|
|
|
unique_key[0] = opal_rand(&rng);
|
|
|
|
unique_key[1] = opal_rand(&rng);
|
2006-09-20 20:59:44 +04:00
|
|
|
}
|
2006-09-24 11:52:42 +04:00
|
|
|
|
2011-04-28 17:54:33 +04:00
|
|
|
char* orte_pre_condition_transports_print(uint64_t *unique_key)
|
2006-09-14 19:27:17 +04:00
|
|
|
{
|
2006-12-04 21:07:24 +03:00
|
|
|
unsigned int *int_ptr;
|
2016-04-29 03:02:47 +03:00
|
|
|
size_t i, j, string_key_len, written_len;
|
2011-04-28 17:54:33 +04:00
|
|
|
char *string_key = NULL, *format = NULL;
|
2006-10-05 09:39:49 +04:00
|
|
|
|
2006-12-04 21:07:24 +03:00
|
|
|
/* string is two 64 bit numbers printed in hex with a dash between
|
|
|
|
* and zero padding.
|
2006-12-03 20:05:15 +03:00
|
|
|
*/
|
2006-12-04 21:07:24 +03:00
|
|
|
string_key_len = (sizeof(uint64_t) * 2) * 2 + strlen("-") + 1;
|
|
|
|
string_key = (char*) malloc(string_key_len);
|
|
|
|
if (NULL == string_key) {
|
2011-04-28 17:54:33 +04:00
|
|
|
return NULL;
|
2006-12-04 21:07:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
string_key[0] = '\0';
|
|
|
|
written_len = 0;
|
|
|
|
|
|
|
|
/* get a format string based on the length of an unsigned int. We
|
|
|
|
* want to have zero padding for sizeof(unsigned int) * 2
|
|
|
|
* characters -- when printing as a hex number, each byte is
|
|
|
|
* represented by 2 hex characters. Format will contain something
|
|
|
|
* that looks like %08lx, where the number 8 might be a different
|
|
|
|
* number if the system has a different sized long (8 would be for
|
|
|
|
* sizeof(int) == 4)).
|
|
|
|
*/
|
2006-12-05 00:45:57 +03:00
|
|
|
asprintf(&format, "%%0%dx", (int)(sizeof(unsigned int)) * 2);
|
2006-12-04 21:07:24 +03:00
|
|
|
|
|
|
|
/* print the first number */
|
|
|
|
int_ptr = (unsigned int*) &unique_key[0];
|
|
|
|
for (i = 0 ; i < sizeof(uint64_t) / sizeof(unsigned int) ; ++i) {
|
2016-04-29 03:02:47 +03:00
|
|
|
if (0 == int_ptr[i]) {
|
|
|
|
/* inject some energy */
|
|
|
|
for (j=0; j < sizeof(unsigned int); j++) {
|
|
|
|
int_ptr[i] |= j << j;
|
|
|
|
}
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
snprintf(string_key + written_len,
|
2006-12-04 21:07:24 +03:00
|
|
|
string_key_len - written_len,
|
|
|
|
format, int_ptr[i]);
|
|
|
|
written_len = strlen(string_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print the middle dash */
|
|
|
|
snprintf(string_key + written_len, string_key_len - written_len, "-");
|
|
|
|
written_len = strlen(string_key);
|
|
|
|
|
|
|
|
/* print the second number */
|
|
|
|
int_ptr = (unsigned int*) &unique_key[1];
|
|
|
|
for (i = 0 ; i < sizeof(uint64_t) / sizeof(unsigned int) ; ++i) {
|
2016-04-29 03:02:47 +03:00
|
|
|
if (0 == int_ptr[i]) {
|
|
|
|
/* inject some energy */
|
|
|
|
for (j=0; j < sizeof(unsigned int); j++) {
|
|
|
|
int_ptr[i] |= j << j;
|
|
|
|
}
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
snprintf(string_key + written_len,
|
2006-12-04 21:07:24 +03:00
|
|
|
string_key_len - written_len,
|
|
|
|
format, int_ptr[i]);
|
|
|
|
written_len = strlen(string_key);
|
|
|
|
}
|
2011-04-28 17:54:33 +04:00
|
|
|
free(format);
|
|
|
|
|
|
|
|
return string_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int orte_pre_condition_transports(orte_job_t *jdata)
|
|
|
|
{
|
|
|
|
uint64_t unique_key[2];
|
|
|
|
int n;
|
|
|
|
orte_app_context_t *app;
|
|
|
|
char *string_key, *cs_env;
|
|
|
|
int fd_rand;
|
2015-06-24 06:59:57 +03:00
|
|
|
size_t bytes_read;
|
2011-04-28 17:54:33 +04:00
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
/* put the number here - or else create an appropriate string. this just needs to
|
|
|
|
* eventually be a string variable
|
|
|
|
*/
|
2015-06-24 06:59:57 +03:00
|
|
|
if(0 != stat("/dev/urandom", &buf)) {
|
2011-04-28 17:54:33 +04:00
|
|
|
/* file doesn't exist! */
|
2015-06-24 06:59:57 +03:00
|
|
|
orte_pre_condition_transports_use_rand(unique_key);
|
2011-04-28 17:54:33 +04:00
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2011-04-28 17:54:33 +04:00
|
|
|
if(-1 == (fd_rand = open("/dev/urandom", O_RDONLY))) {
|
2015-06-24 06:59:57 +03:00
|
|
|
orte_pre_condition_transports_use_rand(unique_key);
|
|
|
|
} else {
|
2011-04-28 17:54:33 +04:00
|
|
|
bytes_read = read(fd_rand, (char *) unique_key, 16);
|
|
|
|
if(bytes_read != 16) {
|
2015-06-24 06:59:57 +03:00
|
|
|
orte_pre_condition_transports_use_rand(unique_key);
|
2011-04-28 17:54:33 +04:00
|
|
|
}
|
2015-02-17 06:27:23 +03:00
|
|
|
close(fd_rand);
|
2011-04-28 17:54:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == (string_key = orte_pre_condition_transports_print(unique_key))) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
2013-03-28 01:09:41 +04:00
|
|
|
if (OPAL_SUCCESS != mca_base_var_env_name ("orte_precondition_transports", &cs_env)) {
|
2006-09-14 19:27:17 +04:00
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
2015-02-17 06:27:23 +03:00
|
|
|
free(string_key);
|
2006-09-14 19:27:17 +04:00
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
2015-06-24 06:59:57 +03:00
|
|
|
|
2010-02-27 20:37:34 +03:00
|
|
|
for (n=0; n < jdata->apps->size; n++) {
|
|
|
|
if (NULL == (app = (orte_app_context_t*)opal_pointer_array_get_item(jdata->apps, n))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
opal_setenv(cs_env, string_key, true, &app->env);
|
2006-09-14 19:27:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(cs_env);
|
2007-03-07 04:09:38 +03:00
|
|
|
free(string_key);
|
2006-09-14 19:27:17 +04:00
|
|
|
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|