<br><font size=2 face="Arial">Nate,</font>
<br>
<br><font size=2 face="Arial">As a gigantic fan of pbs_python, we have
a library that wraps that interface for job_submission (etc) and here are
the funtions we use for constructing the attrl and attropls. I'm
sure Bas can give a better way to do this, but we use the pbs.new_attrl
function to create an attrl struct with as many slots as we need. Then
we plug in the name, resource, and stringed value to each of the empty
slots. Then we can just attach this to the job (for instance attropls
get added at submit job). This works for creating both attrls and
attropls, just pass the correct function pointer to make_attr_structs.
The pbs_call can safely be replaced with the actual function call,
we just route all of our actual Torque communication through a single channel
for managing connections/errors, etc.</font>
<br>
<br><font size=2 face="Arial">def make_attr_structs (attributes, constructor):</font>
<br><font size=2 face="Arial"> """Create an array
of structs (via the specified 'constructor') which encode</font>
<br><font size=2 face="Arial"> the specified 'attributes'."""</font>
<br>
<br><font size=2 face="Arial"> # Determine the number of structs
evinced by 'attributes'.</font>
<br><font size=2 face="Arial"> attr_count = len(attributes)</font>
<br><font size=2 face="Arial"> </font>
<br><font size=2 face="Arial"> #replace the below with something
like:</font>
<br><font size=2 face="Arial"> #constructor(attr_count)</font>
<br><font size=2 face="Arial"> attr = pbs_call(constructor,
attr_count)</font>
<br><font size=2 face="Arial"> index = 0</font>
<br>
<br><font size=2 face="Arial"> # Pack the struct array.</font>
<br><font size=2 face="Arial"> for pair in attributes.iteritems():</font>
<br><font size=2 face="Arial"> name, ds = pair</font>
<br>
<br><font size=2 face="Arial"> # If 'ds' is a dictionary,
then treat it as containing valued resources.</font>
<br><font size=2 face="Arial"> if type(ds) == types.DictType:</font>
<br><font size=2 face="Arial"> for resource_pair in
ds.iteritems():</font>
<br><font size=2 face="Arial"> resource, value
= resource_pair</font>
<br><font size=2 face="Arial"> attr[index].name
= name</font>
<br><font size=2 face="Arial"> attr[index].resource
= resource</font>
<br><font size=2 face="Arial"> attr[index].value
= str(value)</font>
<br><font size=2 face="Arial"> index
+= 1</font>
<br><font size=2 face="Arial"> </font>
<br><font size=2 face="Arial"> else:</font>
<br><font size=2 face="Arial"> # If 'ds' is a scalar
object, then wrap a list around it.</font>
<br><font size=2 face="Arial"> if type(ds) != types.ListType:</font>
<br><font size=2 face="Arial"> ds = [ ds ]</font>
<br>
<br><font size=2 face="Arial"> attr[index].name =
name</font>
<br><font size=2 face="Arial"> attr[index].value =
",".join(map(lambda x: str(x), ds))</font>
<br><font size=2 face="Arial"> index += 1</font>
<br>
<br><font size=2 face="Arial"> return attr</font>
<br>
<br><font size=2 face="Arial">def make_attrl (attributes):</font>
<br><font size=2 face="Arial"> """Obtain an array
of 'attrl' structs which encode the specified 'attributes'.</font>
<br><font size=2 face="Arial"> """</font>
<br>
<br><font size=2 face="Arial"> return make_attr_structs(attributes,
constructor = pbs.new_attrl)</font>
<br>
<br><font size=2 face="Arial">def make_attropl (attributes):</font>
<br><font size=2 face="Arial"> """Obtain an array
of 'attropl' structs which encode the specified</font>
<br><font size=2 face="Arial"> 'attributes'."""</font>
<br>
<br><font size=2 face="Arial"> return make_attr_structs(attributes,
constructor = pbs.new_attropl)</font>
<br>
<br><font size=2 face="Arial">Hope this helps. If not let me know.</font>
<br>
<br><font size=2 face="Arial">Best,</font>
<br><font size=2 face="Arial">Nate</font>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>"Nate Coraor"
<nate@psu.edu></b> </font>
<br><font size=1 face="sans-serif">Sent by: torqueusers-bounces@supercluster.org</font>
<p><font size=1 face="sans-serif">05-Sep-2006 13:42</font>
<td width=59%><font size=1 face="sans-serif">
</font>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td valign=top>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">[torqueusers] python pbs_submit</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2><tt>Hello,<br>
<br>
I'm using the pbs python module (from sara.nl) to submit jobs to <br>
torque. Everything works well except that I can't generate an attrl,
<br>
in order to pass job parameters to pbs_submit. The swig-generated
<br>
code is very hard to follow and there doesn't seem to be any <br>
documentation or examples of using an attrl. If anyone can provide
a <br>
tip on how to create this struct in python, I'd greatly appreciate it.<br>
<br>
Thanks,<br>
--nate<br>
_______________________________________________<br>
torqueusers mailing list<br>
torqueusers@supercluster.org<br>
http://www.supercluster.org/mailman/listinfo/torqueusers<br>
<br>
</tt></font>
<br>