📄 ras_base_node.c
字号:
/* * 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. * 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. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */#include "orte_config.h"#include <string.h>#include "orte/orte_constants.h"#include "opal/util/output.h"#include "opal/util/argv.h"#include "orte/mca/errmgr/errmgr.h"#include "orte/mca/smr/smr_types.h"#include "orte/mca/gpr/gpr.h"#include "orte/mca/ns/ns.h"#include "orte/mca/ras/base/ras_private.h"static void orte_ras_base_node_construct(orte_ras_node_t* node){ node->node_name = NULL; node->launch_id = -1; node->node_arch = NULL; node->node_cellid = 0; node->node_state = ORTE_NODE_STATE_UNKNOWN; node->node_slots = 0; node->node_slots_inuse = 0; node->node_slots_alloc = 0; node->node_slots_max = 0; node->node_username = NULL; node->node_launched = 0;}static void orte_ras_base_node_destruct(orte_ras_node_t* node){ if (NULL != node->node_name) { free(node->node_name); } if (NULL != node->node_arch) { free(node->node_arch); } if (NULL != node->node_username) { free(node->node_username); }}OBJ_CLASS_INSTANCE( orte_ras_node_t, opal_list_item_t, orte_ras_base_node_construct, orte_ras_base_node_destruct);/* * Query the registry for all available nodes */int orte_ras_base_node_query(opal_list_t* nodes){ char* keys[] = { ORTE_NODE_NAME_KEY, ORTE_NODE_LAUNCH_ID_KEY, ORTE_NODE_ARCH_KEY, ORTE_NODE_STATE_KEY, ORTE_NODE_SLOTS_KEY, ORTE_NODE_SLOTS_IN_USE_KEY, ORTE_NODE_SLOTS_ALLOC_KEY, ORTE_NODE_SLOTS_MAX_KEY, ORTE_NODE_USERNAME_KEY, ORTE_CELLID_KEY, NULL }; orte_std_cntr_t i, cnt, *sptr; orte_node_state_t *nsptr; orte_cellid_t *cptr; int32_t *i32; orte_gpr_value_t** values; int rc; /* query all node entries */ rc = orte_gpr.get( ORTE_GPR_KEYS_OR|ORTE_GPR_TOKENS_OR, ORTE_NODE_SEGMENT, NULL, keys, &cnt, &values); if(ORTE_SUCCESS != rc) { ORTE_ERROR_LOG(rc); return rc; } /* parse the response */ for(i=0; i<cnt; i++) { orte_gpr_value_t* value = values[i]; orte_ras_node_t* node = OBJ_NEW(orte_ras_node_t); orte_std_cntr_t k; for(k=0; k<value->cnt; k++) { orte_gpr_keyval_t* keyval = value->keyvals[k]; if(strcmp(keyval->key, ORTE_NODE_NAME_KEY) == 0) { /* we use the dss.copy function here instead of strdup because that function * automatically protects us against a NULL (or zero-length) string */ if (ORTE_SUCCESS != (rc = orte_dss.copy((void**)&(node->node_name), keyval->value->data, ORTE_STRING))) { ORTE_ERROR_LOG(rc); continue; } continue; } if(strcmp(keyval->key, ORTE_NODE_LAUNCH_ID_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&i32, keyval->value, ORTE_INT32))) { ORTE_ERROR_LOG(rc); continue; } node->launch_id = *i32; continue; } if(strcmp(keyval->key, ORTE_NODE_ARCH_KEY) == 0) { /* we use the dss.copy function here instead of strdup because that function * automatically protects us against a NULL (or zero-length) string */ if (ORTE_SUCCESS != (rc = orte_dss.copy((void**)&(node->node_arch), keyval->value->data, ORTE_STRING))) { ORTE_ERROR_LOG(rc); continue; } continue; } if(strcmp(keyval->key, ORTE_NODE_STATE_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&nsptr, keyval->value, ORTE_NODE_STATE))) { ORTE_ERROR_LOG(rc); continue; } node->node_state = *nsptr; continue; } if(strcmp(keyval->key, ORTE_NODE_SLOTS_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&sptr, keyval->value, ORTE_STD_CNTR))) { ORTE_ERROR_LOG(rc); continue; } node->node_slots = *sptr; continue; } if(strcmp(keyval->key, ORTE_NODE_SLOTS_IN_USE_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&sptr, keyval->value, ORTE_STD_CNTR))) { ORTE_ERROR_LOG(rc); continue; } node->node_slots_inuse = *sptr; continue; } if(strncmp(keyval->key, ORTE_NODE_SLOTS_ALLOC_KEY, strlen(ORTE_NODE_SLOTS_ALLOC_KEY)) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&sptr, keyval->value, ORTE_STD_CNTR))) { ORTE_ERROR_LOG(rc); continue; } node->node_slots_alloc += *sptr; continue; } if(strcmp(keyval->key, ORTE_NODE_SLOTS_MAX_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&sptr, keyval->value, ORTE_STD_CNTR))) { ORTE_ERROR_LOG(rc); continue; } node->node_slots_max = *sptr; continue; } if(strcmp(keyval->key, ORTE_NODE_USERNAME_KEY) == 0) { /* we use the dss.copy function here instead of strdup because that function * automatically protects us against a NULL (or zero-length) string */ if (ORTE_SUCCESS != (rc = orte_dss.copy((void**)&(node->node_username), keyval->value->data, ORTE_STRING))) { ORTE_ERROR_LOG(rc); continue; } continue; } if(strcmp(keyval->key, ORTE_CELLID_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&cptr, keyval->value, ORTE_CELLID))) { ORTE_ERROR_LOG(rc); continue; } node->node_cellid = *cptr; continue; } } opal_list_append(nodes, &node->super); OBJ_RELEASE(value); } if (NULL != values) free(values); return ORTE_SUCCESS;}/* * Query the registry for all nodes allocated to a specified job */int orte_ras_base_node_query_alloc(opal_list_t* nodes, orte_jobid_t jobid){ char* keys[] = { ORTE_NODE_NAME_KEY, ORTE_NODE_LAUNCH_ID_KEY, ORTE_NODE_ARCH_KEY, ORTE_NODE_STATE_KEY, ORTE_NODE_SLOTS_KEY, ORTE_NODE_SLOTS_IN_USE_KEY, ORTE_NODE_SLOTS_ALLOC_KEY, ORTE_NODE_SLOTS_MAX_KEY, ORTE_NODE_USERNAME_KEY, ORTE_CELLID_KEY, NULL }; orte_std_cntr_t i, cnt, keys_len; orte_gpr_value_t** values; char* jobid_str; orte_std_cntr_t *sptr; orte_node_state_t *nsptr; orte_cellid_t *cptr; int32_t *i32; int rc, alloc_key_posn=5; if(ORTE_SUCCESS != (rc = orte_ns.convert_jobid_to_string(&jobid_str, jobid))) { ORTE_ERROR_LOG(rc); return rc; } asprintf(&keys[alloc_key_posn], "%s-%s", ORTE_NODE_SLOTS_ALLOC_KEY, jobid_str); keys_len = (orte_std_cntr_t)strlen(keys[alloc_key_posn]); free(jobid_str); /* query selected node entries */ rc = orte_gpr.get( ORTE_GPR_KEYS_OR|ORTE_GPR_TOKENS_OR, ORTE_NODE_SEGMENT, NULL, keys, &cnt, &values); if(ORTE_SUCCESS != rc) { ORTE_ERROR_LOG(rc); return rc; } /* parse the response */ for(i=0; i<cnt; i++) { orte_gpr_value_t* value = values[i]; orte_ras_node_t* node; orte_std_cntr_t k; bool found; found = false; for (k = 0; k < value->cnt; k++) { orte_gpr_keyval_t* keyval = value->keyvals[k]; if(0 == strcmp(keyval->key, keys[alloc_key_posn])) { found = true; break; } } if (!found) continue; node = OBJ_NEW(orte_ras_node_t); for(k=0; k < value->cnt; k++) { orte_gpr_keyval_t* keyval = value->keyvals[k]; if(strcmp(keyval->key, ORTE_NODE_NAME_KEY) == 0) { /* we use the dss.copy function here instead of strdup because that function * automatically protects us against a NULL (or zero-length) string */ if (ORTE_SUCCESS != (rc = orte_dss.copy((void**)&(node->node_name), keyval->value->data, ORTE_STRING))) { ORTE_ERROR_LOG(rc); continue; } continue; } if(strcmp(keyval->key, ORTE_NODE_LAUNCH_ID_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&i32, keyval->value, ORTE_INT32))) { ORTE_ERROR_LOG(rc); continue; } node->launch_id = *i32; continue; } if(strcmp(keyval->key, ORTE_NODE_ARCH_KEY) == 0) { /* we use the dss.copy function here instead of strdup because that function * automatically protects us against a NULL (or zero-length) string */ if (ORTE_SUCCESS != (rc = orte_dss.copy((void**)&(node->node_arch), keyval->value->data, ORTE_STRING))) { ORTE_ERROR_LOG(rc); continue; } continue; } if(strcmp(keyval->key, ORTE_NODE_STATE_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&nsptr, keyval->value, ORTE_NODE_STATE))) { ORTE_ERROR_LOG(rc); continue; } node->node_state = *nsptr; continue; } if(strcmp(keyval->key, ORTE_NODE_SLOTS_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&sptr, keyval->value, ORTE_STD_CNTR))) { ORTE_ERROR_LOG(rc); continue; } node->node_slots = *sptr; continue; } if(strcmp(keyval->key, ORTE_NODE_SLOTS_IN_USE_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&sptr, keyval->value, ORTE_STD_CNTR))) { ORTE_ERROR_LOG(rc); continue; } node->node_slots_inuse = *sptr; continue; } if(strncmp(keyval->key, keys[alloc_key_posn], keys_len) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&sptr, keyval->value, ORTE_STD_CNTR))) { ORTE_ERROR_LOG(rc); continue; } node->node_slots_alloc += *sptr; continue; } if(strcmp(keyval->key, ORTE_NODE_SLOTS_MAX_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&sptr, keyval->value, ORTE_STD_CNTR))) { ORTE_ERROR_LOG(rc); continue; } node->node_slots_max = *sptr; continue; } if(strcmp(keyval->key, ORTE_NODE_USERNAME_KEY) == 0) { /* we use the dss.copy function here instead of strdup because that function * automatically protects us against a NULL (or zero-length) string */ if (ORTE_SUCCESS != (rc = orte_dss.copy((void**)&(node->node_username), keyval->value->data, ORTE_STRING))) { ORTE_ERROR_LOG(rc); continue; } continue; } if(strcmp(keyval->key, ORTE_CELLID_KEY) == 0) { if (ORTE_SUCCESS != (rc = orte_dss.get((void**)&cptr, keyval->value, ORTE_CELLID))) { ORTE_ERROR_LOG(rc); continue; } node->node_cellid = *cptr; continue; } } /* check to see if any slots were reserved on this node for us * The "get" command will return data from ALL nodes on the node * segment. We ONLY want to include here nodes that are assigned * to the specified job - i.e., nodes that have a node_slots_alloc_key * for this jobid. If that is the case, then the node_slots_alloc will be * set to a value greater than 0 */ if (0 < node->node_slots_alloc) { opal_list_append(nodes, &node->super); } else { /* no slots were allocated to us on this node */ OBJ_RELEASE(node); } OBJ_RELEASE(value); } free (keys[alloc_key_posn]); if (NULL != values) free(values); return ORTE_SUCCESS;}/* * Query the registry for a specific node */orte_ras_node_t* orte_ras_base_node_lookup(orte_cellid_t cellid, const char* node_name){ char* keys[] = { ORTE_NODE_NAME_KEY, ORTE_NODE_LAUNCH_ID_KEY, ORTE_NODE_ARCH_KEY, ORTE_NODE_STATE_KEY, ORTE_NODE_SLOTS_KEY, ORTE_NODE_SLOTS_IN_USE_KEY, ORTE_NODE_SLOTS_ALLOC_KEY, ORTE_NODE_SLOTS_MAX_KEY, ORTE_NODE_USERNAME_KEY, ORTE_CELLID_KEY, NULL }; orte_ras_node_t* node = NULL; orte_std_cntr_t i, cnt, num_tokens; orte_std_cntr_t *sptr; orte_cellid_t *cptr; orte_node_state_t *nsptr; int32_t *i32; orte_gpr_value_t** values; char** tokens = NULL; int rc; rc = orte_schema.get_node_tokens(&tokens, &num_tokens, cellid, (char*)node_name); if(ORTE_SUCCESS != rc) { ORTE_ERROR_LOG(rc); return NULL; } /* query specific entry */ rc = orte_gpr.get( ORTE_GPR_KEYS_OR|ORTE_GPR_TOKENS_OR, ORTE_NODE_SEGMENT, tokens, keys, &cnt, &values); if(ORTE_SUCCESS != rc) { ORTE_ERROR_LOG(rc); return NULL; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -