orte/util/nidmap.c
/* since not every node is involved in a job, we have to create a
 * regex that indicates the ppn for every node, marking those that
 * are not involved. Since each daemon knows the entire
 * node pool, we simply provide a ppn for every daemon, with a -1
 * to indicate that the node is empty for that job */
since not every node is involved in a job, we have to create a
regex that indicates the ppn for every node, marking those that
are not involved. Since each daemon knows the entire
node pool, we simply provide a ppn for every daemon, with a -1
to indicate that the node is empty for that job
since not every node is involved in a job we have to create a regex that indicates the ppn for every node marking those that are not involved . Since each daemon knows the entire node pool we simply provide a ppn for every daemon with a - 1 to indicate that the node is empty for that job
int orte_util_nidmap_generate_ppn(orte_job_t *jdata, char **ppn)
{
    orte_nidmap_regex_t *prng, **actives;
    opal_list_t *prk;
    orte_node_t *nptr;
    orte_proc_t *proc;
    size_t n;
    int *cnt, i, k;
    char *tmp2, *ptmp, **cache = NULL;
    prk = (opal_list_t*)malloc(jdata->num_apps * sizeof(opal_list_t));
    cnt = (int*)malloc(jdata->num_apps * sizeof(int));
    actives = (orte_nidmap_regex_t**)malloc(jdata->num_apps * sizeof(orte_nidmap_regex_t*));
    for (n=0; n < jdata->num_apps; n++) {
        OBJ_CONSTRUCT(&prk[n], opal_list_t);
        actives[n] = NULL;
    }
    for (i=0; i < orte_node_pool->size; i++) {
        if (NULL == (nptr = (orte_node_t*)opal_pointer_array_get_item(orte_node_pool, i))) {
            continue;
        }
        memset(cnt, 0, jdata->num_apps * sizeof(int));
        if (NULL != nptr->daemon) {
            for (k=0; k < nptr->procs->size; k++) {
                if (NULL != (proc = (orte_proc_t*)opal_pointer_array_get_item(nptr->procs, k))) {
                    if (proc->name.jobid == jdata->jobid) {
                        ++cnt[proc->app_idx];
                    }
                }
            }
        }
        for (n=0; n < jdata->num_apps; n++) {
            if (NULL == actives[n]) {
                actives[n] = OBJ_NEW(orte_nidmap_regex_t);
                actives[n]->nprocs = cnt[n];
                actives[n]->cnt = 1;
                opal_list_append(&prk[n], &actives[n]->super);
            } else {
                if (cnt[n] == actives[n]->nprocs) {
                    actives[n]->cnt++;
                } else {
                    actives[n] = OBJ_NEW(orte_nidmap_regex_t);
                    actives[n]->nprocs = cnt[n];
                    actives[n]->cnt = 1;
                    opal_list_append(&prk[n], &actives[n]->super);
                }
            }
        }
    }
    ptmp = NULL;
    for (n=0; n < jdata->num_apps; n++) {
        OPAL_LIST_FOREACH(prng, &prk[n], orte_nidmap_regex_t) {
            if (1 < prng->cnt) {
                if (NULL == ptmp) {
                    asprintf(&ptmp, "%u(%u)", prng->nprocs, prng->cnt);
                } else {
                    asprintf(&tmp2, "%s,%u(%u)", ptmp, prng->nprocs, prng->cnt);
                    free(ptmp);
                    ptmp = tmp2;
                }
            } else {
                if (NULL == ptmp) {
                    asprintf(&ptmp, "%u", prng->nprocs);
                } else {
                    asprintf(&tmp2, "%s,%u", ptmp, prng->nprocs);
                    free(ptmp);
                    ptmp = tmp2;
                }
            }
        }
        OPAL_LIST_DESTRUCT(&prk[n]);  
        if (NULL != ptmp) {
            opal_argv_append_nosize(&cache, ptmp);
            free(ptmp);
            ptmp = NULL;
        }
    }
    free(prk);
    free(cnt);
    free(actives);
    *ppn = opal_argv_join(cache, '@');
    opal_argv_free(cache);
    return ORTE_SUCCESS;
}
int orte_util_nidmap_generate_ppn ( orte_job_t * jdata , char * * ppn ) { orte_nidmap_regex_t * prng , * * actives ; opal_list_t * prk ; orte_node_t * nptr ; orte_proc_t * proc ; size_t n ; int * cnt , i , k ; char * tmp2 , * ptmp , * * cache = NULL ; prk = ( opal_list_t * ) malloc ( jdata -> num_apps * sizeof ( opal_list_t ) ) ; cnt = ( int * ) malloc ( jdata -> num_apps * sizeof ( int ) ) ; actives = ( orte_nidmap_regex_t * * ) malloc ( jdata -> num_apps * sizeof ( orte_nidmap_regex_t * ) ) ; for ( n = 0 ; n < jdata -> num_apps ; n ++ ) { OBJ_CONSTRUCT ( & prk [ n ] , opal_list_t ) ; actives [ n ] = NULL ; } for ( i = 0 ; i < orte_node_pool -> size ; i ++ ) { if ( NULL == ( nptr = ( orte_node_t * ) opal_pointer_array_get_item ( orte_node_pool , i ) ) ) { continue ; } memset ( cnt , 0 , jdata -> num_apps * sizeof ( int ) ) ; if ( NULL != nptr -> daemon ) { for ( k = 0 ; k < nptr -> procs -> size ; k ++ ) { if ( NULL != ( proc = ( orte_proc_t * ) opal_pointer_array_get_item ( nptr -> procs , k ) ) ) { if ( proc -> name . jobid == jdata -> jobid ) { ++ cnt [ proc -> app_idx ] ; } } } } for ( n = 0 ; n < jdata -> num_apps ; n ++ ) { if ( NULL == actives [ n ] ) { actives [ n ] = OBJ_NEW ( orte_nidmap_regex_t ) ; actives [ n ] -> nprocs = cnt [ n ] ; actives [ n ] -> cnt = 1 ; opal_list_append ( & prk [ n ] , & actives [ n ] -> super ) ; } else { if ( cnt [ n ] == actives [ n ] -> nprocs ) { actives [ n ] -> cnt ++ ; } else { actives [ n ] = OBJ_NEW ( orte_nidmap_regex_t ) ; actives [ n ] -> nprocs = cnt [ n ] ; actives [ n ] -> cnt = 1 ; opal_list_append ( & prk [ n ] , & actives [ n ] -> super ) ; } } } } ptmp = NULL ; for ( n = 0 ; n < jdata -> num_apps ; n ++ ) { OPAL_LIST_FOREACH ( prng , & prk [ n ] , orte_nidmap_regex_t ) { if ( 1 < prng -> cnt ) { if ( NULL == ptmp ) { asprintf ( & ptmp , " " , prng -> nprocs , prng -> cnt ) ; } else { asprintf ( & tmp2 , " " , ptmp , prng -> nprocs , prng -> cnt ) ; free ( ptmp ) ; ptmp = tmp2 ; } } else { if ( NULL == ptmp ) { asprintf ( & ptmp , " " , prng -> nprocs ) ; } else { asprintf ( & tmp2 , " " , ptmp , prng -> nprocs ) ; free ( ptmp ) ; ptmp = tmp2 ; } } } OPAL_LIST_DESTRUCT ( & prk [ n ] ) ; if ( NULL != ptmp ) { opal_argv_append_nosize ( & cache , ptmp ) ; free ( ptmp ) ; ptmp = NULL ; } } free ( prk ) ; free ( cnt ) ; free ( actives ) ; * ppn = opal_argv_join ( cache , ' ' ) ; opal_argv_free ( cache ) ; return ORTE_SUCCESS ; }
since not every node is involved in a job, we have to create a
 regex that indicates the ppn for every node, marking those that
 are not involved.
since not every node is involved in a job we have to create a regex that indicates the ppn for every node marking those that are not involved .
/* create an array of lists to handle the number of app_contexts in this job */ /* we provide a complete map in the regex, with an entry for every
     * node in the pool */ /* if a daemon has been assigned, then count how many procs
         * for each app_context from the specified job are assigned to this node */ /* track the #procs on this node */ /* just starting */ /* is this the next in line */ /* need to start another range */ /* construct the regex from the found ranges for each app_context */ // releases all the actives objects