Working with Makefiles
The tutorial assumes you have already worked through the Execute a Job Tutorial. Therefore, the instructions here are abbreviated but will follow the same format so you may easily consult the extended tutorial.
On this page, we will use a Makefile to automate the compiling of the C, C++, and Fortran programs. In our PBS script, we will send a command to the Makefile which will compile codes prior to submitting the job to MPI.
Table of Contents
📝 Note: Do not execute jobs on the login nodes; only use the login nodes to access your compute nodes. Processor-intensive, memory-intensive, or otherwise disruptive processes running on login nodes will be killed without warning.
Step 1: Access Your Allocation
If you need to request an allocation, see instructions here.
Open a Bash terminal (or PuTTY for Windows users).
Execute
ssh username@hostname
.When prompted, enter your password.
Step 2: Create a PBS Script
Example PBS Script
Here is an example PBS script for running a batch job on a HPC allocation.
PBS Procedure
From the login node, change your working directory to the desired file system. We are going to use our Lustre allocation for this example. If Lustre storage is not available, you may complete this tutorial from within your home directory on NFS.
Use Vi to create and edit your PBS script.
Create your PBS script within Vi or paste the contents of your PBS script into Vi.
Save your file and return to the Bash shell.
Step 3: Create the Makefile
A makefile contains instructions for Make software to automate the build of programs and source codes.
Makefile Code
This file must be located in the same path as the other source programs.
📝 Note: Indentations in a Makefile must be a Tab
and not spaces
.
Makefile Procedure
Ensure that you are still in your working directory (
/lustre/group/username
) usingpwd
.Use Vi (
vi
) to create your Makefile within your working directory.Paste the hello world Makefile code into Vi.
Save your file and return to the Bash shell.
If you have been following along the tutorials in order, you will already have compiled programs for C, C++, and Fortran. However, if you did not already have compiled codes, the Makefile we have created here would compile all of them when we run our PBS script. In the hello_world_make.pbs
file, there is a line that says make all
. This command will run the contents of our Makefile, which will compile the C, C++, and Fortran programs prior to running the job.
Step 4: Run the Job
Before proceeding, ensure that you are still in your working directory (using
pwd
) and that you still have the PE-gnu and python/3.6.1 modules loaded (usingmodule list
).We need to be in the same path/directory as our PBS script and our Makefile. Use
ls -al
to confirm their presence.
Use
qsub
to schedule your batch job in the queue.This command will automatically queue your job using Torque and produce a six-digit job number (shown below).
You can check the status of your job at any time with the
checkjob
command.You can also stop your job at any time with the
qdel
command.View your results. You can view the contents of these files using the
more
command followed by the file name.Your output should look something like this (the output is truncated.):
Download your results (using the
scp
command or an SFTP client) or move them to persistent storage. See our moving data section for help.
Additional Examples
Last updated