FIgure out ncpus in queuejob hook

How can i get the ncpus allocated to a job within a hook, if the resources arent set and it goes to the queue defaults?

I know if the select statement is used I can get the ncpus from that:

e = pbs.event()
j = e.job
R = j.Resource_List

and the ncpus will be found in R["select"]

But is there a way to determine what the defaults are, or what the job gets assigned if a user just submits a job with no #PBS -l select= statement?

Thanks!

Please refer to this section Example 9-3: Reject jobs with CPU requests that are not multiples of 8
from this guide https://www.altair.com/pdfs/pbsworks/PBSHooks2021.1.pdf

Hi @adarsh - thanks for the suggestion.

The example doesn’t seem to return the defaults when set as a queuejob hook though.

The queue I am submitting to has the following settings:

    queue_type = Execution
    total_jobs = 0
    state_count = Transit:0 Queued:0 Held:0 Waiting:0 Running:0 Exiting:0 Begun
	:0 
    acl_host_enable = False
    from_route_only = False
    resources_max.walltime = 240:00:00
    resources_min.walltime = 00:00:00
    resources_default.ncpus = 1
    resources_default.walltime = 01:00:00
    default_chunk.ncpus = 1
    resources_assigned.mem = 0gb
    resources_assigned.mpiprocs = 0
    resources_assigned.ncpus = 0
    resources_assigned.nodect = 0
    hasnodes = True
    enabled = True
    started = True

If I submit a job with

qsub -q test_queue
Job script will be read from standard input. Submit with CTRL+D.
sleep 300

and don’t specify the nodes or the ncpus then in the queuejob hook pbs.event().job.Resource_List["ncpus"] is None

I suppose what I want to know is when are the defaults for ncpus and nodes set, and how do I access them from a queuejob hook?

Thanks!

Please try this.

import pbs,sys
s = pbs.server()
select_string = str(j.Resource_List['select'])
if str(j.Resource_List['select']) == 'None':
        default_ncpus = s.default_chunk['ncpus']
        select_string = "1:ncpus=%s" % default_ncpus
        j.Resource_List["select"] = pbs.select(select_string) 

Hope this helps

1 Like

Perfect @adarsh - exactly what i wanted

1 Like