Skip to content

Commit

Permalink
Better handling of aborts in parallel runs
Browse files Browse the repository at this point in the history
  • Loading branch information
geojunky committed Oct 4, 2024
1 parent 9a22759 commit 39b7588
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion seismic/bulk_station_orientations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
from shutil import rmtree
from seismic.misc_p import parallel_abort

logging.basicConfig()

Expand Down Expand Up @@ -212,7 +213,11 @@ def main(src_h5_event_file, network, output_basename, station_list, dump_swp_dat
proc_hdfkeys = list(proc_hdfkeys)

# trim stations to be processed based on the user-provided network- and station-list
proc_hdfkeys = rf_util.trim_hdf_keys(proc_hdfkeys, network, station_list)
try:
proc_hdfkeys = rf_util.trim_hdf_keys(proc_hdfkeys, network, station_list)
except Exception as e:
parallel_abort(str(e), logger)
# end try

# split work-load over all procs
proc_hdfkeys = split_list(proc_hdfkeys, nproc)
Expand Down
9 changes: 9 additions & 0 deletions seismic/misc_p.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
from mpi4py import MPI
from logging import Logger

class ProgressTracker:
def __init__(self, output_folder, restart_mode=False):
Expand Down Expand Up @@ -51,3 +52,11 @@ def increment(self):
# end func
# end class

def parallel_abort(msg: str, logger:Logger=None):
comm = MPI.COMM_WORLD
nproc = comm.Get_size()
rank = comm.Get_rank()

if(logger is not None): logger.error('Aborting job from rank {}: {}'.format(rank, msg))
comm.Abort()
# end func

0 comments on commit 39b7588

Please sign in to comment.