Skip to content

CustomizedManagers

fernanqv edited this page Jan 11, 2022 · 1 revision

How to create a custom manager

In case we want to modify the default template parameters for a specific manager, we will have to create a new python class that overload the jobTemplate method of the specific manager. For example, to create a new python script based on the default pbs manager, first, we will have to import all the classes and methods provided and then overload the jobTemplate method of the Job class. This new python script has to be located in a folder contained in the python path and has to be named different thant the default pbs manager (pbs.py).

The next example shows a custom PBS manager called pbs_custom.py:

from drm4g.managers.pbs import *

class Job(drm4g.managers.pbs.Job):
    def jobTemplate(self, parameters):
        
        # Dynamic directives
        args  = '#!/bin/bash\n'
        args += '#PBS -N SYNC_%s\n' % (parameters['environment']['GW_JOB_ID'])
        args += '#PBS -v %s\n' % (','.join(['%s=%s' %(k, v) for k, v in list(parameters['environment'].items())]))
        args += '#PBS -o $stdout\n'
        args += '#PBS -e $stderr\n'

        # Conditional directives
        if 'project' in parameters :
            args += '#PBS -P $project\n'
        if parameters['queue'] != 'default':
            args += '#PBS -q $queue\n'
        if 'maxWallTime' in parameters :
            args += '#PBS -l walltime=$maxWallTime\n'
        if 'maxCpuTime' in parameters :
            args += '#PBS -l cput=$maxCpuTime\n'
        if 'maxMemory' in parameters :
            args += '#PBS -l vmem=${maxMemory}MB\n'
        if 'ppn' in parameters and 'nodes' in parameters :
            args += '#PBS -l nodes=$nodes:ppn=$ppn\n'
        elif 'ppn' in parameters :
            node_count = int(parameters['count']) / int(parameters['ppn'])
            if node_count == 0:
                node_count = 1
            args += '#PBS -l nodes=%d:ppn=$ppn\n' % (node_count)
        else:
            args += '#PBS -l nodes=$count\n'

        # Static directives
        args += '#PBS -l mem=10G\n'

        # Wrapper content
        args += '$executable\n'
        return Template(args).safe_substitute(parameters)

In order to use this new manager for a resource, the parameter lrms of $DRM4G_DIR/etc/resources.conf has to be modified with the name of the new manager (without the .py extension). Do not forget to add the location of this manager to PYTHONPATH.

[RESOURCE]
enable           = true
communicator     = local
frontend         = My_pbs_cluster
lrms             = pbs_custom
......
Clone this wiki locally