Skip to content
Snippets Groups Projects
Commit da43431f authored by Wouter Deconinck's avatar Wouter Deconinck
Browse files

fix: parallelize the single-thread checkGeometry

parent c5d0c847
Branches
Tags
1 merge request!521fix: parallelize the single-thread checkGeometry
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys
import yaml import yaml
import argparse import argparse
import subprocess
from datetime import datetime
DETECTOR_REPO_GROUP = 'https://github.com/eic' DETECTOR_REPO_GROUP = 'https://github.com/eic'
DETECTOR_BEAMLINE_ENV =''' DETECTOR_BEAMLINE_ENV ='''
...@@ -97,6 +100,7 @@ if __name__ == '__main__': ...@@ -97,6 +100,7 @@ if __name__ == '__main__':
default_found = True default_found = True
print(' - {}: {}{}'.format(det, branch, default_str)) print(' - {}: {}{}'.format(det, branch, default_str))
print(' --> Building and installing detector/ip libraries') print(' --> Building and installing detector/ip libraries')
process_list = []
for det in detectors: for det in detectors:
if not args.nightly and 'nightly' in detectors[det]: if not args.nightly and 'nightly' in detectors[det]:
del detectors[det]['nightly'] del detectors[det]['nightly']
...@@ -128,7 +132,7 @@ if __name__ == '__main__': ...@@ -128,7 +132,7 @@ if __name__ == '__main__':
'&&', '&&',
'cmake --build /tmp/build -j$(($(($(nproc)/4))+1)) -- install'] 'cmake --build /tmp/build -j$(($(($(nproc)/4))+1)) -- install']
print(' '.join(cmd)) print(' '.join(cmd))
os.system(' '.join(cmd)) subprocess.check_call(' '.join(cmd), shell=True)
## write version info to jug_info if available ## write version info to jug_info if available
if os.path.exists('/etc/jug_info'): if os.path.exists('/etc/jug_info'):
cmd = ['cd /tmp/det', cmd = ['cd /tmp/det',
...@@ -141,17 +145,17 @@ if __name__ == '__main__': ...@@ -141,17 +145,17 @@ if __name__ == '__main__':
'&&', '&&',
'cd -'] 'cd -']
print(' '.join(cmd)) print(' '.join(cmd))
os.system(' '.join(cmd)) subprocess.check_call(' '.join(cmd), shell=True)
## also copy over IP configuration to the detector ## also copy over IP configuration to the detector
if 'ip' in cfg and os.path.exists('/tmp/det/{ip}'.format(ip=cfg['ip']['config'])): if 'ip' in cfg and os.path.exists('/tmp/det/{ip}'.format(ip=cfg['ip']['config'])):
cmd = 'cp -r /tmp/det/{ip} {data_dir}'.format( cmd = 'cp -r /tmp/det/{ip} {data_dir}'.format(
ip=ip['config'], data_dir=data_dir) ip=ip['config'], data_dir=data_dir)
print(cmd) print(cmd)
os.system(cmd) subprocess.check_call(cmd, shell=True)
## cleanup ## cleanup
cmd = 'rm -rf /tmp/det /tmp/build' cmd = 'rm -rf /tmp/det /tmp/build'
print(cmd) print(cmd)
os.system(cmd) subprocess.check_call(cmd, shell=True)
# be resilient against failures # be resilient against failures
if os.path.exists(prefix): if os.path.exists(prefix):
## create a shortcut for the prefix if desired ## create a shortcut for the prefix if desired
...@@ -160,7 +164,7 @@ if __name__ == '__main__': ...@@ -160,7 +164,7 @@ if __name__ == '__main__':
prefix=prefix, prefix=prefix,
shortcut='{}/{}-{}'.format(args.prefix, det, branch)) shortcut='{}/{}-{}'.format(args.prefix, det, branch))
print(cmd) print(cmd)
os.system(cmd) subprocess.check_call(cmd, shell=True)
## write an environment file for this detector ## write an environment file for this detector
with open('{prefix}/setup.sh'.format(prefix=prefix), 'w') as f: with open('{prefix}/setup.sh'.format(prefix=prefix), 'w') as f:
if 'ip' in cfg: if 'ip' in cfg:
...@@ -183,15 +187,31 @@ if __name__ == '__main__': ...@@ -183,15 +187,31 @@ if __name__ == '__main__':
file=f) file=f)
## run once inside global prefix to initialize artifacts in /opt/detectors ## run once inside global prefix to initialize artifacts in /opt/detectors
os.environ['DETECTOR_PATH'] = args.prefix os.environ['DETECTOR_PATH'] = args.prefix
cmd = f'bash -c \'cd {args.prefix} && source {prefix}/setup.sh && checkGeometry -c {prefix}/share/{det}/{det}.xml\'' cmd = f'cd {args.prefix} && source {prefix}/setup.sh && checkGeometry -c {prefix}/share/{det}/{det}.xml'
print(cmd) print(cmd)
os.system(cmd) process_list.append(subprocess.Popen(cmd, shell=True, executable='/bin/bash', stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
## run once inside specific prefix to initialize artifacts in $DETECTOR_PATH ## run once inside specific prefix to initialize artifacts in $DETECTOR_PATH
os.environ['DETECTOR_PATH'] = args.prefix os.environ['DETECTOR_PATH'] = args.prefix
cmd = f'bash -c \'cd {prefix}/share/{det} && source {prefix}/setup.sh && checkGeometry -c {prefix}/share/{det}/{det}.xml\'' cmd = f'cd {prefix}/share/{det} && source {prefix}/setup.sh && checkGeometry -c {prefix}/share/{det}/{det}.xml'
print(cmd) print(cmd)
os.system(cmd) process_list.append(subprocess.Popen(cmd, shell=True, executable='/bin/bash', stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
while len(process_list) > 0:
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("{} processes running... ({})".format(len(process_list), current_time))
(out, err) = process_list[-1].communicate()
if process_list[-1].wait() != 0:
print(process_list[-1].args)
if out is not None:
print("stdout:")
print(out.decode())
if err is not None:
print("stderr:")
print(err.decode())
sys.exit(1)
process_list.pop()
if not default_found and not args.nightly: if not default_found and not args.nightly:
# Skip symlinking if no defaults present and its not a nightly build # Skip symlinking if no defaults present and its not a nightly build
pass pass
...@@ -204,6 +224,6 @@ if __name__ == '__main__': ...@@ -204,6 +224,6 @@ if __name__ == '__main__':
'&&', '&&',
'ln -sf {full_prefix}/setup.sh {short_prefix}'] 'ln -sf {full_prefix}/setup.sh {short_prefix}']
print(' '.join(cmd)) print(' '.join(cmd))
os.system(' '.join(cmd).format(full_prefix=full_prefix, short_prefix=args.prefix)) subprocess.check_call(' '.join(cmd).format(full_prefix=full_prefix, short_prefix=args.prefix), shell=True)
print('All done!') print('All done!')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment