The example of a job submission in the Platform LSF Programmer's Guide written in C (Page 64, LSF Version 7.0.6) would reflect to the following code in Python:
Code:
submitreq = lsf.submit()
submitreq.command = "/bin/sleep 1000"
submitreq.options = 0
submitreq.options2 = 0
limits = []
for i in range (0, lsf.LSF_RLIM_NLIMITS):
limits.append(lsf.DEFAULT_RLIMIT)
submitreq.rLimits = limits
submitreq.beginTime = 0
submitreq.termTime = 0
submitreq.numProcessors = 1
submitreq.maxNumProcessors = 1;
submitreply = lsf.submitReply()
print(lsf.lsb_init("test"))
print(lsf.lsb_submit(submitreq, submitreply))
The following lsf.i file was used for SWIG:
Code:
/* File: lsf.i */
%module lsf
%{
#define SWIG_FILE_WITH_INIT
#include "/opt/lsf/7.0/include/lsf/lsf.h"
#include "/opt/lsf/7.0/include/lsf/lsbatch.h"
%}
%ignore ls_placeoftype;
%ignore ls_loadoftype;
%ignore ls_lostconnection;
%ignore ls_gethostrespriority;
%ignore ls_verrlog;
%ignore getBEtime;
%ignore ls_nioinit;
%ignore ls_nioselect;
%ignore ls_nioctl;
%ignore ls_nionewtask;
%ignore ls_nioremovetask;
%ignore ls_niowrite;
%ignore ls_nioclose;
%ignore ls_nioread;
%ignore ls_niotasks;
%ignore ls_niostatus;
%ignore ls_niokill;
%ignore ls_niosetdebug;
%ignore ls_niodump;
%ignore ls_readrexlog;
// howto handle char **
%typemap(in) char ** {
int size = PyList_Size($input);
int i = 0;
$1 = (char **) malloc((size+1)*sizeof(char *));
for (i = 0; i < size; i++) {
PyObject *o = PyList_GetItem($input,i);
$1[i] = PyBytes_AsString(PyUnicode_AsUTF8String(PyList_GetItem($input,i)));
}
$1[i] = 0;
}
// cleanup of char **
%typemap(freearg) char ** {
free((char *) $1);
}
// typemap for time_t
%typemap(in) time_t {
$1 = (time_t) PyLong_AsLong($input);
}
%typemap(out) time_t {
$result = PyLong_FromLong((long)$1);
}
%typemap(freearg) time_t {
free((time_t *) $1);
}
// handle int arrays in struct...
%typemap(in) int [ANY] (int temp[$1_dim0]) {
int i;
for (i = 0; i < $1_dim0; i++) {
PyObject *o = PySequence_GetItem($input,i);
temp[i] = (int) PyInt_AsLong(o);
}
$1 = temp;
}
// allow to set members of int array
%typemap(memberin) int [ANY] {
int i;
for (i = 0; i < $1_dim0; i++) {
$1[i] = $input[i];
}
}
// access int arrays
%typemap(out) int [ANY] {
int i;
$result = PyList_New($1_dim0);
for (i = 0; i < $1_dim0; i++) {
PyObject *o = PyLong_FromDouble((int) $1[i]);
PyList_SetItem($result,i,o);
}
}
//
%include "/opt/lsf/7.0/include/lsf/lsf.h"
%include "/opt/lsf/7.0/include/lsf/lsbatch.h"