import psutil


def get_num_procs(njobs:int)->int:
    """
    Small wrapper function used to get an integer number of cores, based on
    the user selection via njobs:
        
        - njobs = 0, set it to 1 core (serial)
        - njobs > 0, set it to njobs cores (parallel)
        - njobs < 0, set it to njobs * the number of physical cores as obtained by psutil.cpu_count
                    (This is useful for multi-socket setups, where psutil will only give the 
                    number of cores on a single socket)
    """
    
    if (njobs==0):
        njobs=1
    if (njobs<0):
        procs=psutil.cpu_count(logical=False)*abs(njobs)
    else:
        procs=njobs
    
    return procs