Skip to content

[Documentation] Explain how to access the executorlib_worker_id for debugging #749

Open

Description

@jan-janssen

The functionality was added in: #748

Basically, the worker ID is available as input parameter to your functions named executorlib_worker_id, so if you have a function like this:

def my_function(a, b, executorlib_worker_id): 
    ...

And you submit it to an executor like this:

exe.submit(my_function, a=1, b=2)

Then executorlib automatically sets the executorlib_worker_id input parameter at the point when the function is executed on the worker, in analogy to the init_function: https://executorlib.readthedocs.io/en/latest/1-single-node.html#performance-optimization

Activity

  1. jan-janssen commented on Aug 7, 2025

    @jan-janssen
    MemberAuthor

    Example from @mgt16-LANL :

    import os
    from concurrent.futures import as_completed
    from executorlib import SingleNodeExecutor
     
    def gpu_init_simple(executorlib_worker_id):
        import os
        cuda_inds = os.environ.get('CUDA_VISIBLE_DEVICES','1').split(',')
        sel_ind = int(executorlib_worker_id) % len(cuda_inds)
        cuda_ind = cuda_inds[sel_ind]
        print('Device is cuda init:' + cuda_ind)
        print('executorlib worker_id init: ', executorlib_worker_id)
        return {}
     
    def run_parallel(ind, executorlib_worker_id):
        print('Ind: ', ind, 'executorlib worker_id: ', executorlib_worker_id)
     
    with SingleNodeExecutor(max_workers=4, init_function=gpu_init_simple,
                            block_allocation=True) as exe:
        futs = []
        print('Starting')
        for ind in range(8):
            fut = exe.submit(run_parallel, ind)
            futs.append(fut)
        print('Submitted')
        count = 0
        for done in as_completed(futs):
            print('Done: ',count)
            count += 1
  2. jan-janssen commented on Feb 3, 2026

    @jan-janssen
    MemberAuthor

    This example nicely highlights how to oversubscribe GPUs, this should be mentioned in the FAQ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions