-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhosts.h
76 lines (59 loc) · 2.12 KB
/
hosts.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
struct host_slots{
int shared;
int total;
int sixtyfour;
int thirtytwo;
int sixteen;
int less_than_two;
};
/* find shared and total slot usage, and return hosts memory availability information */
struct host_slots hosts(){
int j;
/* bhost related variables */
struct hostInfoEnt *hInfo;
char *hostname ;
int numHosts = 1;
struct hostInfo *lsHostInfo;
int free_range[4];
int TOTAL_SLOTS;
int SHARED_SLOTS;
int options = 0;
TOTAL_SLOTS = 0;
SHARED_SLOTS = 0;
free_range[0]=free_range[1]=free_range[2]=free_range[3] = 0;
/* bhost equivalent to get total of shared job slots */
/* see: https://wiki.med.harvard.edu/doc/lsf/api_ref/lsb_hostinfo.html */
hostname="shared_hosts";
hInfo = lsb_hostinfo(&hostname, &numHosts);
if (hInfo == NULL) {
lsb_perror("simbhosts: lsb_hostinfo() failed");
exit (-1);
}
printf("Total hosts from hosts() is %d\n", numHosts);
/* loop over hosts, exclude unavail state */
for(j = 0; j < numHosts; j++) {
/* too many possible states, probably missing case */
if ( (hInfo[j].hStatus & HOST_STAT_UNAVAIL) || (hInfo[j].hStatus & HOST_STAT_UNREACH) || (hInfo[j].hStatus & HOST_CLOSED_BY_ADMIN) ) {
//printf("%s host unavail or unreach or admin closed \n", hInfo[j].host );
}
else {
if ( (hInfo[j].hStatus & HOST_STAT_FULL) || hInfo[j].hStatus == 0 || hInfo[j].hStatus & HOST_STAT_BUSY || hInfo[j].hStatus & HOST_STAT_EXCLUSIVE ) {
SHARED_SLOTS = SHARED_SLOTS + hInfo[j].maxJobs;
/* free memory counts */
if ( hInfo[j].load[10] > 65536){
free_range[0]++;}
else if ( hInfo[j].load[10] > 32768){
free_range[1]++;}
else if ( hInfo[j].load[10] > 16384){
free_range[2]++;}
else if ( hInfo[j].load[10] < 2048){ /* No memory left */
free_range[3]++;}
} /* if is ok busy full or exclusive */
else {
// printf("%s host not ok busy full or exclusive \n", hInfo[j].host );
}
} /* if unreach or unavail */
}
struct host_slots retval = {SHARED_SLOTS,TOTAL_SLOTS,free_range[0],free_range[1],free_range[2],free_range[3]};
return retval;
}