forked from gromacs/copernicus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcpc-worker
executable file
·174 lines (149 loc) · 5.16 KB
/
cpc-worker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
# This file is part of Copernicus
# http://www.copernicus-computing.org/
#
# Copyright (C) 2011, Sander Pronk, Iman Pouya, Erik Lindahl, and others.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# This is the main executable, from which all actions are launched.
import sys
import copy
import cpc.client
import cpc.network.server
import cpc.worker
import cpc.util
import cpc.util.log
from cpc.util import cmd_line_utils
from cpc.util.exception import ClientError
from cpc.util.conf.connection_bundle import ConnectionBundle
from cpc.util.version import __version__
def print_usage():
print "Usage: cpc-worker [global-opts] cpc-worker worker-type"
print ""
print " Global options are:"
print " -c conn-bundle: Specify connection bundle"
print " -p projectname: Only accept work from a named project."
print " -wd dirname: Worker scratch directory (instead of"
print " in the current working directory)."
print " -q minutes: Quit after specified number of minutes of"
print " no work."
print " -d: Debug mode."
print ""
print " Worker types include:"
print " smp: for single-host multiprocessor runs (default)"
print " mpi: for multiple-host MPI runs"
sys.exit(1)
# make a copy for later
args=copy.copy(sys.argv)
# remove the 0th argument
args.pop(0)
bundleFile=None
#opts to be passed to the worker
opts = {}
# workdir is None (to get it from the conf) or a value set with -wd
workdir=None
# quitMinutes is the number of minutes after which to quit if there is no work
# (set with -q)
quitMinutes=None
# sharedWorker is a flag to indicate if the worker shares the machine resources
# or if the resources are exclusive to the worker (sharedWorker=False)
sharedWorker=False
debug=False
# first parse common options
while len(args)>0:
if args[0][0]!='-':
break
elif args[0]=='-c':
option = args.pop(0)
if len(args) < 1:
sys.stderr.write(
"ERROR: no value specified for global option '%s'\n"%option)
print_usage()
bundleFile=args.pop(0)
elif args[0]=='-p':
option = args.pop(0)
if len(args) < 1:
sys.stderr.write(
"ERROR: no value specified for global option '%s'\n"%option)
print_usage()
opts['project']=args.pop(0)
elif args[0]=='-wd':
option = args.pop(0)
if len(args) < 1:
sys.stderr.write(
"ERROR: no value specified for global option '%s'\n"%option)
print_usage()
workdir=args.pop(0)
elif args[0]=='-q':
option = args.pop(0)
if len(args) < 1:
sys.stderr.write(
"ERROR: no value specified for global option '%s'\n"%option)
print_usage()
minutesString=args.pop(0)
try:
quitMinutes=float(minutesString)
except ValueError:
sys.stderr.write("'%s' is not a number."%minutesString)
elif args[0]=='-sh':
option = args.pop(0)
sharedWorker = True
elif args[0]=='-d':
args.pop(0)
debug=True
#can only handle the flag here and we do not want to completely rewrite the cmd line parsing logic at the moment
elif args[0]=='-h':
print_usage()
exit(0)
else:
sys.stderr.write("ERROR: no command or faulty global option '%s'\n"%
args[0])
print_usage()
# read in common configuration
def getArg(argnr, name):
try:
ret=args[argnr]
except IndexError:
raise ClientError("Missing argument: %s"%name)
return ret
#yes this command can be started without any command
cmd =""
if len(args)>0:
cmd=args[0]
cpc.util.log.initClientLog(debug)
try:
if cmd == "help":
cmd_line_utils.printLogo()
cmd_line_utils.printAuthors()
print_usage()
elif cmd == "version":
cmd_line_utils.printLogo()
cmd_line_utils.printAuthors()
print("Worker version: %s"%__version__)
else:
cf= cmd_line_utils.initiateConnectionBundle(bundleFile)
try:
type=getArg(0, "Worker type")
except:
type = "smp"
restargs=[]
for i in range(1, len(args)):
restargs.append(args[i])
worker=cpc.worker.Worker(cf, opts, type, restargs, workdir, quitMinutes, sharedWorker)
worker.run()
worker.cleanup()
except ClientError as e:
print("ERROR: %s"%e)
except cpc.util.CpcError as e:
print("ERROR: %s"%e)