user/pages/14.faq/01.program/docs.en.md
c7b95cb6
 ---
b59c4467
 title: 'Execution of Serial Program'
715ae848
 published: true
c7b95cb6
 ---
 
b59c4467
 This section explains the use case of creating a program in C language, compiling and executing a job on the supercomputer. <br>
 Please refer to [Access](/login) for login to supercomputer.
c7b95cb6
 
 [toc]
 
b59c4467
 ## Creating a sample program
c7b95cb6
 
b59c4467
 This section explains how to create and compile the sample program (sample.c).
c7b95cb6
 
b59c4467
 ### Starting the editor
c7b95cb6
 
b59c4467
 We create a sample program using "emacs" here. In addition to the "emacs", other editors that are installed as standard on the system are "vi (vim)" etc.
c7b95cb6
 
b59c4467
 Start "emacs" with the following command and open the empty file “sample.c”.
c7b95cb6
 
b59c4467
 ```nohighlight
 emacs sample.c
 ```
c7b95cb6
 
b59c4467
 ### Program Description
c7b95cb6
 
b59c4467
 Enter the following program manually or copy and paste it. <br>
 The paste to the terminal is often assigned to the right click or wheel click of the mouse.
c7b95cb6
 
b59c4467
 ```nohighlight
 #include <stdio.h>
 #include <unistd.h>
c7b95cb6
 
b59c4467
 int main (void) {
    printf ("hello \ n \ n");
    sleep (120);
    return 0;
 }
 ```
c7b95cb6
 
b59c4467
 When input is completed, press "Ctrl + x Ctrl + s" to save.
 “Ctrl + x” means “press "x" key while holding down "Ctrl" key on the keyboard”. <br>
 When saving is completed, the following message is displayed at the bottom of the screen.
c7b95cb6
 
 
b59c4467
 ```nohighlight
 Wrote /home/b/b59999/sample.c
 ```
c7b95cb6
 
b59c4467
 To exit the emacs, press "Ctrl + x Ctrl + c". <br>
 Check the created file by typing `ls -l` in the terminal. If the file name "sample.c" is displayed as shown below, there is no problem.
c7b95cb6
 
b59c4467
 ```nohighlight
 -rw-r ----- 1 b59999 b59999 75 Dec 18 10:42 sample.c
 ```
c7b95cb6
 
b59c4467
 ### Compile
c7b95cb6
 
b59c4467
 Enter the following command to compile.
 The command name to compile varies depending on the systems.
c7b95cb6
 
b59c4467
 System | Command
 -------- | -------
 A | cc sample.c
 B or C | icc sample.c
c7b95cb6
 
b59c4467
 The compiled program is named “a.out”. <br>
 If you type "ls -l" in the terminal and the file name "a.out" is displayed as shown below, there is no problem.
c7b95cb6
 
b59c4467
 ```nohighlight
 -rw-r ----- 1 b59999 b59999 9817 Dec 18 10:42 a.out
 ```
c7b95cb6
 
 
b59c4467
 ## Job Execution and Confirmation of the Execution
c7b95cb6
 
b59c4467
 Next section explains the procedure for executing the program created in the previous section. <br>
 Since the login node is a computer shared by many users,
 ***the program needs to be executed on the computing node***  using the following method.
c7b95cb6
 
b59c4467
 A unit that submits (request execution) a program to a computing node is called a job.
 There are two types of job submission methods: interactive processing and batch processing.
 This section introduces how to submit jobs using batch processing.
c7b95cb6
 
b59c4467
 When submitting jobs using batch processing, 
 it is necessary to describe a execution process with a script called a job script. <br>
 This section explains how to create, execute, and confirm job scripts.
c7b95cb6
 
b59c4467
 ### Creating a job script
 Job scripts are basically the same format as shell scripts. The job script consists of an option area describing PBS job submission options and a user program area (shell script part) describing program to be executed. <br>
 In the user program area,  it is possible to describe the processing to be executed before and after in the same format as the shell script in addition to the execution processing of the program itself.
c7b95cb6
 
b59c4467
 Start emacs with the following command and open the "sample.sh" file.
c7b95cb6
 
 ```nohighlight
b59c4467
 emacs sample.sh
c7b95cb6
 ```
 
b59c4467
 When emacs starts, enter the following job script manually or copy and paste it. <br>
 ****How to describe the user program area of the job script differs depending on System A and System B / C. Please use the system of  which you submit the job.***
c7b95cb6
 
b59c4467
 #### Job script for System A
