Example #1
0
def memprint(priority, msg):
    """ 
    Make print only work when RANK == 0, 
    avoiding repeated printing of statements.
    """
    if (RANK == 0) and (priority <= VERBOSE_MEM):
        tot_mem = bytes2human(vmem()[0])
        av_mem = bytes2human(vmem()[3])
        print('  ' * priority + msg + ': ' + av_mem + ' / ' + tot_mem)
Example #2
0
def mpiprint(priority, msg):
    """ 
    Make print only work when RANK == 0, 
    avoiding repeated printing of statements.
    """
    if (RANK == 0) and (priority <= VERBOSE_MEM):
        tot_mem = bytes2human(vmem()[0])
        av_mem = bytes2human(vmem()[3])
        try:
            msg += ': ' + av_mem + ' / ' + tot_mem
        except:
            pass
    if (RANK == 0) and (priority <= VERBOSE):
        try:
            print('  ' * priority + msg)
        except:
            print(msg)
Example #3
0
#!/usr/bin/env python3
# compute free memory
from psutil import virtual_memory as vmem

meg = 1000000
gig = 1000000000

mem = vmem()
total = mem.total
free = mem.free
used = mem.used

if free / gig < 1:
    denom = 'MB_FREE'
    denom_free = free / meg
else:
    denom = 'GB_FREE'
    denom_free = free / gig


def to_percent(total, free):
    '''Return percent of memory in free'''
    return free / total * 100


print(
    f'TOTAL: {total/gig:.2f}GB {denom}: {denom_free:.2f} %FREE: {to_percent(total,free):.0f}%'
)