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

Source Code for Module Biskit.default_hosts

  1  ## List of available cluster nodes 
  2  ## 
  3  ## Biskit, a toolkit for the manipulation of macromolecular structures 
  4  ## Copyright (C) 2004-2006 Raik Gruenberg & Johan Leckner 
  5  ## 
  6  ## This program is free software; you can redistribute it and/or 
  7  ## modify it under the terms of the GNU General Public License as 
  8  ## published by the Free Software Foundation; either version 2 of the 
  9  ## License, or any later version. 
 10  ## 
 11  ## This program is distributed in the hope that it will be useful, 
 12  ## but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 14  ## General Public License for more details. 
 15  ## 
 16  ## You find a copy of the GNU General Public License in the file 
 17  ## license.txt along with this program; if not, write to the Free 
 18  ## Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 19  ## 
 20  ## 
 21  ## Adapt this file and save it under biskit/Biskit/hosts.py ! 
 22  ## 
 23  ## last $Date: 2007/02/28 22:37:32 $ 
 24  ## last $Author: graik $ 
 25  ## $Revision: 2.5 $ 
 26   
 27  """ 
 28  List of cluster computers. 
 29   
 30  B{ Each host must be accessible via ssh w/o password. } 
 31   
 32  List and dictionaries describing avaliable hosts:: 
 33   
 34    nodes_* .. lists with one entry per computer 
 35    cpus_*  .. lists with one entry per CPU (usuallly that's the one used) 
 36   
 37    nodes/cpus_own   .. computers reserved for own use, highest priority 
 38    nodes/cpus_shared.. computers shared with others, medium priority 
 39    nodes/cpus_other .. computers mainly used by others, lowest priority 
 40   
 41    nodes/cpus_all   .. all computers in descending priority 
 42    nice_dic         .. nice value for each host 
 43  """ 
 44  import Biskit.mathUtils as MU 
 45  from tools import * 
 46  import os 
 47  import string 
 48   
 49  import ConfigParser 
 50   
 51  ## Read configuration file 
 52  conf = ConfigParser.ConfigParser() 
 53  conf.read( os.path.expanduser('~/.biskit/hosts.dat' ) ) 
 54   
 55   
