Sample Flux Script

Below is the example.flux script file:

#!/bin/sh
#Submit using flux batch <filename>

#flux: --job-name=EXAMPLE
#flux: --output='EXAMPLE.{{id}}.out'
#flux: --error='EXAMPLE.{{id}}.err'
#flux: -N 1
#flux: -l # Add task rank prefixes to each line of output.
#flux: --setattr=thp=always # Enable Transparent Huge Pages (THP)
#flux: -t 20
#flux: -q pbatch # other available queues: pdebug

export MPICH_GPU_SUPPORT_ENABLED=1
export HSA_XNACK=1

# Check if THP are enabled
#cat /sys/kernel/mm/transparent_hugepage/enabled

flux run -N1 -n 4 --verbose --exclusive --setopt=mpibind=verbose:1 ./example.out

#flux run -N1 -n4 -x -l -g1  ./example
#flux run -N1 -n4 -x -l -g1  ./example

This file can be submitted to the flux scheduler with:

flux batch example.flux

Sample Flux Job via Python

Below is an example of interacting with flux job submission via the python interface, file flux-example.py

#!/usr/bin/python3
import sys
import os
import flux
from flux.job import JobspecV1

def main():
    handle = flux.Flux()
    jobspec = JobspecV1.from_command(
        command=["./a.out"], num_tasks=4, num_nodes=1,
    )
    jobspec.cwd = os.getcwd()
    jobspec.exclusive=1
    jobspec.t=5
    jobspec.environment = dict(os.environ)
    jobspec.stdout="PYEXAMPLE.{{id}}.out"
    jobspec.stderr="PYEXAMPLE.{{id}}.err"
    print(flux.job.submit(handle, jobspec))

if __name__=="__main__":
    main()

This should be run directly such as:

./flux-example.py