Skip to content

Commit d356184

Browse files
author
liubo
committed
add more examples for limit, load
1 parent df68da7 commit d356184

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

examples/disp_limit_all.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from pythonlsf import lsf
2+
3+
def printLimitItem(name, item):
4+
print(name+' :')
5+
print(' consumerC : {}'.format(item.consumerC))
6+
consumers = lsf.limitConsumerArray_frompointer(item.consumerV)
7+
for j in range (item.consumerC) :
8+
print(' [{}] type : {}'.format(j, consumers[j].type))
9+
print(' [{}] name : {}'.format(j, consumers[j].name))
10+
print(' resourceC : {}'.format(item.resourceC))
11+
resources = lsf.limitResourceArray_frompointer(item.resourceV)
12+
for j in range (item.resourceC) :
13+
print(' [{}] name : {}'.format(j, resources[j].name))
14+
print(' [{}] type : {}'.format(j, resources[j].type))
15+
print(' [{}] val : {}'.format(j, resources[j].val))
16+
17+
return 0
18+
19+
def printLimit():
20+
if lsf.lsb_init("test") > 0:
21+
return -1;
22+
23+
req = lsf.limitInfoReq()
24+
req.name = " ";
25+
pp_ents = lsf.calloc_limitInfoEntPtrPtr()
26+
intp_size = lsf.copy_intp(0)
27+
lsinfo = lsf.lsInfo()
28+
29+
rc = lsf.lsb_limitInfo(req, pp_ents, intp_size, lsinfo)
30+
if rc == -1 :
31+
print('call lsf failed')
32+
return -1;
33+
34+
ents = lsf.limitInfoEntPtrPtr_value(pp_ents)
35+
size = lsf.intp_value(intp_size)
36+
37+
print("{} limits in the cluster.".format(size))
38+
39+
for i in range(size) :
40+
ent = lsf.limitInfoEntArray_getitem(ents, i)
41+
# print limit name
42+
print('Limit No.{} : {}'.format(i, ent.name))
43+
44+
# print confInfo in the limit
45+
printLimitItem('confInfo', ent.confInfo)
46+
47+
# print usageC in the limit
48+
print('usageC : {}'.format(ent.usageC))
49+
# print usageInfo in the limit
50+
all_usageInfo = lsf.limitItemArray_frompointer(ent.usageInfo)
51+
for j in range (ent.usageC) :
52+
printLimitItem('usageInfo', all_usageInfo[j])
53+
54+
# print ineligible in the limit
55+
print('ineligible : {}\n\n'.format(ent.ineligible))
56+
57+
return 0
58+
59+
if __name__ == '__main__':
60+
print("LSF Clustername is : {}".format(lsf.ls_getclustername()))
61+
printLimit()
62+

examples/lsload.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from pythonlsf import lsf
2+
import ctypes
3+
4+
def printHostInfo():
5+
if lsf.lsb_init("test") > 0:
6+
return -1;
7+
8+
intp_nhosts = lsf.new_intp()
9+
lsf.intp_assign(intp_nhosts, 0)
10+
hostsdata = lsf.ls_load(None, intp_nhosts, 0, None)
11+
nhosts = lsf.intp_value(intp_nhosts)
12+
all_lsload_data = lsf.hostLoadArray_frompointer(hostsdata)
13+
14+
print("{} hosts in the cluster.".format(nhosts))
15+
16+
for i in range(nhosts) :
17+
host = all_lsload_data[i]
18+
hostname = ctypes.cast( host.hostName, ctypes.c_char_p)
19+
print('No.{} host name : {}'.format(i, hostname.value))
20+
21+
return 0
22+
23+
if __name__ == '__main__':
24+
print("LSF Clustername is : {}".format(lsf.ls_getclustername()))
25+
printHostInfo()
26+

pythonlsf/lsf.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ static void stringArray_setitem(char * *ary, size_t index, char * value) {
175175
%array_class(struct queueInfoEnt, queueInfoEntArray);
176176
%array_class(struct hostInfoEnt, hostInfoEntArray);
177177
%array_class(struct hostLoad, hostLoadArray);
178+
%array_class(struct _limitItem, limitItemArray)
179+
%array_class(struct _limitConsumer, limitConsumerArray)
180+
%array_class(struct _limitResource, limitResourceArray)
178181

179182
// handle int arrays
180183
%typemap(in) int [ANY] (int temp[$1_dim0]) {

0 commit comments

Comments
 (0)