2005-03-14 23:57:21 +03: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.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2006-02-07 06:32:36 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
2005-03-14 23:57:21 +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.
|
2005-03-14 23:57:21 +03:00
|
|
|
* $COPYRIGHT$
|
2006-02-07 06:32:36 +03:00
|
|
|
*
|
2005-03-14 23:57:21 +03:00
|
|
|
* Additional copyrights may follow
|
2006-02-07 06:32:36 +03:00
|
|
|
*
|
2005-03-14 23:57:21 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2005-09-19 19:29:14 +04:00
|
|
|
#include "orte_config.h"
|
2006-09-15 01:29:51 +04:00
|
|
|
#include "orte/orte_constants.h"
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
#include <errno.h>
|
2005-04-11 22:43:57 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-03-14 23:57:21 +03:00
|
|
|
#include <unistd.h>
|
2005-04-11 09:07:57 +04:00
|
|
|
#endif
|
2005-03-14 23:57:21 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
2005-09-19 19:29:14 +04:00
|
|
|
#include "opal/util/trace.h"
|
|
|
|
|
|
|
|
#include "orte/mca/gpr/gpr.h"
|
|
|
|
#include "orte/mca/ns/ns.h"
|
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2006-09-15 01:29:51 +04:00
|
|
|
#include "orte/mca/rmgr/base/rmgr_private.h"
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the job segment and initialize the application context.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int orte_rmgr_base_put_app_context(
|
|
|
|
orte_jobid_t jobid,
|
|
|
|
orte_app_context_t** app_context,
|
2006-08-15 23:54:10 +04:00
|
|
|
orte_std_cntr_t num_context)
|
2005-03-14 23:57:21 +03:00
|
|
|
{
|
2006-02-07 06:32:36 +03:00
|
|
|
orte_gpr_value_t *value;
|
2006-08-15 23:54:10 +04:00
|
|
|
orte_std_cntr_t i;
|
|
|
|
orte_std_cntr_t job_slots;
|
2005-03-14 23:57:21 +03:00
|
|
|
int rc;
|
2006-02-07 06:32:36 +03:00
|
|
|
char *segment;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2005-09-19 19:29:14 +04:00
|
|
|
OPAL_TRACE(2);
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
rc = orte_rmgr_base_get_job_slots(jobid, &job_slots);
|
|
|
|
if(ORTE_SUCCESS != rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put context info on the job segment of the registry */
|
2006-02-07 06:32:36 +03:00
|
|
|
if(ORTE_SUCCESS != (rc = orte_schema.get_job_segment_name(&segment, jobid))) {
|
2005-03-14 23:57:21 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_gpr.create_value(&value, ORTE_GPR_OVERWRITE,
|
|
|
|
segment, num_context, 1))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
free(segment);
|
|
|
|
return rc;
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
free(segment); /* don't need this any more */
|
|
|
|
|
|
|
|
value->tokens[0] = strdup(ORTE_JOB_GLOBALS);
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
for(i=0; i<num_context; i++) {
|
|
|
|
orte_app_context_t* app = app_context[i];
|
2006-06-16 02:14:07 +04:00
|
|
|
app->idx = i;
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_gpr.create_keyval(&(value->keyvals[i]),
|
|
|
|
ORTE_JOB_APP_CONTEXT_KEY,
|
|
|
|
ORTE_APP_CONTEXT,
|
|
|
|
app))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2005-03-14 23:57:21 +03:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2006-06-16 02:14:07 +04:00
|
|
|
|
2005-03-22 03:31:17 +03:00
|
|
|
OBJ_RETAIN(app);
|
2005-03-14 23:57:21 +03:00
|
|
|
job_slots += app->num_procs;
|
|
|
|
}
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
rc = orte_gpr.put(1, &value);
|
|
|
|
if(ORTE_SUCCESS != rc) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2005-10-08 02:24:52 +04:00
|
|
|
rc = orte_rmgr_base_set_job_slots(jobid, job_slots); /* JJH C/N napping breaks here */
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
OBJ_RELEASE(value);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Comparison function for sorting context by index.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int orte_rmgr_base_cmp_app_context(
|
|
|
|
orte_app_context_t** app1,
|
|
|
|
orte_app_context_t** app2)
|
|
|
|
{
|
2005-09-19 19:29:14 +04:00
|
|
|
OPAL_TRACE(3);
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if ((*app1)->idx < (*app2)->idx) {
|
|
|
|
return -1;
|
|
|
|
} else if((*app1)->idx > (*app2)->idx) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retreive the application context
|
|
|
|
*/
|
|
|
|
|
|
|
|
int orte_rmgr_base_get_app_context(
|
|
|
|
orte_jobid_t jobid,
|
|
|
|
orte_app_context_t*** app_context,
|
2006-08-15 23:54:10 +04:00
|
|
|
orte_std_cntr_t* num_context)
|
2005-03-14 23:57:21 +03:00
|
|
|
{
|
|
|
|
char *segment;
|
|
|
|
char *tokens[2];
|
|
|
|
char *keys[2];
|
|
|
|
orte_gpr_value_t** values = NULL;
|
2006-08-15 23:54:10 +04:00
|
|
|
orte_std_cntr_t i, num_values = 0, index = 0;
|
2005-03-14 23:57:21 +03:00
|
|
|
int rc;
|
|
|
|
|
2005-09-19 19:29:14 +04:00
|
|
|
OPAL_TRACE(2);
|
2006-02-07 06:32:36 +03:00
|
|
|
|
|
|
|
/* get the job segment name */
|
2005-03-14 23:57:21 +03:00
|
|
|
if(ORTE_SUCCESS != (rc = orte_schema.get_job_segment_name(&segment, jobid)))
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
tokens[0] = ORTE_JOB_GLOBALS;
|
|
|
|
tokens[1] = NULL;
|
|
|
|
|
|
|
|
keys[0] = ORTE_JOB_APP_CONTEXT_KEY;
|
|
|
|
keys[1] = NULL;
|
|
|
|
|
|
|
|
rc = orte_gpr.get(
|
|
|
|
ORTE_GPR_TOKENS_OR,
|
|
|
|
segment,
|
|
|
|
tokens,
|
|
|
|
keys,
|
|
|
|
&num_values,
|
|
|
|
&values
|
|
|
|
);
|
2005-12-21 16:45:06 +03:00
|
|
|
if (rc != ORTE_SUCCESS) {
|
2005-03-14 23:57:21 +03:00
|
|
|
goto cleanup;
|
2005-12-21 16:45:06 +03:00
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
*num_context = 0;
|
|
|
|
for(i=0; i<num_values; i++) {
|
|
|
|
*num_context += values[i]->cnt;
|
|
|
|
}
|
2005-12-21 16:45:06 +03:00
|
|
|
if (0 == *num_context) {
|
|
|
|
*app_context = NULL;
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
*app_context = (orte_app_context_t**)malloc(*num_context * sizeof(orte_app_context_t*));
|
|
|
|
for(i=0; i<num_values; i++) {
|
|
|
|
orte_gpr_value_t* value = values[i];
|
|
|
|
orte_gpr_keyval_t** keyvals = value->keyvals;
|
2006-08-15 23:54:10 +04:00
|
|
|
orte_std_cntr_t k;
|
2005-03-14 23:57:21 +03:00
|
|
|
for(k=0; k < value->cnt; k++) {
|
2006-02-07 06:32:36 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&((*app_context)[index++]), keyvals[k]->value, ORTE_APP_CONTEXT))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
keyvals[k]->value->data = NULL; /* protect the data storage from later release */
|
2005-03-14 23:57:21 +03:00
|
|
|
}
|
|
|
|
}
|
2006-02-07 06:32:36 +03:00
|
|
|
qsort(*app_context, *num_context, sizeof(orte_app_context_t*),
|
2005-03-14 23:57:21 +03:00
|
|
|
(int (*)(const void*,const void*))orte_rmgr_base_cmp_app_context);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for(i=0; i<num_values; i++) {
|
|
|
|
OBJ_RELEASE(values[i]);
|
|
|
|
}
|
2006-02-07 06:32:36 +03:00
|
|
|
if(NULL != values)
|
2005-03-14 23:57:21 +03:00
|
|
|
free(values);
|
|
|
|
free(segment);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Query for the total number of process slots requested for the job.
|
|
|
|
*/
|
|
|
|
|
2006-08-15 23:54:10 +04:00
|
|
|
int orte_rmgr_base_get_job_slots(orte_jobid_t jobid, orte_std_cntr_t* proc_slots)
|
2005-03-14 23:57:21 +03:00
|
|
|
{
|
|
|
|
char *segment;
|
|
|
|
char *tokens[2];
|
|
|
|
char *keys[2];
|
|
|
|
orte_gpr_value_t** values = NULL;
|
2006-08-15 23:54:10 +04:00
|
|
|
orte_std_cntr_t i, num_values = 0, *ps;
|
2005-03-14 23:57:21 +03:00
|
|
|
int rc;
|
|
|
|
|
2005-09-19 19:29:14 +04:00
|
|
|
OPAL_TRACE(2);
|
2006-02-07 06:32:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
/* query the job segment on the registry */
|
|
|
|
if(ORTE_SUCCESS != (rc = orte_schema.get_job_segment_name(&segment, jobid)))
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
tokens[0] = ORTE_JOB_GLOBALS;
|
|
|
|
tokens[1] = NULL;
|
|
|
|
|
|
|
|
keys[0] = ORTE_JOB_SLOTS_KEY;
|
|
|
|
keys[1] = NULL;
|
|
|
|
|
|
|
|
rc = orte_gpr.get(
|
|
|
|
ORTE_GPR_KEYS_OR|ORTE_GPR_TOKENS_OR,
|
|
|
|
segment,
|
|
|
|
tokens,
|
|
|
|
keys,
|
|
|
|
&num_values,
|
|
|
|
&values
|
|
|
|
);
|
2005-03-19 02:58:36 +03:00
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if(rc != ORTE_SUCCESS) {
|
|
|
|
free(segment);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
free(segment); /* don't need this any more */
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
if(0 == num_values) {
|
|
|
|
*proc_slots = 0;
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
if(1 != num_values || values[0]->cnt != 1) {
|
|
|
|
return ORTE_ERR_NOT_FOUND;
|
|
|
|
}
|
2006-08-15 23:54:10 +04:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&ps, values[0]->keyvals[0]->value, ORTE_STD_CNTR))) {
|
2006-02-07 06:32:36 +03:00
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
*proc_slots = *ps;
|
2005-03-14 23:57:21 +03:00
|
|
|
|
|
|
|
for(i=0; i<num_values; i++)
|
|
|
|
OBJ_RELEASE(values[i]);
|
2006-02-07 06:32:36 +03:00
|
|
|
if (NULL != values) free(values);
|
|
|
|
|
2005-03-14 23:57:21 +03:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the total number of process slots requested for the job.
|
|
|
|
*/
|
|
|
|
|
2006-08-15 23:54:10 +04:00
|
|
|
int orte_rmgr_base_set_job_slots(orte_jobid_t jobid, orte_std_cntr_t proc_slots)
|
2005-03-14 23:57:21 +03:00
|
|
|
{
|
2006-02-07 06:32:36 +03:00
|
|
|
orte_gpr_value_t *value;
|
2005-03-14 23:57:21 +03:00
|
|
|
char *segment;
|
|
|
|
int rc;
|
|
|
|
|
2005-09-19 19:29:14 +04:00
|
|
|
OPAL_TRACE(2);
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
/* put context info on the job segment of the registry */
|
|
|
|
if(ORTE_SUCCESS != (rc = orte_schema.get_job_segment_name(&segment, jobid))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_gpr.create_value(&value, ORTE_GPR_OVERWRITE,
|
|
|
|
segment, 1, 1))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
free(segment);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
free(segment);
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
value->tokens[0] = strdup(ORTE_JOB_GLOBALS);
|
2005-03-14 23:57:21 +03:00
|
|
|
|
2006-02-07 06:32:36 +03:00
|
|
|
if (ORTE_SUCCESS != (rc = orte_gpr.create_keyval(&(value->keyvals[0]),
|
|
|
|
ORTE_JOB_SLOTS_KEY,
|
2006-08-15 23:54:10 +04:00
|
|
|
ORTE_STD_CNTR,
|
2006-02-07 06:32:36 +03:00
|
|
|
&proc_slots))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_gpr.put(1, &value))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
OBJ_RELEASE(value);
|
2005-03-14 23:57:21 +03:00
|
|
|
return rc;
|
|
|
|
}
|