Dynamic shared resource information

Unlike host-based resources which are inherent properties contributing to the making of each host, shared resources are shared among a set of hosts. The availability of a shared resource is characterized by having multiple instances, with each instance being shared among a set of hosts.

ls_sharedresource-info()

ls_sharedresourceinfo() can be used to access shared resource information:

struct lsSharedResourceInfo *ls_sharedresourceinfo(resources, numResources, hostname, options)

On success, ls_sharedresourceinfo() returns an array containing a shared resource information structure (struct lsSharedResourceInfo) for each shared resource. On failure, ls_sharedresourceinfo() returns NULL and sets lserrno to indicate the error.

ls_sharedresourceinfo() has the following parameters:

char **resources;           NULL terminated array of resource names 
int *numresources;          Number of shared resources 
int hostName;               Host name 
int options;                Options (Currently set to 0) 
resources Parameter

resources is a list (NULL terminated array) of shared resource names whose resource information is to be returned. Specify NULL to return resource information for all shared resources defined in the cluster.

numresources Parameter

numresources is an integer specifying the number of resource information structures (LS_SHARED_RESOURCE_INFO_T) to return. Specify 0 to return resource information for all shared resources in the cluster. On success, numresources is assigned the number of LS_SHARED_RESOURCE_INFO_T structures returned.

hostName Parameter

hostName is the integer name of a host. Specifying hostName indicates that only the shared resource information for the named host is to be returned. Specify NULL to return resource information for all shared resources defined in the cluster.

options Parameter

options is reserved for future use. Currently, it should be set to 0.

lsSharedResource-Info structure

ls_sharedresourceinfo() returns an array of the following data structure as defined in <lsf/lsf.h> :

typedef struct lsSharedResourceInfo { 
    char  *resourceName;      Resource name 
    int   nInstances;         Number of instances 
    LS_SHARED_RESOURCE_INST_T *instances;  Pointer to the next instance 
} LS_SHARED_RESOURCE_INFO_T

For each shared resource, LS_SHARED_RESOURCE_INFO_T encapsulates an array of instances in the instances field. Each instance is represented by the data type LS_SHARED_RESOURCE_INST_T defined in <lsf/lsf.h>:

typedef struct lsSharedResourceInstance { 
    char  *value;             Value associated with the instance 
    int   nHosts;             Number of hosts sharing the instance 
    char  **hostList;         Hosts associated with the instance 
} LS_SHARED_RESOURCE_INST_T;

The value field of the LS_SHARED_RESOURCE_INST_T structure contains the ASCII representation of the actual value of the resource. The interpretation of the value requires the knowledge of the resource (Boolean, Numeric or String), which can be obtained from the resItem structure accessible through the lsLoad structure returned by ls_load().

Example

The following example shows how to use ls_sharedresourceinfo() to collect dynamic shared resource information in an LSF cluster. This example displays information from all the dynamic shared resources in the cluster. For each resource, the resource name, instance number, value and locations are displayed.

#include <stdio.h> 
#include <lsf/lsf.h> 
static struct resItem * getResourceDef(char *); 
static struct lsInfo  * lsInfo; 
 
void  
int main() 
{ 
    struct lsSharedResourceInfo *resLocInfo; 
    int numRes = 0; 
    int i, j, k; 
 
    lsInfo = ls_info(); 
    if (lsInfo == NULL) { 
        ls_perror("ls_info"); 
        exit(-1); 
    } 
 
    resLocInfo = ls_sharedresourceinfo (NULL, &numRes, NULL, 0); 
 
    if (resLocInfo == NULL) { 
        ls_perror("ls_sharedresourceinfo"); 
        exit(-1); 
    } 
 
    printf("%-11.11s %8.8s %6.6s %14.14s\n", "NAME", 
          "INSTANCE", "VALUE", "LOCATIONS"); 
 
    for (k = 0; k < numRes; k++) { 
        struct resItem *resDef; 
        resDef = getResourceDef(resLocInfo[k].resourceName); 
        if (! (resDef->flags & RESF_DYNAMIC))  
            continue; 
 
        printf("%-11.11s", resLocInfo[k].resourceName); 
        for (i = 0; i < resLocInfo[k].nInstances; i++) { 
            struct lsSharedResourceInstance *instance; 
 
            if (i == 0) 
                printf(" %8.1d", i+1); 
            else 
                printf(" %19.1d", i+1); 
 
            instance = &resLocInfo[k].instances[i]; 
            printf(" %6.6s", instance->value); 
 
            for (j = 0; j < instance->nHosts; j++)  
                if (j == 0) 
                   printf(" %14.14s\n", instance->hostList[j]); 
                else 
                   printf(" %41.41s\n", instance->hostList[j]); 
 
        } /* for */ 
    } /* for */ 
} /* main */
static struct resItem * 
getResourceDef(char *resourceName) 
{ 
    int i; 
 
    for (i = 0; i < lsInfo->nRes; i++) { 
        if (strcmp(resourceName, lsInfo->resTable[i].name) == 0)  
            return &lsInfo->resTable[i]; 
    } 
 
    /* Fail to find the matching resource */ 
    fprintf(stderr, "Cannot find resource definition for            <%s>\n", resourceName); 
 
    exit (-1); 
 
} 

The output of the above program is similar to the following:

% a.out 
NAME        INSTANCE  VALUE    LOCATIONS 
dynamic1        1       2        hostA 
                                 hostC 
                                 hostD 
                2       4        hostB 
                                 hostE 
dynamic2        1       3        hostA 
                                 hostE

The resource dynamic1 has two instances, one contains two resource units shared by hostA, hostC and hostD and the other contains four resource units shared by hostB and hostE. The dynamic2 resource has only one instance with three resource units shared by hostA and hostE.

For configuration of shared resources, see the ResourceMap section of lsf.cluster.cluster_name file in the Platform LSF Reference.