NERSCPowering Scientific Discovery Since 1974

Your First Program on Edison

From Logging in to Submitting a Job

In order to follow this page, you will need a NERSC username and password, and to be a member of an allocated project account ("repo"). If you do not have all of these things please visit the Accounts Page.

Logging in

% ssh -l username

When you successfully log in you will land in your $HOME directory.

First Program Code: Parallel Hello World

Open a new file called helloWorld.f90 with a text editor such as emacs or vi.  Use the "view source" button Copy Icon that will appear in the upper right hand corner of the example when you move your cursor there and paste the contents of the code below into the file.

program helloWorld
implicit none
include "mpif.h"
integer :: myPE, numProcs, ierr
call MPI_INIT(ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, numProcs, ierr)
print *, "Hello from Processor ", myPE
call MPI_FINALIZE(ierr)
end program helloWorld

Compile the Program

Use the compiler "wrappers" to compile codes on Edison: use ftn for Fortran, cc for C, and CC for C++.

% ftn -o helloWorld helloWorld.f90

Run the Program

There are two things that are needed to run a code on Edison: (1) You must submit a request to the batch system; and (2) You must launch your job on to the compute nodes using the 'aprun' command.  There are two ways to submit a request to the batch system: (1) You can request an interactive batch session using a command such as 'qsub -I -V -q debug' (which has a 30-minute limit) or your can submit a batch script (see below).  The example here uses an MPI parallel code but you must use the 'aprun' command to launch an executable on to the compute nodes whether your code is serial, MPI parallel, or single-node threaded parallel.  There is no 'mpirun' command.

Create a Batch Script

Open a file called my_batch_script with a text editor like vi or emacs and paste in the contents below. (Use the "view source" button Copy Icon that will appear in the upper right hand corner of the batch script example when you move your cursor there.)  The batch script is used to tell the Edison system to reserve compute node resources for your job and how it should launch your application on the compute nodes it has reserved.

Contents of file: my_batch_script

#PBS -q debug 
#PBS -l mppwidth=24
#PBS -l walltime=00:10:00
#PBS -N my_job
#PBS -j oe

aprun -n 24 ./helloWorld

Submit Your Job to the Queue

The qsub command is used on the login nodes to submit your batch script so your job will run on the Edison compute nodes.

% qsub my_batch_script

A jobid will be returned, such as 164822.edique02.

Monitor Your Job in the Queue

After you submit your job, the system scheduler will check to see if there are compute nodes available to run the job. If there are compute nodes available, your job will start running. If there are not, your job will wait in the queue until there are enough resources to run your application. You can monitor your position in the queue using several different commands, such as:

edison% qs -u username
edison% qstat -u username
edison% showq

Examine Your Job's Output

When your job has completed you should see a file called my_job.o[jobid]

 Hello from Processor            1
 Hello from Processor            2
 Hello from Processor           10
 Hello from Processor            8
 Hello from Processor           11
 Hello from Processor            3
 Hello from Processor            9
 Hello from Processor            4
 Hello from Processor            6
 Hello from Processor            5
 Hello from Processor            7
 Hello from Processor           12
 Hello from Processor           17
 Hello from Processor           20
 Hello from Processor           14
 Hello from Processor           22
 Hello from Processor           15
 Hello from Processor           16
 Hello from Processor           23
 Hello from Processor           21
 Hello from Processor           13
 Hello from Processor           19
 Hello from Processor           18
 Hello from Processor            0
Application 100039 resources: utime ~2s, stime ~1s, Rss ~5700, inblocks ~6317, outblocks ~15013

 + --------------------------------------------------------------------------
 +        Job name: my_job
 +          Job Id: 164822.edique02
 +          System: edison
 +     Queued Time: Wed Jul 31 18:45:39 2013
 +      Start Time: Wed Jul 31 18:45:49 2013
 + Completion Time: Wed Jul 31 18:45:54 2013
 +            User: zz217
 +        MOM Host: nid00898
 +           Queue: debug
 +  Req. Resources: mppnodect=1,mppnppn=24,mppwidth=24,walltime=00:10:00
 +  Used Resources: cput=00:00:00,mem=1556kb,vmem=11788kb,walltime=00:00:06
 +     Acct String: mpccc
 +   PBS_O_WORKDIR: /global/u1/z/zz217/tests/ph
 +     Submit Args: my_batch_script
 + --------------------------------------------------------------------------