Newer
Older
import math
import socket
import utilities.generic
#############
# variables #
#############
CORIOLIS = 'coriolis'
CYCLONE = 'cyclone'
LEMAITRE4 = 'lemaitre4'
MANNEBACK = 'manneback'
LUCIA = 'lucia'
LUMI = 'lumi'
KEY_MEMORY = 'memory'
KEY_NUMBER_OF_CORES = 'number_of_cores'
NODE_INFORMATION = {
KEY_MEMORY: {
LEMAITRE4: 766000,
MANNEBACK: 257324,
LUCIA: 245760,
LUMI: 229376,
},
KEY_NUMBER_OF_CORES: {
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
LEMAITRE4: 128,
MANNEBACK: 32,
LUCIA: 128,
LUMI: 128,
},
}
MEMORY_USED_PERCENTAGE = 0.95
#############
# functions #
#############
def get_machine_name():
'''
Get the name of the machine in use.
'''
machine = socket.gethostname()
if machine in ('lm4-f001', 'lm4-f002'):
machine = LEMAITRE4
elif machine in ('mbackf1.cism.ucl.ac.be', 'mbackf2.cism.ucl.ac.be'):
machine = MANNEBACK
elif machine[-17:] == '.lucia.cenaero.be':
machine = LUCIA
return machine
def get_node_information(what, machine):
'''
Obtain a given information about the nodes of a given machine.
'''
try:
value = NODE_INFORMATION[what][machine]
except KeyError:
raise utilities.generic.ClimateToolboxException(
'The %s for the nodes of "%s" is unknown.'%(what.replace('_', ' '), machine))
return value
def get_memory_with_margin(machine):
'''
Get the memory of nodes of a given machine, with a safety margin.
'''
memory = get_node_information(what=KEY_MEMORY, machine=machine)
memory_with_margin = math.floor(MEMORY_USED_PERCENTAGE * memory)
return memory_with_margin
def get_matching_number_of_cores(machine, memory):
'''
Get the number of cores that ensures that we use approximately the same fraction of cores and of
memory on the nodes of a given machine.
'''
memory_per_core = (get_node_information(what=KEY_MEMORY, machine=machine)
/ get_node_information(what=KEY_NUMBER_OF_CORES, machine=machine))
number_of_cores = math.ceil(memory / memory_per_core)
return number_of_cores