Skip to content

Commit

Permalink
fix % display in libhpc
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo committed Mar 7, 2022
1 parent 850cf65 commit 57935c0
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/haddock/libs/libhpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,22 @@ def run(self):
"""Run tasks in the Queue."""
# split by maximum number of submission so we do it in batches
adaptive_l = []
total_completed = 0
batch = [
self.worker_list[i:i + self.queue_limit]
for i in range(0, len(self.worker_list), self.queue_limit)
]
total_batches = len(batch)
try:
for batch_num, job_list in enumerate(batch, start=1):
log.info(f"> Running batch {batch_num}/{len(batch)}")
for batch_num, worker_list in enumerate(batch, start=1):
log.info(f"> Running batch {batch_num}/{total_batches}")
start = time.time()
for worker in job_list:
for worker in worker_list:
worker.run()

# check if those finished
completed = False
while not completed:
for worker in job_list:
for worker in worker_list:
worker.update_status()
if worker.job_status != "finished":
log.info(
Expand All @@ -188,29 +188,24 @@ def run(self):
)

completed_count = sum(
w.job_status == "finished" for w in job_list
w.job_status == "finished" for w in worker_list
)

failed_count = sum(
w.job_status == "failed" for w in job_list
w.job_status == "failed" for w in worker_list
)

total_completed += completed_count + failed_count

per = float(total_completed) / len(self.worker_list) * 100

log.info(f">> {per:.2f}% done")
if completed_count + failed_count == len(job_list):
if completed_count + failed_count == len(worker_list):
completed = True
end = time.time()
elapsed = end - start
log.info(f'>> Took {elapsed:.2f}s')
adaptive_l.append(elapsed)
else:
if not adaptive_l:
# This is the first run, use pre-defined waits
if len(job_list) < 10:
if len(worker_list) < 10:
sleep_timer = 10
elif len(job_list) < 50:
elif len(worker_list) < 50:
sleep_timer = 30
else:
sleep_timer = 60
Expand All @@ -221,7 +216,11 @@ def run(self):
)
log.info(f">> Waiting... ({sleep_timer:.2f}s)")
time.sleep(sleep_timer)
log.info(f"> Batch {batch_num}/{len(batch)} done")

per = (float(batch_num) / float(total_batches)) * 100
log.info(
f">> Batch {batch_num}/{total_batches} took "
f"{elapsed:.2f}s to finish, {per:.2f}% complete")

except KeyboardInterrupt as err:
self.terminate()
Expand Down

0 comments on commit 57935c0

Please sign in to comment.