-
Notifications
You must be signed in to change notification settings - Fork 1
/
argument_tools.py
99 lines (89 loc) · 2.72 KB
/
argument_tools.py
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
import numpy as np
import sys
import multiprocessing as mp
import getopt
def parse_arguments(sys_argv, subjects):
"""
argv = sys_argv[1:]
try:
opts, args = getopt.getopt(argv, "m:s:hb:e:", ["first=", "last="])
except getopt.GetoptError:
print('test.py -i <inputfile> -o <outputfile>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('test.py -b first -s last')
sys.exit()
elif opt in ("-b", "--first"):
start = arg
elif opt in ("-e", "--last"):
end = arg
if opt == '-m':
print(f'Max processes is set at {arg}')
max_processors =
if 'start' in locals():
del (start, end)
if 'start' in locals():
start = int(start)
if 'end' in locals():
subjects = subjects[int(start):int(end) + 1]
else:
subjects = subjects[start:]
if 'start' not in locals():
if 'end' not in locals():
subjects = subjects
else:
subjects = subjects[0:end]
"""
if np.size(sys_argv) > 1:
max_processors = int(sys_argv[1])
else:
max_processors = 1
if np.size(sys_argv) > 2:
subject_processes = int(sys_argv[2])
else:
subject_processes = np.size(subjects)
if mp.cpu_count() < max_processors:
max_processors = mp.cpu_count()
if max_processors < subject_processes:
subject_processes = max_processors
function_processes = np.int(max_processors / subject_processes)
return subject_processes, function_processes
def parse_arguments_function(sys_argv):
"""
argv = sys_argv[1:]
try:
opts, args = getopt.getopt(argv, "m:s:hb:e:", ["first=", "last="])
except getopt.GetoptError:
print('test.py -i <inputfile> -o <outputfile>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('test.py -b first -s last')
sys.exit()
elif opt in ("-b", "--first"):
start = arg
elif opt in ("-e", "--last"):
end = arg
if opt == '-m':
print(f'Max processes is set at {arg}')
max_processors =
if 'start' in locals():
del (start, end)
if 'start' in locals():
start = int(start)
if 'end' in locals():
subjects = subjects[int(start):int(end) + 1]
else:
subjects = subjects[start:]
if 'start' not in locals():
if 'end' not in locals():
subjects = subjects
else:
subjects = subjects[0:end]
"""
if np.size(sys_argv) > 1:
function_processes = int(sys_argv[1])
else:
function_processes = 1
return function_processes