1
1

Cleanup some of the loops in the nidmap code

This commit was SVN r21505.
Этот коммит содержится в:
Ralph Castain 2009-06-24 02:47:45 +00:00
родитель addaf7aaf8
Коммит 19062d70e4

Просмотреть файл

@ -288,22 +288,24 @@ int orte_util_build_daemon_nidmap(char **nodes)
int orte_util_encode_nodemap(opal_byte_object_t *boptr) int orte_util_encode_nodemap(opal_byte_object_t *boptr)
{ {
orte_vpid_t *vpids; orte_vpid_t *vpids;
orte_node_t **nodes; orte_node_t *node, *hnp;
int32_t i, num_nodes; int32_t i, num_nodes;
uint8_t num_digs; uint8_t num_digs;
int rc; int rc;
char *nodename; char *nodename;
opal_buffer_t buf; opal_buffer_t buf;
int32_t *arch; int32_t *arch;
char *ptr;
/* setup a buffer for tmp use */ /* setup a buffer for tmp use */
OBJ_CONSTRUCT(&buf, opal_buffer_t); OBJ_CONSTRUCT(&buf, opal_buffer_t);
/* determine the number of nodes in the global node array */ /* determine the number of nodes in the global node array */
num_nodes = 0; num_nodes = 0;
nodes = (orte_node_t**)orte_node_pool->addr; for (i=0; i < orte_node_pool->size; i++) {
while (num_nodes < orte_node_pool->size && if (NULL == opal_pointer_array_get_item(orte_node_pool, i)) {
NULL != nodes[num_nodes]) { continue;
}
++num_nodes; ++num_nodes;
} }
/* pack number of nodes */ /* pack number of nodes */
@ -315,12 +317,13 @@ int orte_util_encode_nodemap(opal_byte_object_t *boptr)
/* pack the HNP's node name - don't mess with /* pack the HNP's node name - don't mess with
* trying to encode it - it could be different * trying to encode it - it could be different
*/ */
/* the HNP always has an entry */
hnp = (orte_node_t*)opal_pointer_array_get_item(orte_node_pool, 0);
/* if we are not keeping FQDN hostnames, abbreviate /* if we are not keeping FQDN hostnames, abbreviate
* the nodename as required * the nodename as required
*/ */
if (!orte_keep_fqdn_hostnames) { if (!orte_keep_fqdn_hostnames) {
char *ptr; nodename = strdup(hnp->name);
nodename = strdup(nodes[0]->name);
if (NULL != (ptr = strchr(nodename, '.'))) { if (NULL != (ptr = strchr(nodename, '.'))) {
*ptr = '\0'; *ptr = '\0';
} }
@ -330,17 +333,19 @@ int orte_util_encode_nodemap(opal_byte_object_t *boptr)
} }
free(nodename); free(nodename);
} else { } else {
if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, &nodes[0]->name, 1, OPAL_STRING))) { if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, &hnp->name, 1, OPAL_STRING))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
return rc; return rc;
} }
} }
/* pack every nodename individually */ /* pack every nodename individually */
for (i=1; i < num_nodes; i++) { for (i=1; i < orte_node_pool->size; i++) {
if (!orte_keep_fqdn_hostnames) { if (!orte_keep_fqdn_hostnames) {
char *ptr; if (NULL == (node = (orte_node_t*)opal_pointer_array_get_item(orte_node_pool, i))) {
nodename = strdup(nodes[i]->name); continue;
}
nodename = strdup(node->name);
if (NULL != (ptr = strchr(nodename, '.'))) { if (NULL != (ptr = strchr(nodename, '.'))) {
*ptr = '\0'; *ptr = '\0';
} }
@ -350,7 +355,7 @@ int orte_util_encode_nodemap(opal_byte_object_t *boptr)
} }
free(nodename); free(nodename);
} else { } else {
if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, &nodes[i]->name, 1, OPAL_STRING))) { if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, &node->name, 1, OPAL_STRING))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
return rc; return rc;
} }
@ -370,13 +375,16 @@ int orte_util_encode_nodemap(opal_byte_object_t *boptr)
/* allocate space for the daemon vpids */ /* allocate space for the daemon vpids */
vpids = (orte_vpid_t*)malloc(num_nodes * sizeof(orte_vpid_t)); vpids = (orte_vpid_t*)malloc(num_nodes * sizeof(orte_vpid_t));
for (i=0; i < num_nodes; i++) { for (i=1; i < orte_node_pool->size; i++) {
if (NULL == nodes[i]->daemon) { if (NULL == (node = (orte_node_t*)opal_pointer_array_get_item(orte_node_pool, i))) {
continue;
}
if (NULL == node->daemon) {
/* some nodes may not have daemons on them */ /* some nodes may not have daemons on them */
vpids[i] = ORTE_VPID_INVALID; vpids[i] = ORTE_VPID_INVALID;
continue; continue;
} }
vpids[i] = nodes[i]->daemon->name.vpid; vpids[i] = node->daemon->name.vpid;
} }
if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, vpids, num_nodes, ORTE_VPID))) { if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, vpids, num_nodes, ORTE_VPID))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
@ -387,8 +395,11 @@ int orte_util_encode_nodemap(opal_byte_object_t *boptr)
if (OPAL_ENABLE_HETEROGENEOUS_SUPPORT) { if (OPAL_ENABLE_HETEROGENEOUS_SUPPORT) {
/* check to see if all reported archs are the same */ /* check to see if all reported archs are the same */
orte_homogeneous_nodes = true; orte_homogeneous_nodes = true;
for (i=1; i < num_nodes; i++) { for (i=1; i < orte_node_pool->size; i++) {
if (nodes[i]->arch != nodes[0]->arch) { if (NULL == (node = (orte_node_t*)opal_pointer_array_get_item(orte_node_pool, i))) {
continue;
}
if (node->arch != hnp->arch) {
orte_homogeneous_nodes = false; orte_homogeneous_nodes = false;
break; break;
} }
@ -414,8 +425,11 @@ int orte_util_encode_nodemap(opal_byte_object_t *boptr)
/* allocate space for the node arch */ /* allocate space for the node arch */
arch = (int32_t*)malloc(num_nodes * 4); arch = (int32_t*)malloc(num_nodes * 4);
/* transfer the data from the nodes */ /* transfer the data from the nodes */
for (i=0; i < num_nodes; i++) { for (i=0; i < orte_node_pool->size; i++) {
arch[i] = nodes[i]->arch; if (NULL == (node = (orte_node_t*)opal_pointer_array_get_item(orte_node_pool, i))) {
continue;
}
arch[i] = node->arch;
} }
/* pack the values */ /* pack the values */
if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, arch, num_nodes, OPAL_INT32))) { if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, arch, num_nodes, OPAL_INT32))) {
@ -480,7 +494,7 @@ int orte_util_decode_nodemap(opal_byte_object_t *bo)
orte_nid_t *node; orte_nid_t *node;
orte_vpid_t *vpids; orte_vpid_t *vpids;
uint8_t num_digs; uint8_t num_digs;
orte_nid_t **nd, *ndptr; orte_nid_t *nd, *ndptr;
int32_t *arch; int32_t *arch;
opal_buffer_t buf; opal_buffer_t buf;
opal_byte_object_t *boptr; opal_byte_object_t *boptr;
@ -496,9 +510,10 @@ int orte_util_decode_nodemap(opal_byte_object_t *bo)
* the memory pointed to by the elements in the array, so we need * the memory pointed to by the elements in the array, so we need
* to release those first * to release those first
*/ */
nd = (orte_nid_t**)orte_nidmap.addr; for (i=0; i < orte_nidmap.size; i++) {
for (i=0; i < orte_nidmap.size && NULL != nd[i]; i++) { if (NULL != (ndptr = (orte_nid_t*)opal_pointer_array_get_item(&orte_nidmap, i))) {
OBJ_RELEASE(nd[i]); OBJ_RELEASE(ndptr);
}
} }
/* now use the opal function to reset the internal pointers */ /* now use the opal function to reset the internal pointers */
opal_pointer_array_remove_all(&orte_nidmap); opal_pointer_array_remove_all(&orte_nidmap);
@ -566,11 +581,12 @@ int orte_util_decode_nodemap(opal_byte_object_t *bo)
* daemons in the system * daemons in the system
*/ */
num_daemons = 0; num_daemons = 0;
nd = (orte_nid_t**)orte_nidmap.addr;
for (i=0; i < num_nodes; i++) { for (i=0; i < num_nodes; i++) {
nd[i]->daemon = vpids[i]; if (NULL != (ndptr = (orte_nid_t*)opal_pointer_array_get_item(&orte_nidmap, i))) {
if (ORTE_VPID_INVALID != vpids[i]) { ndptr->daemon = vpids[i];
++num_daemons; if (ORTE_VPID_INVALID != vpids[i]) {
++num_daemons;
}
} }
} }
free(vpids); free(vpids);
@ -604,16 +620,16 @@ int orte_util_decode_nodemap(opal_byte_object_t *bo)
return rc; return rc;
} }
/* transfer the data to the nodes */ /* transfer the data to the nodes */
nd = (orte_nid_t**)orte_nidmap.addr;
for (i=0; i < num_nodes; i++) { for (i=0; i < num_nodes; i++) {
nd[i]->arch = arch[i]; if (NULL != (ndptr = (orte_nid_t*)opal_pointer_array_get_item(&orte_nidmap, i))) {
ndptr->arch = arch[i];
}
} }
free(arch); free(arch);
} }
/* unpack any attributes that may have been included */ /* unpack any attributes that may have been included */
n = 1; n = 1;
nd = (orte_nid_t**)orte_nidmap.addr;
while (ORTE_SUCCESS == opal_dss.unpack(&buf, &boptr, &n, OPAL_BYTE_OBJECT)) { while (ORTE_SUCCESS == opal_dss.unpack(&buf, &boptr, &n, OPAL_BYTE_OBJECT)) {
char *nodename, *attr, *tptr; char *nodename, *attr, *tptr;
opal_buffer_t bobuf; opal_buffer_t bobuf;
@ -629,7 +645,10 @@ int orte_util_decode_nodemap(opal_byte_object_t *bo)
return rc; return rc;
} }
/* find this node in nidmap */ /* find this node in nidmap */
for (i=0, ndptr=NULL; i < orte_nidmap.size && NULL != nd[i]; i++) { for (i=0, ndptr=NULL; i < orte_nidmap.size; i++) {
if (NULL == (nd = (orte_nid_t*)opal_pointer_array_get_item(&orte_nidmap, i))) {
continue;
}
/* since we may not have kept fqdn hostnames, we can only check /* since we may not have kept fqdn hostnames, we can only check
* for equality to the length of the name in the first field * for equality to the length of the name in the first field
* of an fqdn name * of an fqdn name
@ -638,8 +657,8 @@ int orte_util_decode_nodemap(opal_byte_object_t *bo)
if (NULL != tptr) { if (NULL != tptr) {
*tptr = '\0'; *tptr = '\0';
} }
if (0 == strncmp(nd[i]->name, nodename, strlen(nodename))) { if (0 == strncmp(nd->name, nodename, strlen(nodename))) {
ndptr = nd[i]; ndptr = nd;
break; break;
} }
} }
@ -676,17 +695,18 @@ int orte_util_decode_nodemap(opal_byte_object_t *bo)
} }
if (0 < opal_output_get_verbosity(orte_debug_output)) { if (0 < opal_output_get_verbosity(orte_debug_output)) {
nd = (orte_nid_t**)orte_nidmap.addr;
for (i=0; i < num_nodes; i++) { for (i=0; i < num_nodes; i++) {
opal_list_item_t *item; opal_list_item_t *item;
orte_attr_t *attr; orte_attr_t *attr;
if (NULL == (nd = (orte_nid_t*)opal_pointer_array_get_item(&orte_nidmap, i))) {
continue;
}
opal_output(0, "%s node[%d].name %s daemon %s arch %0x", opal_output(0, "%s node[%d].name %s daemon %s arch %0x",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), i, ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), i,
(NULL == nd[i]) ? "NULL" : nd[i]->name, (NULL == nd->name) ? "NULL" : nd->name,
ORTE_VPID_PRINT(nd[i]->daemon), ORTE_VPID_PRINT(nd->daemon), nd->arch);
(NULL == nd[i]) ? 0 : nd[i]->arch); for (item = opal_list_get_first(&nd->attrs);
for (item = opal_list_get_first(&nd[i]->attrs); item != opal_list_get_end(&nd->attrs);
item != opal_list_get_end(&nd[i]->attrs);
item = opal_list_get_next(item)) { item = opal_list_get_next(item)) {
attr = (orte_attr_t*)item; attr = (orte_attr_t*)item;
opal_output(0, "\tAttribute: %s #bytes: %d", attr->name, attr->size); opal_output(0, "\tAttribute: %s #bytes: %d", attr->name, attr->size);
@ -799,7 +819,7 @@ int orte_util_decode_pidmap(opal_byte_object_t *bo)
orte_node_rank_t *node_rank; orte_node_rank_t *node_rank;
orte_std_cntr_t n; orte_std_cntr_t n;
opal_buffer_t buf; opal_buffer_t buf;
orte_jmap_t **jobs, *jmap; orte_jmap_t *job, *jmap;
bool already_present; bool already_present;
int j; int j;
int rc; int rc;
@ -814,10 +834,6 @@ int orte_util_decode_pidmap(opal_byte_object_t *bo)
n = 1; n = 1;
/* cycle through the buffer */ /* cycle through the buffer */
while (ORTE_SUCCESS == (rc = opal_dss.unpack(&buf, &jobid, &n, ORTE_JOBID))) { while (ORTE_SUCCESS == (rc = opal_dss.unpack(&buf, &jobid, &n, ORTE_JOBID))) {
/* refresh the base address as it may have changed if we
* added a job to the array
*/
jobs = (orte_jmap_t**)orte_jobmap.addr;
/* unfortunately, job objects cannot be stored /* unfortunately, job objects cannot be stored
* by index number as the jobid is a constructed * by index number as the jobid is a constructed
* value. So we have no choice but to cycle through * value. So we have no choice but to cycle through
@ -827,10 +843,10 @@ int orte_util_decode_pidmap(opal_byte_object_t *bo)
*/ */
already_present = false; already_present = false;
for (j=0; j < orte_jobmap.size; j++) { for (j=0; j < orte_jobmap.size; j++) {
if (NULL == jobs[j]) { if (NULL == (job = (orte_jmap_t*)opal_pointer_array_get_item(&orte_jobmap, j))) {
continue; continue;
} }
if (jobid == jobs[j]->job) { if (jobid == job->job) {
already_present = true; already_present = true;
break; break;
} }