def main():
    implementation = "bulksubmit"
    start_time = time.perf_counter()
    args = setup_parser().parse_args()
    # open connection to broker
    h = flux.Flux()
    # create jobspec for sleep command
    compute_jobspec = job.JobspecV1.from_command(command=["true"],
                                                 num_tasks=1,
                                                 num_nodes=1,
                                                 cores_per_task=1)
    compute_jobspec.cwd = os.getcwd()
    done = 0
    for _ in range(args.jobcount):
        job.submit_async(h, compute_jobspec, waitable=True).then(submit_cb)
    if h.reactor_run(h.get_reactor(), 0) < 0:
        h.fatal_error("reactor start failed")
    while done < args.jobcount:
        jobid, success, errstr = job.wait(h)
        if not success:
            print("wait: {} Error: {}".format(jobid, errstr))
        done += 1
    total_time = time.perf_counter() - start_time
    print("Total seconds: {}".format(total_time))
    utils.save_timing_data(args.jobcount, total_time, implementation)
Beispiel #2
0
    def submit_async(self, args, jobspec=None):
        """
        Submit job, constructing jobspec from args unless jobspec is not None.
        Returns a SubmitFuture.
        """
        if jobspec is None:
            jobspec = self.jobspec_create(args)

        if args.dry_run:
            print(jobspec.dumps(), file=sys.stdout)
            sys.exit(0)

        arg_debug = False
        arg_waitable = False
        if args.flags is not None:
            for tmp in args.flags:
                for flag in tmp.split(","):
                    if flag == "debug":
                        arg_debug = True
                    elif flag == "waitable":
                        arg_waitable = True
                    else:
                        raise ValueError("--flags: Unknown flag " + flag)

        if not self.flux_handle:
            self.flux_handle = flux.Flux()

        if args.urgency == "default":
            urgency = flux.constants.FLUX_JOB_URGENCY_DEFAULT
        elif args.urgency == "hold":
            urgency = flux.constants.FLUX_JOB_URGENCY_HOLD
        elif args.urgency == "expedite":
            urgency = flux.constants.FLUX_JOB_URGENCY_EXPEDITE
        else:
            urgency = int(args.urgency)

        return job.submit_async(
            self.flux_handle,
            jobspec.dumps(),
            urgency=urgency,
            waitable=arg_waitable,
            debug=arg_debug,
        )
Beispiel #3
0
import sys

if len(sys.argv) != 2:
    njobs = 100
else:
    njobs = int(sys.argv[1])

attrs = ["state", "name", "t_submit"]
jobspec = job.JobspecV1.from_command(["sleep", "0"],
                                     num_tasks=1,
                                     cores_per_task=1)


def list_cb(f, arg):
    print(f.get())


def submit_cb(f, arg):
    jobid = job.submit_get_id(f)
    h.rpc("job-info.list-id", dict(id=jobid, attrs=attrs)).then(list_cb)


h = flux.Flux()
for i in range(njobs):
    job.submit_async(h, jobspec).then(submit_cb)

if h.reactor_run() < 0:
    h.fatal_error("reactor_run failed")

# vim: tabstop=4 shiftwidth=4 expandtab
Beispiel #4
0
 def submit_async(self, args):
     spec = self.jobspec.dumps()
     for _ in range(args.njobs):
         job.submit_async(self.handle, spec).then(self.submit_cb, args)
    bar = "\u2588" * fill + "-" * (length - fill)
    s = "\r|{0}| {1:.1f}% {2}".format(bar, 100 * fraction, suffix)
    sys.stdout.write(s)
    if fraction == 1.0:
        sys.stdout.write("\n")


def submit_cb(f):
    jobs.append(job.submit_get_id(f))


# asynchronously submit jobspec files from a directory
log("Starting...")
for file in sys.argv[1:]:
    with open(file) as jobspec:
        job.submit_async(h, jobspec.read(), waitable=True).then(submit_cb)

if h.reactor_run() < 0:
    h.fatal_error("reactor start failed")

total = len(jobs)
dt = time.time() - t0
jps = len(jobs) / dt
log("submitted {0} jobs in {1:.2f}s. {2:.2f}job/s".format(total, dt, jps))

count = 0
while count < total:
    # wait for jobs to complete in any order
    job.wait(h)
    count = count + 1
    if count == 1: