In the previous chapter, a very simple application was introduced that prints the name of the LSF cluster. This section extends that example by printing the current master host name and the defined resource names in the cluster. It uses the following additional LSLIB function calls:
All of these functions return NULL on failure and set lserrno to indicate the error.
The function ls_info() returns a pointer to the lsinfo data structure
struct lsInfo {int nRes; Number of resources in the systemstruct resItem *resTable; A resItem for each resource in the systemint nTypes; Number of host typeschar hostTypes[MAXTYPES][MAXLSFNAMELEN]; Host typesint nModels; Number of host modelschar hostModels[MAXMODELS][AXLSFNAMELEN]; Host modelschar hostArchs[MAXMODELS][MAXLSFNAMELEN]; Architecture nameint modelRefs[MAXMODELS]; Number of hosts of this architecturefloat cpuFactor[MAXMODELS]; CPU factors of each host modelint numIndx; Total number of load indices in resItemint numUsrIndix; Number of user-defined load indices};
Within struct lsinfo, the resItem data structure describes the valid resources defined in the LSF cluster:
struct resItem {char name[MAXLSFNAMELEN]; The name of the resourcechar des[MAXRESDESLEN]; The description of the resorceenum valueType valueType; Type of value: BOOLEAN, NUMERIC, STRING, EXTERNALenum orderType orderType; Order: INCR, DECR, NAint flags; Resource attribute flags#define RESF_BUILTIN 0x01 Built-in vs configured resource#define RESF_DYNAMIC 0x02 Dynamic vs static value#define RESF_GLOBAL 0x04 Resource defined in all clusters#define RESF_SHARED 0x08 Shared resource for some hosts#define RESF_LIC 0x10 License static value#define RESF_EXTERNAL 0x20 External resource defined#define RESF_RELEASE 0x40 Resource can be released when job issuspendedint interval; The update interval for a load index, in seconds};
The constants MAXTYPES, MAXMODELS, and MAXLSFNAMELEN are defined in <lsf/lsf.h>. MAXLSFNAMELEN is the maximum length of a name in LSF.
A host type in LSF refers to a class of hosts that are considered to be compatible from an application point of view. This is entirely configurable, although normally hosts with the same architecture (binary compatible hosts) should be configured to have the same host type.
A host model in LSF refers to a class of hosts with the same CPU performance. The CPU factor of a host model should be configured to reflect the CPU speed of the model relative to other host models in the LSF cluster.
ls_getmastername() returns a string containing the name of the current master host.
ls_getclustername() returns a string containing the name of the local load sharing cluster defined in the configuration files.
The returned data structure of every LSLIB function is dynamically allocated inside LSLIB. This storage space is automatically freed by LSLIB and re-allocated next time the same LSLIB function is called. An application should never attempt to free the storage returned by LSLIB. If you need to keep this information across calls, make your own copy of the data structure. This applies to all LSLIB function calls.
The following program displays LSF cluster information using the above LSLIB function calls.
#include <stdio.h>#include <lsf/lsf.h>main(){struct lsInfo *lsInfo;char *cluster, *master;int i;/* get the name of the local load sharing cluster */cluster = ls_getclustername();if (cluster == NULL) {ls_perror("ls_getclustername");exit(‑1);}printf("My cluster name is <%s>\n", cluster);/* get the name of the current master host */master = ls_getmastername();if (master == NULL) {ls_perror("ls_getmastername");exit(‑1);}printf("Master host is <%s>\n", master);/* get the load sharing configuration information */lsInfo = ls_info();if (lsInfo == NULL) {ls_perror("ls_info");exit(‑1);}printf("\n%‑15.15s %s\n", "RESOURCE_NAME", "DESCRIPTION");for (i=0; i<lsInfo‑>nRes; i++)printf("%‑15.15s %s\n",lsInfo‑>resTable[i].name, lsInfo‑>resTable[i].des);exit(0);}
The above program will produce output similar to the following:
% a.outMy cluster name is <test_cluster>Master host is <hostA>RESOURCE_NAME DESCRIPTIONr15s 15‑second CPU run queue lengthr1m 1‑minute CPU run queue length (alias: cpu)r15m 15‑minute CPU run queue lengthut 1‑minute CPU utilization (0.0 to 1.0)pg Paging rate (pages/second)io Disk IO rate (Kbytes/second)ls Number of login sessions (alias: login)it Idle time (minutes) (alias: idle)tmp Disk space in /tmp (Mbytes)swp Available swap space (Mbytes) (alias: swap)mem Available memory (Mbytes)ncpus Number of CPUsndisks Number of local disksmaxmem Maximum memory (Mbytes)maxswp Maximum swap space (Mbytes)maxtmp Maximum /tmp space (Mbytes)cpuf CPU factorrexpri Remote execution priorityserver LSF server hostLSF_Base Base productlsf_base Base productLSF_Manager Standard productlsf_manager Standard productLSF_JobSchedule JobScheduler productlsf_js JobScheduler productLSF_Make Make productlsf_make Make productLSF_Parallel Parallel productlsf_parallel Parallel productLSF_Analyzer Analyzer productlsf_analyzer Analyzer productmips MIPS architecturedec DECStation systemsparc SUN SPARCbsd BSD unixsysv System V UNIXhpux HP-UX UNIXaix AIX UNIXirix IRIX UNIXultrix Ultrix UNIXsolaris SUN SOLARISsun41 SunOS4.1convex ConvexOSosf1 OSF/1fs File servercs Compute serverframe Hosts with FrameMaker licensebigmem Hosts with very big memorydiskless Diskless hostsalpha DEC alphalinux LINUX UNIXtype Host typemodel Host modelstatus Host statushname Host name