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_sharedresourceinfo() can be used to access shared resource information:
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 namesint *numresources; Number of shared resourcesint hostName; Host nameint options; Options (Currently set to 0)
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 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 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 is reserved for future use. Currently, it should be set to 0.
ls_sharedresourceinfo() returns an array of the following data structure as defined in <lsf/lsf.h> :
typedef struct lsSharedResourceInfo {char *resourceName; Resource nameint nInstances; Number of instancesLS_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 instanceint nHosts; Number of hosts sharing the instancechar **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().
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;voidint 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);elseprintf(" %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]);elseprintf(" %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.outNAME INSTANCE VALUE LOCATIONSdynamic1 1 2 hostAhostChostD2 4 hostBhostEdynamic2 1 3 hostAhostE
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.