56 -def getHosts( section, option ):
57 """ 58 Get host names from the config file hosts.dat specified bythe 59 section and option parameters. 60 61 @param section: ConfigParser section in ~/.biskit/hosts.dat 62 @type section: str 63 @param option: ConfigParser option in ~/.biskit/hosts.dat 64 @type option: str 65 66 @return: host name taken from hosts.dat or None 67 @rtype: str OR None 68 """ 69 if conf.has_option( section, option ): 70 setting = conf.get( section, option ) 71 ## Strip comment from setting (separator #) 72 setting = string.split( setting, '#' ) 73 hosts = [] 74 ## Split list (separator ,) 75 for host in string.split( setting[0], ' ' ): 76 hosts += [ string.strip( host ) ] 77 return hosts 78 return []
79 80
81 -def getDict( section, option ):
82 """ 83 Get host dictionaries from the config file hosts.dat specified by 84 the section and option parameters. The dictionary has the host as key 85 and the values can be availiable RAM or a nice value. 86 87 @param section: ConfigParser section in ~/.biskit/hosts.dat 88 @type section: str 89 @param option: ConfigParser option in ~/.biskit/hosts.dat 90 @type option: str 91 92 @return: dictionary with host:value 93 @rtype: dict 94 """ 95 dic = {} 96 ## Strip comment from setting (separator: #) 97 ## Split entry (separator ,) 98 for i in getHosts( section, option ): 99 ## Split dictionary (separator :) 100 if not len(i) == 0: 101 i = string.split( i, ':' ) 102 dic[ string.strip(i[0]) ] = float( i[1] ) 103 return dic
104 105 106 dual = [] 107 108 ## 109 ## computers reserved for own use, highest priority 110 ## 111 __dual = getHosts( 'own_hosts', 'dual' ) # dual cpu computers reserved for own use, highest priority, separate with a blank space 112 __single = getHosts( 'own_hosts', 'single' ) # single cpu computers reserved for own use, highest priority, separate with space 113 114 nodes_own = __dual +__single 115 cpus_own = __dual * 2 + __single 116 117 dual += __dual 118 119 120 ## 121 ## computers shared with others, medium priority 122 ## 123 __dual = getHosts( 'shared_hosts', 'dual' ) # dual cpu computers shared with others, medium priority, separate with space 124 __single = getHosts( 'shared_hosts', 'single' ) # single cpu computers shared with others, medium priority, separate with space 125 126 dual += __dual 127 128 nodes_shared = __dual + __single 129 cpus_shared = __dual * 2 + __single 130 131 132 ## 133 ## computers mainly used by others, lowest priority 134 ## 135 __dual = getHosts( 'others_hosts', 'dual' ) # dual cpu computers mainly used by others, lowest priority, separate with space 136 __single = getHosts( 'others_hosts', 'single' ) # dual cpu computers mainly used by others, lowest priority, separate with space 137 138 dual += __dual 139 140 nodes_other = __dual + __single 141 cpus_other = __dual * 2 + __single 142 143 144 ## 145 ## all computers in descending priority 146 ## 147 nodes_all = nodes_own + nodes_shared + nodes_other 148 cpus_all = cpus_own + cpus_shared + cpus_other 149 150 151 ## 152 ## nice value for each computer 153 ## 154 nice_dic = { 'default':19 } 155 for h in nodes_own: 156 nice_dic[h] = 0 157 for h in cpus_shared: 158 nice_dic[h] = 0 159 for h in cpus_other: 160 nice_dic[h] = 17 161 162 ## 163 ## temporary fine tuning 164 ## 165 own_nice = getDict( 'own_hosts', 'nice' ) # nice value for own computers, default 0, separate hosts with space and values with ":" 166 shared_nice = getDict( 'shared_hosts', 'nice' ) # nice value shared computers, default 0, separate hosts with space and values with ":" 167 others_nice = getDict( 'others_hosts', 'nice' ) # nice value others computers, default 17, separate hosts with space and values with ":" 168 169 nice_dic.update(own_nice) 170 nice_dic.update(shared_nice) 171 nice_dic.update(others_nice) 172 173 174 ## 175 ## Memory available for each node, in GB 176 ## 177 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 ":" 178 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 ":" 179 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 ":" 180 181 ram_dic = { 'default':0.5 } 182 for h in dual: 183 ram_dic[ h ] = 1.0 184 185 ram_dic.update(own_ram) 186 ram_dic.update(shared_ram) 187 ram_dic.update(others_ram) 188 189 190 ## 191 ## exclude list, temporarily remove some nodes 192 ## 193 nodes_exclude = [] 194 nodes_exclude += getHosts( 'own_hosts', 'exclude' ) # exclude list, temporarily remove some nodes, separate with space 195 nodes_exclude += getHosts( 'shared_hosts', 'exclude' ) # exclude list, temporarily remove some nodes, separate with space 196 nodes_exclude += getHosts( 'others_hosts', 'exclude' ) # exclude list, temporarily remove some nodes, separate with space 197 198 199 ## 200 ## Switch On / Off temporary removal of nodes 201 ## Set to 1 to take some nodes out of the list (i.e. don't use them) 202 ## Set to 0 to let Biskit use all computers 203 ## 204 REMOVE = 1 205 206 if REMOVE: 207 for l in [ nodes_all, cpus_all, nodes_own, cpus_own, 208 nodes_shared, cpus_shared, nodes_other, cpus_other ]: 209 210 MU.removeFromList( l, nodes_exclude, all=1 ) 211 212 ################ 213 ## empty test ## 214 215 import Biskit.test as BT 216
217 -class Test(BT.BiskitTest):
218 """Mock test, hosts only contains data""" 219 pass
220