************************************** Dynamically Control Consumed Resources ************************************** Problem ======= You want to dynamically change the consumed resources of the task. Solution ======== Use the task's :py:meth:`get_property` method with :py:obj:`JOB_SCHEDULER_CONTEXT ` input. You can call :py:meth:`yield_resource` to decrease the resources consumed by the task and :py:meth:`reserve_resource` to increase the resources consumed by the task. .. literalinclude:: ..\..\..\code\HowTos\ResourceManager.py :language: python :linenos: Discussion ========== Accurate resource tracking is important for efficiently using all available resources. A high degree of flexibility is allowed for more advanced cases where more control is needed for specifying which task is consuming which resource. Resource yielding comes in handy when a known task is not doing any real work and the system should consider its resources available to the system. The most common use case for this is when the task is waiting for work to be done. Resource reserving is much less common. Reserve a resource when more work is about to be done and the system should be notified. Resources also have a concept of *private* and *global* availability. A global resource is the most common and the default. Global resources are available to all tasks -- there are no restrictions. A private resource is a special kind of resource that restricts who can consume it, most commonly children of the task. Make a resource private by specifying :py:obj:`True` to the :py:attr:`restrict_to_children` parameter of :py:meth:`yield_resource`. Resources from private resources are consumed first before consuming global resources. The most common reason for using private resources over global resources is to ensure child tasks will have a pool of resources available only to them. That is, using private resources can guarantee that a child task will not have to wait in the queue because it does not have the necessary resources. .. note:: When a task submits a child job all of its resources are yielded by default. You will only have to yield resources if you choose to manually do so. See Also ======== Other Resources """"""""""""""" * :ref:`Control resources given to task` * :ref:`Submitting sub or child jobs`