Skip to content

Available runtime processors is not really number of available processors #3963

@amsen20

Description

@amsen20

def availableProcessors(): Int = {

This function returns the number of available processors by reading from _SC_NPROCESSORS_ONLN, which utilizes get_nprocs(). The get_nprocs() function operates similarly to lscpu and does not indicate the number of processors a program can access.

Here is a code to show the difference:

#include <stdio.h>
#include <stdlib.h>
#include <sys/sysinfo.h>
#include <omp.h>

int main()
{
        printf("This system has %d processors configured and "
                        "%d processors available.\n",
                        get_nprocs_conf(), get_nprocs());

        printf("and in OMP: %d\n", omp_get_max_threads());
        exit(EXIT_SUCCESS);
}

The output for different numbers of available threads (using taskset) is as follows:

➜ g++ a.cpp -fopenmp
➜ taskset -c 0-0 ./a.out
This system has 8 processors configured and 8 processors available.
and in OMP: 1
➜ taskset -c 0-1 ./a.out
This system has 8 processors configured and 8 processors available.
and in OMP: 2
➜ taskset -c 0-4 ./a.out
This system has 8 processors configured and 8 processors available.
and in OMP: 5
➜ taskset -c 0-100 ./a.out
This system has 8 processors configured and 8 processors available.
and in OMP: 8

This may cause ambiguity in what available processors mean.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions