예제 #1
0
def run_task(arg):
    r"""
    Run *one* task.

    This is the only part that actually loads Sage.
    """
    typ, n, d, (i_start, i_stop) = arg

    import multiprocessing as mp
    import sage.all
    if typ == 'sv':
        from max_plus.sv_identities import sv_candidates as candidates
    elif typ == 'vv':
        from max_plus.vv_identities import vv_candidates as candidates
    else:
        raise ValueError("typ should either be sv or vv")

    return list(candidates(n, d, word_unrank(i_start,n), word_unrank(i_stop,n)))
예제 #2
0
def run_task(arg):
    typ, n, d, (i_start, i_stop), outdir, jobid = arg

    import sage.all
    if typ == 'sv':
        from max_plus.sv_identities import sv_candidates as candidates
    elif typ == 'vv':
        from max_plus.vv_identities import vv_candidates as candidates
    else:
        raise ValueError("typ should either be sv or vv")

    u_start = word_unrank(i_start, n)
    u_stop = word_unrank(i_stop, n)

    p = mp.current_process()
    s_start = word_nice_str(u_start)
    s_stop = word_nice_str(u_stop)
    filename = os.path.join(outdir, '{}-{}'.format(s_start, s_stop))
    if os.path.isfile(filename):
        f = open(filename)
        done = 'END' in f.read()
        f.close()
        if done:
            return

    f = open(filename, 'w')
    write_line(f, None)
    write_line(f, '{} candidates n={} d={}'.format(typ,n,d))
    write_line(f, 'u_start: {} ({})'.format(s_start, i_start))
    write_line(f, 'u_stop : {} ({})'.format(s_stop, i_stop))
    write_line(f, 'JOB_ID : {}'.format(jobid))
    write_line(f, 'NTASKS : {}'.format(nb_tasks))
    write_line(f, 'PROCID : {}'.format(i))
    write_line(f, p.name)
    write_line(f, None)
    for u in candidates(n, d, u_start, u_stop):
        f.write('{} {}\n'.format(word_nice_str(u[0]), word_nice_str(u[1])))
        f.flush()
    write_line(f, None)
    write_line(f, 'END')
    write_line(f, None)
    f.close()