Restricting a user to use only two nodes

How to restrict a user to use only 2 nodes if he submit job with 3 nodes then don run the job.
Please provide the command for that.

Thanks

You can use a queuejob hook to find out about the user qsub request and then accept or reject the job.
Get the number of cores requested, get the number of chunks requested, check the placement requested, based on these details and the cluster configuration you have, you can easily customise your hook.

Please use the below hook that will do the needful:

#qmgr -c ‘c h selcheck event=queuejob’
#qmgr -c ‘i h selcheck application/x-python default check_qsub_request.py’

#cat check_qsub_request.py

import pbs,os

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

LIST_OF_RESTRICTED_USERS=["user1" ,"user2" , "root"]
NUM_OF_NODES_ALLOWED_PER_JOB=2
username = str(e.requestor)


select_string = str(j.Resource_List['select'])
placement=str(j.Resource_List['place'])
pbs.logmsg(pbs.LOG_DEBUG, 'Select statement of this job is %s' % str(select_string))
pbs.logmsg(pbs.LOG_DEBUG, 'Placement requested for this job is %s' % str(j.Resource_List['place']))


if "+" in select_string:
    chunks=select_string.split('+')
    if len(chunks) >  NUM_OF_NODES_ALLOWED_PER_JOB and username in LIST_OF_RESTRICTED_USERS:
        pbs.logmsg(pbs.LOG_DEBUG, 'Number of  nodes requested for this job is %s' % str(len(chunks)))
        message = " %s nodes are requested for this job, %s restricted to 2 nodes per job" % (str(len(chunks)),username)
        e.reject(message)
else:
    chunks=int(select_string.split(':')[0])
    if  chunks > NUM_OF_NODES_ALLOWED_PER_JOB and placement=="scatter" and username in LIST_OF_RESTRICTED_USERS:
        pbs.logmsg(pbs.LOG_DEBUG, 'Number of  nodes requested for this job is %s' % str(chunks))
        message = " %s nodes are requested for this job, %s restricted to 2 nodes per job" % (str(chunks), username)
        e.reject(message)

updated to preserve the indentation of the source for user.