Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

One of the nice features of srun is that it preserves this ability to redirect input and output. Just remember that any options directly after srun such as –N will be used by srun. However, any options or piping commands after your program name will be used by the program only.

Dealing with Batch Files

...

In many cases, you will want to run your calculation on the scratch space for a particular node. This will prevent your calculation from writing to the NSF mounted /home directory and insure that you are not wasting time due to unnecessary data transfer between nodes. However, the srun command doesn’t know which node you want to run on or in which directory your calculation will need to run. In these cases, it is essential to write a batch file that will guide your calculation along. The essential steps to include in your batch file are (this example uses a naming convention that this is run #2 on day May 24):

  1. The first line of your script file must indicate that this is a script:

    Code Block
    languagebash
    #!/bin/bash
  2. Create an unique directory in your scratch space for this calculation (substitute your user name is the commands below):

    Code Block
    languagebash
    mkdir /scratch/user_name/may24_run2/
  3. Report back to a file in your home directory as to which node the calculation is running on and the time it started. This will help you track down the results when it is finished.

    Code Block
    languagebash
    /usr/bin/hostname > /home/user_name/may24_run2.log
    /usr/bin/date >> /home/user_name/may24_run2.log
  4. Now that we have created the directory, we need to move all the necessary input files over from the home directory.

    Code Block
    languagebash
    cp /home/user_name/input_store/input.dat /scratch/user_name/may24_run2/
  5. Hop into the directory we created

    Code Block
    languagebash
    cd /scratch/user_name/may24_run2
  6. Start the calculation

    Code Block
    languagebash
    /home/user_name/bin/cool_program.x < input.dat > may24.out.run
  7. Report back when the calculation is finished. Leave some info in our home directory log file.

    Code Block
    languagebash
    echo "Job Done" >> /home/user_name/may24_run2.log
    /bin/date >> /home/user_name/may24_run2.log
  8. Copy results back back to a directory in your home directory (make sure you have previously created the "output_store" folder in your home directory)

    Code Block
    languagebash
    cp /scratch/user_name/may24_run2/may24.out.run /home/user_name/output_store/
  9. Clean up the scratch space on the node so as to not fill up the disk

    Code Block
    languagebash
    rm -rf /scratch/user_name/may24_run2

...

Code Block
languagebash
$ chmod u+x batch_file.run

And when you start the batch file with srun, use the -b option so srun know that the file contains a series of commands:

 Use srun to submit the job:

Code Block
languagebash
$ srun -b batch_file.run

You will see a new job listed when you type squeue .

...