#!/bin/bash

{{#job.name}}
#BSUB -J "{{.}}"
{{/job.name}}

{{#job.spec.directory}}
#BSUB -cwd "{{.}}"
{{/job.spec.directory}}

{{#job.spec.inherit_environment}}
#BSUB -env all
{{/job.spec.inherit_environment}}
{{^job.spec.inherit_environment}}
#BSUB -env none
{{/job.spec.inherit_environment}}
{{#env}}
#BSUB -env {{name}}={{value}}
{{/env}}

{{#job.spec.resources}}

    {{#node_count}}
#BSUB -nnodes {{.}}
    {{/node_count}}

    {{#process_count}}
#BSUB -n {{.}}
    {{/process_count}}

    {{#gpu_cores_per_process}}
#BSUB -gpu num={{.}}/task
    {{/gpu_cores_per_process}}

{{/job.spec.resources}}


{{#job_duration}}
#BSUB -W {{.}}
{{/job_duration}}

{{#job.spec.attributes}}
    {{#queue_name}}
#BSUB -q "{{.}}"
    {{/queue_name}}

    {{#project_name}}
#BSUB -G "{{.}}"
#BSUB -P "{{.}}"
    {{/project_name}}

    {{#reservation_id}}
#BSUB -U "{{.}}"
    {{/reservation_id}}

    {{#custom_attributes.lsf}}
#BSUB -{{key}} "{{value}}"
    {{/custom_attributes.lsf}}

{{/job.spec.attributes}}

{{!since we redirect the output manually, below, tell LSF not to do its own thing, since it
only results in empty files that are not cleaned up}}
#BSUB -e /dev/null
#BSUB -o /dev/null

{{!redirect output here instead of through #BSUB directive since LSB_JOBID is not available
when the directives are evaluated; the reason for using the job id in the first place being the
same as for the exit code file.}}
exec &>> "{{psij.script_dir}}/$LSB_JOBID.out"

{{#psij.launch_command}}{{.}} {{/psij.launch_command}}

{{!we redirect to a file tied to the native ID so that we can reach the file with attach().}}
echo "$?" > "{{psij.script_dir}}/$LSB_JOBID.ec"
