Wayne State University


Wayne State University

High Performance Computing Services



Follow these steps to compile a program with a C/C++ compiler.
Log on to the grid.

Start an interactive job. Type: qsub -I

Input: 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.

Job is ready. Running on vii3 in this example.

nano hello.f

  Input: nano hello.f
Type the following lines into the editor:
      print *, "Hello World"

(The spaces may be important, depending upon the compiler. There are six spaces (a tab) before each line.)

Text in nano editor

Save the file and exit (Press Ctrl + X, then Y for Yes and keep the name hello.f)

Choose a C/C++ compiler (A list of C/C++ compilers can be found here). In this example we will use gcc.

Load the module. Type:
module load gnu-4.7.2/compiler

Input: module load gnu-4.7.2/compiler

To see the pathname of the gcc compiler you will be using type: which gcc

Input: which gcc

This shows you the first instance of g77 in your path.

Result: Shows first instance of gcc in path.

gcc hello.f -o hello_c_example

Input: : gcc hello.f -o hello_c_example

Now create the job script. Type:
nano c_job_script

nano c_job_script

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/zz9992/hello_c_example $TMPDIR


Script typed into nano

Save the file and exit the editor.

NOTE: zz9992 is the account used in this example, but you will have to modify the script using the Access ID and directories specific to your account.

Make sure that the file is executable. You can do this by changing the permissions. Type:
chmod +x c_job_script

Input: chmod +x c_job_script

Execute the job script. Type: ./c_job_script

Input: ./c_job_script

The job has been executed.

Output: Hello World
Computer Center Services * 5925 Woodward Avenue Detroit, Michigan 48202