NERSCPowering Scientific Discovery Since 1974

Your First Program

From Logging in to Submitting a Job

In order to follow this page, you will need an account, a username and a password. If you do not have all of these things please visit the Accounts Page.

Logging in

% ssh -l username franklin.nersc.gov

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. Paste the contents of the below code into the file.

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

Compile the program

ftn is the name of the Fortran compiler wrapper on Franklin.

% ftn -o helloWorld helloWorld.f90

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" or "copy to clipboard" button in the upper right hand corner of the batch script example.)  The batch script is used to instruct Franklin's batch system to reserve compute nodes for your job and then how  your application should be run on the compute nodes.

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

cd $PBS_O_WORKDIR
aprun -n 8 ./helloWorld

Submit Your Job to the Queue

The qsub command is used to submit your batch script to run on the Franklin compute nodes.

% qsub my_batch_script

A jobid will be returned, such as 7080540.nid00003

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 with the showq or qs command.

franklin% qs
franklin% qstat -u username
franklin% showq

 

Examine Your Job's Output

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

Warning: no access to tty (Bad file descriptor).

Thus no job control in this shell.

 Hello World from     2

 Hello World from     0

Hello World from     5

Hello World from     4

Hello World from 3

Hello World from 1

Hello World from 7

Hello World from 6

Application 9535825 resources: utime 0, stime 0


 + --------------------------------------------------------------------------

 +        Job name: mm3

 +          Job Id: 7080540.nid00003

 +          System: franklin

 +     Queued Time: Mon Mar 21 17:14:24 2011

 +      Start Time: Mon Mar 21 17:14:47 2011

 + Completion Time: Mon Mar 21 17:15:11 2011

 +            User: yunhe

 +        MOM Host: nid00339

 +           Queue: debug

 +  Req. Resources: other=QSUBPID:18484:nid00095,walltime=00:05:00

 +  Used Resources: cput=00:00:00,mem=0kb,vmem=0kb,walltime=00:00:24

 +     Acct String: mpccc

 +   PBS_O_WORKDIR: /global/homes/y/yunhe/shared

 +     Submit Args: mm3

 + ------------------------------------------------------------------------------