Package Biskit :: Module hosts
[hide private]
[frames] | no frames]

Source Code for Module Biskit.hosts

  1  ## List of available cluster nodes 
  2  ## Adapt this file and save it under biskit/Biskit/hosts.py ! 
  3  ## 
  4  ## last $Date: 2007/02/28 22:37:32 $ 
  5  ## last $Author: graik $ 
  6  """ 
  7  List of cluster computers. 
  8  Each host must be accessible via ssh w/o password:: 
  9   
 10    nodes_* .. lists with one entry per computer 
 11    cpus_*  .. lists with one entry per CPU (usually that's the one used) 
 12   
 13    nodes/cpus_own   .. computers reserved for own use, highest priority 
 14    nodes/cpus_shared.. computers shared with others, medium priority 
 15    nodes/cpus_other .. computers mainly used by others, lowest priority 
 16   
 17    nodes/cpus_all   .. all computers in descending priority 
 18    nice_dic         .. nice value for each host 
 19  """ 
 20  import Biskit.mathUtils as MU 
 21  import os 
 22  import string as S 
 23   
 24  import ConfigParser 
 25   
 26  ## Read configuration file 
 27  conf = ConfigParser.ConfigParser() 
 28  conf.read( os.path.expanduser('~/.biskit/hosts.dat' ) ) 
 29   
 30   
31 -def getHosts( section, option ):
32 """ 33 Get a list of hosts from the host list using ConfigParser. 34 35 @param section: ConfigParser section in ~/.biskit/hosts.dat 36 @type section: str 37 @param option: ConfigParser option in ~/.biskit/hosts.dat 38 @type option: str 39 40 @return: a list of hosts 41 @rtype: [str] 42 """ 43 ## Strip comment from setting (separator #) 44 ## Split list (separator 'space') 45 if conf.has_option( section, option ): 46 setting = conf.get( section, option ) 47 setting = S.split( setting, '#' ) 48 hosts = [] 49 for host in S.split( setting[0], ' ' ): 50 if len(host) != 0: 51 hosts += [ S.strip(host) ] 52 return hosts 53 return []
54 55
56 -def getDict( section, option ):
57 """ 58 Get a dictionary with host as key. 59 60 @param section: ConfigParser section in ~/.biskit/hosts.dat 61 @type section: str 62 @param option: ConfigParser option in ~/.biskit/hosts.dat 63 @type option: str 64 65 @return: a dictionary with host as key and (nice) value as value 66 @rtype: dict 67 """ 68 ## Strip comment from setting (separator: #) 69 ## Split entry (separator 'space') 70 ## Split value for dictionary (separator :) 71 dic = {} 72 for i in getHosts( section, option ): 73 i = S.split( i, ':' ) 74 dic[ S.strip(i[0]) ] = float( i[1] ) 75 return dic
76 77 78 dual = [] 79 80 ## 81 ## computers reserved for own use, highest priority 82 ## 83 __dual = getHosts( 'own_hosts', 'dual' ) # dual cpu computers reserved for own use, highest priority, separate with a blank space 84 __single = getHosts( 'own_hosts', 'single' ) # single cpu computers reserved for own use, highest priority, separate with space 85 86 nodes_own = __dual +__single 87 cpus_own = __dual * 2 + __single 88 89 dual += __dual 90 91 92 ## 93 ## computers shared with others, medium priority 94 ## 95 __dual = getHosts( 'shared_hosts', 'dual' ) # dual cpu computers shared with others, medium priority, separate with space 96 __single = getHosts( 'shared_hosts', 'single' ) # single cpu computers shared with others, medium priority, separate with space 97 98 dual += __dual 99 100 nodes_shared = __dual + __single 101 cpus_shared = __dual * 2 + __single 102 103 104 ## 105 ## computers mainly used by others, lowest priority 106 ## 107 __dual = getHosts( 'others_hosts', 'dual' ) # dual cpu computers mainly used by others, lowest priority, separate with space 108 __single = getHosts( 'others_hosts', 'single' ) # dual cpu computers mainly used by others, lowest priority, separate with space 109 110 dual += __dual 111 112 nodes_other = __dual + __single 113 cpus_other = __dual * 2 + __single 114 115 116 ## 117 ## all computers in descending priority 118 ## 119 nodes_all = nodes_own + nodes_shared + nodes_other 120 cpus_all = cpus_own + cpus_shared + cpus_other 121 122 123 ## 124 ## nice value for each computer 125 ## 126 nice_dic = { 'default':19 } 127 for h in nodes_own: 128 nice_dic[h] = 0 129 for h in cpus_shared: 130 nice_dic[h] = 0 131 for h in cpus_other: 132 nice_dic[h] = 17 133 134 ## 135 ## temporary fine tuning 136 ## 137 own_nice = getDict( 'own_hosts', 'nice' ) # nice value for own computers, default 0, separate hosts with space and values with ":" 138 shared_nice = getDict( 'shared_hosts', 'nice' ) # nice value shared computers, default 0, separate hosts with space and values with ":" 139 others_nice = getDict( 'others_hosts', 'nice' ) # nice value others computers, default 17, separate hosts with space and values with ":" 140 141 nice_dic.update(own_nice) 142 nice_dic.update(shared_nice) 143 nice_dic.update(others_nice) 144 145 146 ## 147 ## Memory available for each node, in GB 148 ## 149 own_ram = getDict( 'own_hosts', 'ram' ) # installed RAM for own computers in GB, default values 0.5 for single and 1 for dual, separate hosts with space and values with ":" 150 shared_ram = getDict( 'shared_hosts', 'ram' ) # installed RAM shared computers in GB, default values 0.5 for single and 1 for dual, separate hosts with space and values with ":" 151 others_ram = getDict( 'others_hosts', 'ram' ) # installed RAM others computers in GB, default values 0.5 for single and 1 for dual, separate hosts with space and values with ":" 152 153 ram_dic = { 'default':0.5 } 154 for h in dual: 155 ram_dic[ h ] = 1.0 156 157 ram_dic.update(own_ram) 158 ram_dic.update(shared_ram) 159 ram_dic.update(others_ram) 160 161 162 ## 163 ## exclude list, temporarily remove some nodes 164 ## 165 nodes_exclude = [] 166 nodes_exclude += getHosts( 'own_hosts', 'exclude' ) # exclude list, temporarily remove some nodes, separate with space 167 nodes_exclude += getHosts( 'shared_hosts', 'exclude' ) # exclude list, temporarily remove some nodes, separate with space 168 nodes_exclude += getHosts( 'others_hosts', 'exclude' ) # exclude list, temporarily remove some nodes, separate with space 169 170 171 ## 172 ## Switch On / Off temporary removal of nodes 173 ## Set to 1 to take some nodes out of the list (i.e. don't use them) 174 ## Set to 0 to let Biskit use all computers 175 ## 176 REMOVE = 1 177 178 if REMOVE: 179 for l in [ nodes_all, cpus_all, nodes_own, cpus_own, 180 nodes_shared, cpus_shared, nodes_other, cpus_other ]: 181 182 MU.removeFromList( l, nodes_exclude, all=1 ) 183 184 ############## 185 ## empty test 186 ############## 187 import Biskit.test as BT 188
189 -class Test(BT.BiskitTest):
190 """Mock test, hosts only contains data""" 191 pass
192