/* * Query the registry for all nodes allocated to a specified app_context */ int orte_rmaps_base_get_target_nodes(opal_list_t *allocated_nodes, orte_std_cntr_t *total_num_slots, orte_app_context_t *app, orte_mapping_policy_t policy) { opal_list_item_t *item, *next; orte_node_t *node; orte_std_cntr_t num_slots; orte_std_cntr_t i; int rc; /** set default answer */ *total_num_slots = 0; /* if the hnp was allocated, include it unless flagged not to */ if (orte_hnp_is_allocated) { if (NULL != (node = (orte_node_t*)opal_pointer_array_get_item(orte_node_pool, 0))) { if (ORTE_NODE_STATE_DO_NOT_USE == node->state) { /* clear this for future use, but don't include it */ node->state = ORTE_NODE_STATE_UP; } else if (ORTE_NODE_STATE_NOT_INCLUDED != node->state) { OBJ_RETAIN(node); opal_list_append(allocated_nodes, &node->super); } } } /* add everything in the node pool that can be used */ for (i=1; i < orte_node_pool->size; i++) { if (NULL != (node = (orte_node_t*)opal_pointer_array_get_item(orte_node_pool, i))) { /* ignore nodes that are marked as do-not-use for this mapping */ if (ORTE_NODE_STATE_DO_NOT_USE == node->state) { /* reset the state so it can be used another time */ node->state = ORTE_NODE_STATE_UP; continue; } if (ORTE_NODE_STATE_DOWN == node->state) { continue; } if (ORTE_NODE_STATE_NOT_INCLUDED == node->state) { /* not to be used */ continue; } /* retain a copy for our use in case the item gets * destructed along the way */ OBJ_RETAIN(node); opal_list_append(allocated_nodes, &node->super); } } /** check that anything is here */ if (0 == opal_list_get_size(allocated_nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-available-resources", true); return ORTE_ERR_SILENT; } /* is there a default hostfile? */ if (NULL != orte_default_hostfile) { /* yes - filter the node list through the file, removing * any nodes not in the file -or- excluded via ^ */ if (ORTE_SUCCESS != (rc = orte_util_filter_hostfile_nodes(allocated_nodes, orte_default_hostfile))) { ORTE_ERROR_LOG(rc); return rc; } /** check that anything is here */ if (0 == opal_list_get_size(allocated_nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-available-resources", true); return ORTE_ERR_SILENT; } } /* did the app_context contain a hostfile? */ if (NULL != app && NULL != app->hostfile) { /* yes - filter the node list through the file, removing * any nodes not found in the file */ if (ORTE_SUCCESS != (rc = orte_util_filter_hostfile_nodes(allocated_nodes, app->hostfile))) { ORTE_ERROR_LOG(rc); return rc; } /** check that anything is here */ if (0 == opal_list_get_size(allocated_nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, app->hostfile); return ORTE_ERR_SILENT; } } /* did the app_context contain an add-hostfile? */ if (NULL != app && NULL != app->add_hostfile) { /* yes - filter the node list through the file, removing * any nodes not found in the file */ if (ORTE_SUCCESS != (rc = orte_util_filter_hostfile_nodes(allocated_nodes, app->add_hostfile))) { ORTE_ERROR_LOG(rc); return rc; } /** check that anything is here */ if (0 == opal_list_get_size(allocated_nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, app->hostfile); return ORTE_ERR_SILENT; } } /* now filter the list through any -host specification */ if (NULL != app && NULL != app->dash_host) { if (ORTE_SUCCESS != (rc = orte_util_filter_dash_host_nodes(allocated_nodes, app->dash_host))) { ORTE_ERROR_LOG(rc); return rc; } /** check that anything is left! */ if (0 == opal_list_get_size(allocated_nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, ""); return ORTE_ERR_SILENT; } } /* now filter the list through any add-host specification */ if (NULL != app && NULL != app->add_host) { if (ORTE_SUCCESS != (rc = orte_util_filter_dash_host_nodes(allocated_nodes, app->add_host))) { ORTE_ERROR_LOG(rc); return rc; } /** check that anything is left! */ if (0 == opal_list_get_size(allocated_nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, ""); return ORTE_ERR_SILENT; } } /* finally, filter thru any resource constraints */ #if 0 for (item = opal_list_get_first(&app->resource_constraints); item != opal_list_get_end(&app->resource_constraints); item = opal_list_get_next(item)) { req_res = (opal_sysinfo_value_t*)item; OPAL_OUTPUT_VERBOSE((5, orte_rmaps_base.rmaps_output, "%s CHECKING CONSTRAINT %s FOR APP %s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), req_res->key, app->app)); /* check against node values */ item2 = opal_list_get_first(allocated_nodes); while (item2 != opal_list_get_end(allocated_nodes)) { next = opal_list_get_next(item2); node = (orte_node_t*)item2; found = false; for (item3 = opal_list_get_first(&node->resources); item3 != opal_list_get_end(&node->resources); item3 = opal_list_get_next(item3)) { ninfo = (opal_sysinfo_value_t*)item3; OPAL_OUTPUT_VERBOSE((5, orte_rmaps_base.rmaps_output, "%s COMPARING CONSTRAINT %s WITH RESOURCE %s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), req_res->key, ninfo->key)); if (0 == strcmp(req_res->key, ninfo->key)) { if (OPAL_STRING == req_res->type) { OPAL_OUTPUT_VERBOSE((5, orte_rmaps_base.rmaps_output, "%s CHECKING RESOURCE %s:%s ON NODE %s:%s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), ninfo->key, req_res->data.str, node->name, ninfo->data.str)); /* there could be multiple hosts or host-types here */ vals = opal_argv_split(req_res->data.str, ','); for (i=0; NULL != vals[i]; i++) { if (0 == strncasecmp(vals[i], ninfo->data.str, strlen(vals[i]))) { found = true; break; } } opal_argv_free(vals); } else { OPAL_OUTPUT_VERBOSE((5, orte_rmaps_base.rmaps_output, "%s CHECKING RESOURCE %s:%ld ON NODE %s:%ld", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), ninfo->key, (long)req_res->data.i64, node->name, (long)ninfo->data.i64)); if (req_res->data.i64 <= ninfo->data.i64) { found = true; } } break; } } OPAL_OUTPUT_VERBOSE((5, orte_rmaps_base.rmaps_output, "%s CONSTRAINT RESULTED IN %s NODE %s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), found ? "RETAINING" : "REMOVING", node->name)); if (!found) { opal_list_remove_item(allocated_nodes, item2); OBJ_RELEASE(item2); } item2 = next; } } #endif /* If the "no local" option was set, then remove the local node * from the list */ if (policy & ORTE_MAPPING_NO_USE_LOCAL) { /* we don't need to check through the entire list as * the head node - if it is on the list at all - will * always be in the first position */ item = opal_list_get_first(allocated_nodes); node = (orte_node_t*)item; /* need to check ifislocal because the name in the * hostfile may not have been FQDN, while name returned * by gethostname may have been (or vice versa) */ if (opal_ifislocal(node->name)) { opal_list_remove_item(allocated_nodes, item); OBJ_RELEASE(item); /* "un-retain" it */ } /** if we aren't mapping daemons, check that anything is left! */ if (NULL != app && 0 == opal_list_get_size(allocated_nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:nolocal-no-available-resources", true); return ORTE_ERR_SILENT; } } /* if the app is NULL, then we are mapping daemons - so remove * all nodes that already have a daemon on them * * NOTE: it is okay if the final list is empty. It just means * that there are no new daemons to be launched for the * virtual machine */ if (NULL == app) { item = opal_list_get_first(allocated_nodes); while (item != opal_list_get_end(allocated_nodes)) { /** save the next pointer in case we remove this node */ next = opal_list_get_next(item); /** already have a daemon? */ node = (orte_node_t*)item; if (NULL != node->daemon) { /* if this is the local node, keep it if requested */ if (node->daemon->name.vpid == ORTE_PROC_MY_HNP->vpid && !(policy & ORTE_MAPPING_NO_USE_LOCAL)) { item = next; continue; } opal_list_remove_item(allocated_nodes, item); OBJ_RELEASE(item); /* "un-retain" it */ } /** go on to next item */ item = next; } *total_num_slots = 0; return ORTE_SUCCESS; } /* remove all nodes that are already at max usage, and * compute the total number of allocated slots while * we do so */ num_slots = 0; item = opal_list_get_first(allocated_nodes); while (item != opal_list_get_end(allocated_nodes)) { /** save the next pointer in case we remove this node */ next = opal_list_get_next(item); /** check to see if this node is fully used - remove if so */ node = (orte_node_t*)item; if (0 != node->slots_max && node->slots_inuse > node->slots_max) { opal_list_remove_item(allocated_nodes, item); OBJ_RELEASE(item); /* "un-retain" it */ } else { /** otherwise, add the slots for our job to the total */ num_slots += node->slots_alloc; } /** go on to next item */ item = next; } /* Sanity check to make sure we have resources available */ if (0 == num_slots) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:all-available-resources-used", true); return ORTE_ERR_SILENT; } *total_num_slots = num_slots; return ORTE_SUCCESS; }
int orte_rmaps_base_filter_nodes(orte_app_context_t *app, opal_list_t *nodes, bool remove) { int rc=ORTE_ERR_TAKE_NEXT_OPTION; char *hosts; /* did the app_context contain a hostfile? */ if (orte_get_attribute(&app->attributes, ORTE_APP_HOSTFILE, (void**)&hosts, OPAL_STRING)) { /* yes - filter the node list through the file, removing * any nodes not found in the file */ if (ORTE_SUCCESS != (rc = orte_util_filter_hostfile_nodes(nodes, hosts, remove))) { ORTE_ERROR_LOG(rc); free(hosts); return rc; } /** check that anything is here */ if (0 == opal_list_get_size(nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, "-hostfile", hosts); free(hosts); return ORTE_ERR_SILENT; } free(hosts); } /* did the app_context contain an add-hostfile? */ if (orte_get_attribute(&app->attributes, ORTE_APP_ADD_HOSTFILE, (void**)&hosts, OPAL_STRING)) { /* yes - filter the node list through the file, removing * any nodes not found in the file */ if (ORTE_SUCCESS != (rc = orte_util_filter_hostfile_nodes(nodes, hosts, remove))) { free(hosts); ORTE_ERROR_LOG(rc); return rc; } /** check that anything is here */ if (0 == opal_list_get_size(nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, "-add-hostfile", hosts); free(hosts); return ORTE_ERR_SILENT; } free(hosts); } /* now filter the list through any -host specification */ if (!orte_soft_locations && orte_get_attribute(&app->attributes, ORTE_APP_DASH_HOST, (void**)&hosts, OPAL_STRING)) { if (ORTE_SUCCESS != (rc = orte_util_filter_dash_host_nodes(nodes, hosts, remove))) { ORTE_ERROR_LOG(rc); free(hosts); return rc; } /** check that anything is left! */ if (0 == opal_list_get_size(nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, "-host", hosts); free(hosts); return ORTE_ERR_SILENT; } free(hosts); } /* now filter the list through any add-host specification */ if (orte_get_attribute(&app->attributes, ORTE_APP_ADD_HOST, (void**)&hosts, OPAL_STRING)) { if (ORTE_SUCCESS != (rc = orte_util_filter_dash_host_nodes(nodes, hosts, remove))) { ORTE_ERROR_LOG(rc); free(hosts); return rc; } /** check that anything is left! */ if (0 == opal_list_get_size(nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, "-add-host", hosts); free(hosts); return ORTE_ERR_SILENT; } free(hosts); } return rc; }
int orte_rmaps_base_filter_nodes(orte_app_context_t *app, opal_list_t *nodes, bool remove) { int rc=ORTE_ERR_TAKE_NEXT_OPTION; /* did the app_context contain a hostfile? */ if (NULL != app->hostfile) { /* yes - filter the node list through the file, removing * any nodes not found in the file */ if (ORTE_SUCCESS != (rc = orte_util_filter_hostfile_nodes(nodes, app->hostfile, remove))) { ORTE_ERROR_LOG(rc); return rc; } /** check that anything is here */ if (0 == opal_list_get_size(nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, "-hostfile", app->hostfile); return ORTE_ERR_SILENT; } } /* did the app_context contain an add-hostfile? */ if (NULL != app->add_hostfile) { /* yes - filter the node list through the file, removing * any nodes not found in the file */ if (ORTE_SUCCESS != (rc = orte_util_filter_hostfile_nodes(nodes, app->add_hostfile, remove))) { ORTE_ERROR_LOG(rc); return rc; } /** check that anything is here */ if (0 == opal_list_get_size(nodes)) { orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, "-add-hostfile", app->hostfile); return ORTE_ERR_SILENT; } } /* now filter the list through any -host specification */ if (!orte_soft_locations && NULL != app->dash_host) { if (ORTE_SUCCESS != (rc = orte_util_filter_dash_host_nodes(nodes, app->dash_host, remove))) { ORTE_ERROR_LOG(rc); return rc; } /** check that anything is left! */ if (0 == opal_list_get_size(nodes)) { char *foo; foo = opal_argv_join(app->dash_host, ','); orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, "-host", foo); free(foo); return ORTE_ERR_SILENT; } } /* now filter the list through any add-host specification */ if (NULL != app->add_host) { if (ORTE_SUCCESS != (rc = orte_util_filter_dash_host_nodes(nodes, app->add_host, remove))) { ORTE_ERROR_LOG(rc); return rc; } /** check that anything is left! */ if (0 == opal_list_get_size(nodes)) { char *foo; foo = opal_argv_join(app->dash_host, ','); orte_show_help("help-orte-rmaps-base.txt", "orte-rmaps-base:no-mapped-node", true, app->app, "-add-host", foo); free(foo); return ORTE_ERR_SILENT; } } return rc; }