c7b95cb6
 ```nohighlight
b59c4467
 #! / bin / bash
 #============ PBS Options ============
 #QSUB -q gr19999b
 #QSUB -ug gr19999
 #QSUB -A p = 1: c = 1: t = 1: m = 1355M
 #QSUB -W 10:00
 #============ Shell Script ============
 aprun -n $ QSUB_PROCS -d $ QSUB_THREADS -N $ QSUB_PPN ./a.out
c7b95cb6
 ```
b59c4467
 * Note) ***aprun command is required*** for batch processing in System A. Please refer to [here](./# aprun) for details.  
c7b95cb6
 
b59c4467
 #### Job script for system B / C
c7b95cb6
 ```nohighlight
b59c4467
 #! / bin / bash
 #============ PBS Options ============
 #QSUB -q gr19999b
 #QSUB -ug gr19999
 #QSUB -A p = 1: c = 1: t = 1: m = 3413M
 #QSUB -W 10:00
 #============ Shell Script ============
 ./a.out
c7b95cb6
 ```
 
b59c4467
 Next, modify the job script according to your available system and queue.
c7b95cb6
 
b59c4467
 ####  \ #QSUB -q value
c7b95cb6
 
b59c4467
 Specify the queue after `#QSUB -q`. The below is the queue name for each service course.
     
 Service Course | Queue Name
c7b95cb6
 -------- | --------
b59c4467
 Entry course | eb
 Personal course | pa (System A) <br> pb (System B) <br> pc (System C)
 Group course, organization fixed rate, HPCI, JHPCN | Queue name notified to applicant
     
 If you specify a group course queue "gr19999b", enter as follows.
c7b95cb6
 ```nohighlight
b59c4467
 #QSUB -q gr19999b
c7b95cb6
 ```
 
b59c4467
 #### \ #QSUB -ug value
c7b95cb6
 
b59c4467
 This is required for users of group course, organization fixed rate, HPCI, JHPCN. 
 Users of entry course and personal course can delete this line.
c7b95cb6
 
b59c4467
 Specify the group name after `#QSUB -ug`. Group name of the group course is the same as the group name (the last letter removed from the queue name). 
 Group name of the organization fixed rate, HPCI, and JHPCN may differ from the queue name, so please follow the specified group name.
c7b95cb6
 
b59c4467
 If you submit the group course queue "gr19999b" of the system B, enter as follows.
c7b95cb6
 ```nohighlight
b59c4467
 #QSUB -ug gr19999
c7b95cb6
 ```
 
b59c4467
 #### \ #QSUB -A value
 You can specify the amount of Job allocation resource after `#QSUB -A`.
 The following four arguments can be specified. If not specified, default values are automatically set.
c7b95cb6
 
b59c4467
 -A argument | Description | Default value |
 ----------- | ------------------------------------- | -----------------
 p = procs | Number of processes allocated during job execution | 1
 t = threads | Number of threads allocated per process during job execution. Set environment variable OMP_NUM_THREADS automatically | 1
 c = cores | Number of CPU cores allocated per process during job execution. Basically set to the same value as "t" | 1
 m = memory | Amount of allocated memory per process during job execution (unit: M, G, T) | 1355M (System A), 3413M (System B), 42666M (System C)
c7b95cb6
 
b59c4467
 As we deal with a serial program (non-parallel program) as an example here, we describe an example in which one core, one thread, and 1355M of memory are allocated and executed below. For parallel computation, please see [Execution of MPI Program](/faq/mpi).
c7b95cb6
 
b59c4467
 ```nohighlight
 #QSUB -A p = 1: c = 1: t = 1: m = 1355M
 ```
c7b95cb6
 
b59c4467
 #### \ #QSUB -W value
 You can specify the upper limit of the job execution time after `#QSUB -W`.
 The default value of the job execution time and the upper limit value which can be specified are as follows:
c7b95cb6
 
b59c4467
 Service course | Default value | Upper limit value |
 ------------------ | ----------------- | -------- |
 Entry course | 1:00 (1 hour) | 1:00 (1 hour)
 Personal course | 1:00 (1 hour) | 168: 00 (168 hours)
 Group course, Organization Fixed Rate, HPCI, JHPCN | 1:00 (1 hour) | 336: 00 (336 hours)
c7b95cb6
 
 
b59c4467
 If the upper limit of the job execution time is 10 hours, enter as follows.
 ```nohighlight
 #QSUB -W 10:00
 ```
c7b95cb6
 
b59c4467
 #### aprun command [only for System A] {#aprun}
 In the system A, a node where the job script is executed (gateway node) and a node where the program is executed (computing node) are separated.
 To run a program on a computing node, the _**aprun**_ command _**must_** be used at the location where the job script program is executed regardless of whether it is a serial program or an MPI program.
c7b95cb6
 
b59c4467
 The following are typical examples of aprun command. Please refer to the command manual (man aprun) for details of the options.
c7b95cb6
 
b59c4467
 Option | Function | Default value | Remarks |
 : --------------------: | --------------------------- --------- | ----------------- | ------ |
 -n _procs_ | Specify the number of processes to be started | 1 | By specifying $ QSUB_PROCS, the number specified for "p" in the #QSUB -A option is inserted.
 -d _cores_ | Specify the number of CPU cores to be secured per process | 1 | By specifying $ QSUB_THREADS, the number specified for "t" in the #QSUB -A option is inserted.
 -N _procs \ _per \ _node_ | Specify the number of processes per node | 1 | By specifying $ QSUB_PPN, the optimal number of processes per node is automatically inserted.
c7b95cb6
 
b59c4467
 ### Job Execution
c7b95cb6
 
b59c4467
 Submit a job with the following command.
c7b95cb6
 
 ```nohighlight
 qsub sample.sh
 ```
b59c4467
 If the above command is successfully received, the JOBID is displayed as shown below.
 ```nohighlight
 $ qsub sample.sh
 1255581.jb
 ```
c7b95cb6
 
b59c4467
 ### Confirmation of the Execution
c7b95cb6
 
b59c4467
 You can check the job status with the `qs` command.
c7b95cb6
 
b59c4467
 Example of output result:
c7b95cb6
 ```nohighlight
b59c4467
 QUEUE     USER     JOBID      STATUS  PROC THRD CORE    MEM    ELAPSE( limit)
  gr19999b  b59999   1255581   RUN               1         1         1    1355M  00:00( 10:00)
 ``` 
c7b95cb6
 
b59c4467
 When the "STATUS" is "RUN", the program is running on the computing node. <br>
 When the job ends, the standard output of the program is output to a file with the extension “o + number”, such as “B121811.o1255581”. The part of the number is JOBID.
c7b95cb6
 
b59c4467
 Use the `ls` command to find and open the standard output file. If the job is running normally, job summary with the output "hello" is shown as below.
c7b95cb6
 
 ```nohighlight
b59c4467
 [b59999 @ laurel3 b] $ ls
 B121811.o1255581 B121811.e1255581
c7b95cb6
 
b59c4467
 [b59999 @ laurel3 b] $ cat B121811.o1255581
c7b95cb6
 hello
 
b59c4467
 ================================================== ==============================
c7b95cb6
 
b59c4467
                 Resource Usage on 2017-12-18 11: 50: 04.791317:
c7b95cb6
 
b59c4467
 JobId: 1255581.jb
         Job_Name = B1255581
         queue = gr19999b
         Resource_List.Aoption = gr19999: p = 1: t = 1: c = 1: m = 1355: c_dash = 1
         Resource_List.select = 1: ncpus = 2: mpiprocs = 1: mem = 1355mb: jobfilter = long
c7b95cb6
         qtime = 2017-12-18 11:49:58
         stime = 2017-12-18 11:50:04
         resource_used.cpupercent = 0
         resource_used.cput = 00:00:00
         resources_used.mem = 0b
         resources_used.ncpus = 2
         resources_used.vmem = 0b
         resources_used.walltime = 00:00:02
 
b59c4467
 ================================================== ==============================
c7b95cb6
 ```
 
b59c4467
 A file with a extension “e + number” is a standard error output.
 
 
 ## For Full-Scale Calculation
 
 In the above tutorial, the sample program was executed in a single process in the home directory.
 
 For full-scale calculations, parallel execution of multiple processes and multiple threads using MPI and OpenMP is necessary. For that, the #QSUB -A option that is not covered in the job script this time is required. Also, since the standard execution time of a job is 1 hour, the `#QSUB -W` option is required for long-time calculations. <br>
 For details, please refer to the following page according to the systems.
 
 * [Executing Programs](/run)
 
 If you are not in the entry course, you can use a large volume disk as a disk space in addition to the home (capacity: 100 GB).
 Please refer to the following page for details.
c7b95cb6
 
b59c4467
 * [Using file system](/filesystem)
c7b95cb6
 
b59c4467
 Several types of commercial tools are also available for compilers and calculation libraries.
 Please refer to the following page for details.
c7b95cb6
 
b59c4467
 * [Compilers and Libraries](/compilers)
c7b95cb6
 
b59c4467
 Sample scripts for the job scripts are provided according to the execution type.
 Please refer to the following page for details.
c7b95cb6
 
b59c4467
 * [Sample Script (System A)](/run/systema#samplescript)
 * [Sample Script (System B / C)](/run/systembc#samplescript)
c7b95cb6
 
b59c4467
 This concludes the explanation of compiling and executing of your application.
c7b95cb6