Example #1
0
def process_rsmas_cmd_line_parse(iargs=None):
    """ Creates command line argument parser object. """

    parser = argparse.ArgumentParser(description='Process Rsmas Routine InSAR Time Series Analysis',
                                     formatter_class=argparse.RawTextHelpFormatter,
                                     epilog=EXAMPLE)

    parser = putils.add_common_parser(parser)
    parser = putils.add_process_rsmas(parser)
    inps = parser.parse_args(args=iargs)
    inps = putils.create_or_update_template(inps)

    return inps
Example #2
0
def process_rsmas_cmd_line_parse(iargs=None):
    """ Creates command line argument parser object. """

    parser = argparse.ArgumentParser(
        description='Process Rsmas Routine InSAR Time Series Analysis',
        formatter_class=argparse.RawTextHelpFormatter,
        epilog=EXAMPLE)

    parser = putils.add_common_parser(parser)
    parser = putils.add_process_rsmas(parser)
    inps = parser.parse_args(args=iargs)
    template_file = pathObj.auto_template
    # print default template
    if inps.print_template:
        raise SystemExit(open(template_file, 'r').read())
    inps = putils.create_or_update_template(inps)

    return inps
def main(iargs=None):
    """
    summarize job durations
    """

    parser = argparse.ArgumentParser()
    parser = argparse.ArgumentParser(
        description='Utility to summarize job times and service units billed',
        formatter_class=argparse.RawTextHelpFormatter,
        epilog=EXAMPLE)
    parser.add_argument(
        'custom_template_file',
        metavar="FILE",
        default='None',
        nargs='?',
        help='template file to use [default: working directory]')
    parser.add_argument('--local',
                        dest='local_flag',
                        action='store_true',
                        default=False,
                        help='for current (local) directory')

    inps = parser.parse_args(args=iargs)

    try:
        inps = putils.create_or_update_template(inps)
        run_files_dir = inps.work_dir + '/run_files'
    except:
        cwd = os.getcwd()
        if 'run_files' in os.path.basename(cwd):
            inps.work_dir = os.path.dirname(cwd)
            inps.project_name = os.path.basename(inps.work_dir)
            run_files_dir = cwd
        else:
            inps.work_dir = cwd
            inps.project_name = os.path.basename(inps.work_dir)
            run_files_dir = cwd + '/run_files'

    run_stdout_files = glob.glob(
        run_files_dir + '/run_*_*_[0-9][0-9][0-9][0-9]*.o') + glob.glob(
            run_files_dir + '/*/run_*_*_[0-9][0-9][0-9][0-9]*.o')
    run_stdout_files = natsorted(run_stdout_files)

    #run_stdout_files2 = glob.glob(run_files_dir + '/stdout_run_*/run_*.o')
    #run_stdout_files2 = natsorted(run_stdout_files2)
    #run_stdout_files.extend(run_stdout_files2)

    if len(run_stdout_files) == 0:
        run_stdout_files = glob.glob(run_files_dir + '/stdout_run_*/run_*.o')
        run_stdout_files = natsorted(run_stdout_files)

    job_id_list = []

    bursts = glob.glob(inps.work_dir + '/geom_reference/*/hgt*rdr')
    number_of_bursts = len(bursts)

    if len(bursts) == 0:
        number_of_bursts = 1

    out_lines = []
    string = 'run_files_dir:  ' + run_files_dir
    print(string)
    out_lines.append(string)
    text = 'Number of bursts: ' + str(number_of_bursts)
    string = '{:32} {:1}'.format(
        text, "  NNodes  Timelimit   Reserved    Elapsed  Time_per_burst")
    print(string)
    out_lines.append(string)

    num_nodes_list = []
    wall_time_list = []
    reserved_time_list = []
    elapsed_time_list = []

    hostname = subprocess.Popen(
        "hostname -f", shell=True,
        stdout=subprocess.PIPE).stdout.read().decode("utf-8")

    scheduler = None
    for platform in ['frontera', 'stampede2', 'comet']:
        if platform in hostname:
            scheduler = 'SLURM'
            break
    if not scheduler == 'SLURM':
        print('Not on TACC system - return from summarize_job_run_times.py')
        return None

    for fname in run_stdout_files:
        job_id = os.path.basename(fname).split('.o')[0].split('_')[-1]

        command = 'sacct --format=NNodes,Timelimit,reserved,elapsed -j ' + job_id

        process = subprocess.Popen(command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   shell=True)
        stdout, stderr = process.communicate()
        try:
            out = stdout.splitlines()[2]
        except:
            continue
        num_nodes = out.decode('utf-8').split()[0]
        wall_time = out.decode('utf-8').split()[1]
        reserved_time = out.decode('utf-8').split()[2]
        elapsed_time = out.decode('utf-8').split()[3]

        time_per_burst = putils.multiply_walltime(elapsed_time,
                                                  factor=1 / number_of_bursts)

        string = '{:32} {:1}  {:1}'.format(
            '_'.join(os.path.basename(fname).split('_')[0:-1]),
            out.decode('utf-8'), time_per_burst)
        print(string)
        out_lines.append(string)

        num_nodes_list.append(num_nodes)
        wall_time_list.append(wall_time)
        reserved_time_list.append(reserved_time)
        elapsed_time_list.append(elapsed_time)

    reserved_time_sum = putils.sum_time(reserved_time_list)
    elapsed_time_sum = putils.sum_time(elapsed_time_list)
    total_time = putils.sum_time([reserved_time_sum, elapsed_time_sum])

    service_units = calculate_service_units(num_nodes_list, elapsed_time_list)

    if os.path.exists('run_files/rerun.log'):
        file = open('run_files/rerun.log', mode='r')
        rerun_log = file.read()
        print('\n' + rerun_log)
        out_lines.append('\n' + rerun_log)

    string = '\nTotal reserved (pending), elapsed time: ' + reserved_time_sum + ' ' + elapsed_time_sum
    print(string)
    out_lines.append(string)
    string = 'Total time:                             ' + total_time
    print(string)
    out_lines.append(string)
    string = 'Service units:                          ' + str(
        round(service_units, 1))
    print(string)
    out_lines.append(string)
    string = ' '
    print(string)
    out_lines.append(string)

    home_dir = os.getenv('HOME')
    save_job_run_times_summary(home_dir + '/job_summaries', out_lines,
                               inps.project_name)

    return None