Skip to content
Extraits de code Groupes Projets
generic.py 1,95 ko
Newer Older
  • Learn to ignore specific revisions
  • 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'
    
    
        LEMAITRE4: 766000,
        MANNEBACK: 257324,
        LUCIA: 245760,
        LUMI: 229376,
      },
    
        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