int bproc_test_init(const char *nstr) { int i; struct bproc_node_set_t ns; if (bproc_nodelist(&ns) == -1) { fprintf(stderr, "bproc_nodelist: %s\n", bproc_strerror(errno)); fprintf(stderr, "Failed to read node list, using front end only.\n"); nnodes = 0; return 0; } if (!nstr) nstr = getenv("NODES"); if (nstr) { /* Get the node set from the environment */ struct bproc_node_set_t ns1; if (bproc_nodefilter(&ns1, &ns, nstr)) { fprintf(stderr, "Invalid node set: %s\n", nstr); return -1; } nnodes = 0; for (i=0; i < ns1.size && nnodes < BPROC_TEST_NODES_MAX; i++) { if (bproc_access(ns1.node[i].node, 1) == 0) nodes[nnodes++] = ns1.node[i].node; else fprintf(stderr, "bproc_test: Ignoring user specified node %d " "- node is not accessible.\n", ns1.node[i].node); } bproc_nodeset_free(&ns1); } else { /* Find a nodeset automatically */ nnodes = 0; for (i=0; i < ns.size && nnodes < BPROC_TEST_NODES_MAX; i++) { if (bproc_access(ns.node[i].node, 1) == 0) nodes[nnodes++] = ns.node[i].node; } } /* Find an invalid node number */ for (i=0; i < ns.size; i++) { if (node_inv <= ns.node[i].node) node_inv = ns.node[i].node + 1; } bproc_nodeset_free(&ns); printf("bproc_test: node_set = -1"); for (i=0; i < nnodes; i++) printf(" %d", nodes[i]); printf("\n"); printf("bproc_test: invalid node = %d\n", node_inv); return 0; }
static int orte_ras_bjs_discover( opal_list_t* nodelist, orte_app_context_t** context, size_t num_context) { char* nodes; char* ptr; opal_list_item_t* item; opal_list_t new_nodes; int rc; /* query the nodelist from the registry */ if(ORTE_SUCCESS != (rc = orte_ras_base_node_query(nodelist))) { ORTE_ERROR_LOG(rc); return rc; } /* validate that any user supplied nodes actually exist, etc. */ item = opal_list_get_first(nodelist); while(item != opal_list_get_end(nodelist)) { opal_list_item_t* next = opal_list_get_next(item); int node_num; orte_ras_node_t* node = (orte_ras_node_t*)item; if(ORTE_SUCCESS != orte_ras_bjs_node_resolve(node->node_name, &node_num)) { opal_list_remove_item(nodelist,item); OBJ_DESTRUCT(item); item = next; continue; } if(orte_ras_bjs_node_state(node_num) != ORTE_NODE_STATE_UP) { opal_list_remove_item(nodelist,item); OBJ_DESTRUCT(item); item = next; continue; } if(bproc_access(node_num, BPROC_X_OK) != 0) { opal_list_remove_item(nodelist,item); OBJ_DESTRUCT(item); item = next; continue; } /* try and determine the number of available slots */ if(node->node_slots == 0) { node->node_slots = orte_ras_bjs_node_slots(node->node_name); } item = next; } /* parse the node list and check node status/access */ nodes = getenv("NODES"); if (NULL == nodes) { return ORTE_ERR_NOT_AVAILABLE; } OBJ_CONSTRUCT(&new_nodes, opal_list_t); while(NULL != (ptr = strsep(&nodes,","))) { orte_ras_node_t *node; orte_node_state_t node_state; int node_num; /* is this node already in the list */ for(item = opal_list_get_first(nodelist); item != opal_list_get_end(nodelist); item = opal_list_get_next(item)) { node = (orte_ras_node_t*)item; if(strcmp(node->node_name, ptr) == 0) break; } if(item != opal_list_get_end(nodelist)) continue; if(sscanf(ptr, "%d", &node_num) != 1) { continue; } if(ORTE_NODE_STATE_UP != (node_state = orte_ras_bjs_node_state(node_num))) { opal_output(0, "error: a specified node (%d) is not up.\n", node_num); rc = ORTE_ERROR; goto cleanup; } if(bproc_access(node_num, BPROC_X_OK) != 0) { opal_output(0, "error: a specified node (%d) is not accessible.\n", node_num); rc = ORTE_ERROR; goto cleanup; } /* create a new node entry */ node = OBJ_NEW(orte_ras_node_t); node->node_name = strdup(ptr); node->node_state = node_state; node->node_slots = orte_ras_bjs_node_slots(node->node_name); opal_list_append(&new_nodes, &node->super); } /* add any newly discovered nodes to the registry */ if(opal_list_get_size(&new_nodes)) { rc = orte_ras_base_node_insert(&new_nodes); if(ORTE_SUCCESS != rc) { ORTE_ERROR_LOG(rc); } } /* append them to the nodelist */ while(NULL != (item = opal_list_remove_first(&new_nodes))) opal_list_append(nodelist, item); cleanup: OBJ_DESTRUCT(&new_nodes); return rc; }