HPC Grid Tutorial: How to Compile with C/C++Share & Print
Follow these steps to compile a program with a C/C++ compiler.
Watch the video tutorial here!
1. Log on to the Grid.
2. Start an interactive job. Type: qsub -I
This puts you on a compute node for you to do compiling on. Never run jobs or do compiling on the head node Warrior.
3. Type: nano hello.c
4. Type the following lines into the editor:
The spaces may be important, depending upon the compiler. There are six spaces (a tab) before each line.
Save the file and exit. Press Ctrl + X, then Y for Yes and keep the name hello.c.
5. Choose a C/C++ compiler. In this example we will use gcc. Load the module.
Type: module load gnu7/7.3.0
6. To see the pathname of the gcc compiler you will be using type: which gcc
This shows you the first instance of it in your path.
7. Type: gcc hello.c -o hello_c_example
8. Now that you're done compiling, end the interactive job by pressing Ctrl + D.
9. Create the job script. Type: nano c_job_script
9. Enter the following into the editor:
#PBS -q wsuq
#PBS -l ncpus=1
#PBS -o /wsu/home/zz/zz99/zz9992/output_file
#PBS -e /wsu/home/zz/zz99/zz9992/error_file
cp /wsu/home/zz/zz99/zz9991/hello_c_example $TMPDIR
Save the file and exit the editor. Press Ctrl + X, then Y for Yes and keep the name c_job_script.
NOTE: zz9992 is the account used in this example, but you will have to modify the script using the AccessID and directories specific to your account.
10. Make sure that the file is executable. You can do this by changing the permissions.
Type: chmod +x c_job_script
11. Submit the job. Type: qsub c_job_script
12. You can check to see what jobs you're running by using the command qme. Once the job is finished running you will have an error and output file. Check your home directory by typing: ls
Check the contents of the output file by typing: cat output_file
The script was successfully executed.