Display selected load indices

By providing a list of load index names to an LSLIB function, you can get the load information about the specified load indices.

ls_loadinfo()

The following example shows how you can display the values of the external load indices. This program uses ls_loadinfo():

struct hostLoad *ls_loadinfo(resreq, numhosts, options,                             fromhost, hostlist, listsize,
                            namelist)

The parameters for this routine are:

char *resreq;              Resource requirement
int *numhosts;             Return parameter, number of hosts returned 
int options;               Host and load selection options 
char *fromhost;            Used only if DFT_FROMTYPE is set in options 
char **hostlist;           A list of candidate hosts for selection 
int listsize;              Number of hosts in hostlist 
char ***namelist;          Input/output parameter -- load index name list 

ls_loadinfo() is similar to ls_load() except that ls_loadinfo() allows an application to supply both a list of load indices and a list of candidate hosts. If both of namelist and hostlist are NULL, then it operates in the same way as ls_load() function.

The parameter namelist allows an application to specify a list of load indices of interest. The function then returns only the specified load indices. On return, this parameter is modified to point to another name list that contains the same set of load index names. This load index is in a different order to reflect the mapping of index names and the actual load values returned in the hostLoad array:

Example

#include <stdio.h>
#include <lsf/lsf.h>
/*include the header file with the getIndexList function here*/
main() 
{
    struct hostLoad *load;
    char **loadNames;
    int numIndx;
    int numUsrIndx;
    int nHosts;
    int i;
    int j;
    loadNames = getIndexList(&numIndx);
    if (loadNames == NULL) {
        ls_perror("Unable to get load index names\n");
        exit(-1);
    }
    numUsrIndx = numIndx - 11;  /* this is the total num of
                                site defined indices*/
    if (numUsrIndx == 0) {
        printf("No external load indices defined\n");
        exit(-1);
    }
    loadNames += 11;  /* skip the 11 built-in load index names */
    
    load = ls_loadinfo(NULL, &nHosts, 0, NULL, NULL, 0,                       &loadNames);
    if (load == NULL) {
        ls_perror("ls_loadinfo");
        exit(-1);
    }
    printf("Report on external load indices\n");
    for (i=0; i<nHosts; i++) {
        printf("Host %s:\n", load[i].hostName);
        for (j=0; j<numUsrIndx; j++) 
            printf("index name: %s, value %5.0f\n", 
                   loadNames[j], load[i].li[j]);
    }
}

The above program uses the getIndexList() function described in the previous example program to get a list of all available load index names. Sample output from the above program follows:

Report on external load indices
Host hostA:
        index name: usr_tmp, value 87 
        index name: num_licenses, value 1
Host hostD:
        index name: usr_tmp, value 18
        index name: num_licenses, value 2