Skip to content

Commit 1bf0f2c

Browse files
committed
if --wait is passed into gufi_query_distributed, print output files
1 parent 8c3cd15 commit 1bf0f2c

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

scripts/gufi_query_distributed

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262

6363

64+
import sys
65+
6466
import gufi_common
6567
import gufi_distributed
6668

@@ -114,6 +116,8 @@ def schedule_top(args, jobids):
114116

115117
cmd = [args.sbatch, '--nodes=1']
116118
cmd += gufi_distributed.depend_on_slurm_jobids(jobids)
119+
if args.wait:
120+
cmd += ['--wait']
117121
cmd += [
118122
args.gufi_query,
119123
'-n', str(args.threads),
@@ -127,6 +131,14 @@ def parse_args():
127131
'Script for distributing gufi_query across nodes')
128132

129133
parser.add_argument('--dry-run', action='store_true')
134+
parser.add_argument('-W', '--wait',
135+
action='store_true',
136+
help='wait until all jobs complete and print results')
137+
parser.add_argument('--chunk-size',
138+
type=gufi_common.get_positive,
139+
default=4096,
140+
help='output file read chunk size')
141+
130142
parser.add_argument('--gufi_query', metavar='path',
131143
type=str,
132144
default='gufi_query.sbatch')
@@ -155,9 +167,18 @@ def main():
155167
lambda idx, start, end: schedule_work(args, idx, start, end),
156168
lambda jobids: schedule_top(args, jobids))
157169

158-
print('cat the following slurm job output files to get complete results:')
159-
for jobid in jobids:
160-
print(' {0}'.format(jobid))
170+
if args.wait:
171+
for jobid in jobids:
172+
with open('slurm-{0}.out'.format(jobid), 'r', encoding='utf-8') as f:
173+
while True:
174+
chunk = f.read(args.chunk_size)
175+
if not chunk:
176+
break
177+
sys.stdout.write(chunk)
178+
else:
179+
print('cat the following slurm job output files to get complete results:')
180+
for jobid in jobids:
181+
print(' {0}'.format(jobid))
161182

162183
if __name__ == '__main__':
163184
main()

test/regression/sbatch.no-output.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ case $key in
7676
--nodes|--dependency)
7777
shift # past count
7878
;;
79-
--nodes=*)
79+
--nodes=*|--wait)
8080
;;
8181
*) # unknown option
8282
POSITIONAL+=("$1") # save it in an array for later

test/regression/sbatch.output.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ case $key in
7676
--nodes|--dependency)
7777
shift # past count
7878
;;
79-
--nodes=*)
79+
--nodes=*|--wait)
8080
;;
8181
*) # unknown option
8282
POSITIONAL+=("$1") # save it in an array for later

0 commit comments

Comments
 (0)