Skip to content

make n_jobs=-1 as default instead of n_jobs=None? #111

@akshitasure12

Description

@akshitasure12

In tournament.is_reachable() under nx_parallel, the call to Parallel() does not explicitly pass the n_jobs parameter.

n_jobs = nxp.get_n_jobs()

return all(
	Parallel()(delayed(two_neighborhood_close)(G, chunk) for chunk in node_chunks)
)

By default, this will use n_jobs=None, which as per the joblib documentation, is interpreted as n_jobs=1 unless overridden by a parallel_config() context manager.

Expected Behavior :

n_jobs = nxp.get_n_jobs()

return all(
        Parallel(n_jobs=n_jobs)(delayed(two_neighborhood_close)(G, chunk) for chunk in node_chunks)
    )

Also, in the current implementation of get_n_jobs(), when n_jobs is not explicitly set (n_jobs=None), the following logic is used:

if n_jobs is None:
        if nx.config.backends.parallel.active:
            n_jobs = nx.config.backends.parallel.n_jobs
        else:
            from joblib.parallel import get_active_backend
            
            n_jobs = get_active_backend()[1]

    if n_jobs is None:
        return 1

Wouldn't it be more logical to automatically set n_jobs=-1 when get_active_backend()[1] gives none and nx.config.backends.parallel.active is false? Otherwise, the current behavior defaults n_jobs to 1, causing the task to run sequentially.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions