Puc Tutorial 0: Your First Puc Program

This tutorial shows you how to develop, compile and run your first Puc program called Alphabet that prints the alphabet ('A' to 'Z') out to STDOUT.

1. Programming Process

  1. Prepare D-thinker.

    If it is your first time to use D-thinker, you can deploy D-thinker in your cluster by following D-thinker Build/Configuration Guide. Or you can also use our deployed cluster. You need to create your account first. Then we will tell you how to use the cluster by email.

  2. Log on the portal.

    The portal is the control node of D-thinker. Technically, the portal runs the "scheduler" service of D-thinker. You need to log on the portal to access D-thinker.

     $ ssh username@server.domain -p port
  3. Write the program alphabet.c.

    A Puc source file is saved as *.c by convention, for example, alphabet.c is the source file for the Alphabet Puc program. Please create the source file alphabet.c on the portal and input the following code using your favorite text editor such as nano. (Note: the alphabet.c file should only contain the following code after your editing.)

     #define N_ALPHABET_SIZE 26
     long array[N_ALPHABET_SIZE];
     void create_alphabet() {
         long i;
         for (i = 0; i < N_ALPHABET_SIZE; i = i + 1) {
             array[i] = 65 + i; // ASCII code
         commit; // commit task
     void print_alphabet() {
         long i;
         for (i = 0; i < N_ALPHABET_SIZE; i = i + 1) {
             /* print the charactor to STDOUT */
             *(long*)0x100000208 = array[i];
         *(long*)0x100000208 = 10; // new line
         commitd; // commit and delete depending task type
     void main() {
         /* A task sotres the alphabet in array[] */
         runner create_alphabet()
           using array[0,,N_ALPHABET_SIZE];
         /* A watcher prints the alphabet in array[] */
         runner print_alphabet()
           using array[0,,N_ALPHABET_SIZE]
           watching array[0,,N_ALPHABET_SIZE];

    Save the file and exit the editor.

  4. Compile the program.

    A specialized compiler for Puc, called cc0, will compile a Puc source file and generates D-CISC binary code. Make sure to check that the D-CISC binary code, which is the alphabet.bin file, is generated and up-to-date.

     $ cc0 alphabet.c -o alphabet.bin
  5. Run the program.

    Run the program by following command.

     $ dt run alphabet.bin

    If all goes well, you would get result like this:

     [user@portal ~]$ vim alphabet.c
     [user@portal ~]$ cc0 alphabet.c -o alphabet.bin
     [user@portal ~]$ dt run alphabet.bin
     Prepare the D-thinker...
     Start VPCs. (slot 0) (slot 0) (slot 0)
     Start to run the program with 3 VPCs.
     Program execution completed.
     The STDOUTs:
     You can view all in the result directory

2. Optional Steps

  1. You can always check the status of D-thinker.

     $ dt status
  2. If you find anything abnormal with the exection of your D-thinker program, feel free to terminate it.

     $ dt slay
  3. You can check STDOUT.

     [user@portal ~]$ cd /home/user/think/tmp/runtime/result-3
     [user@portal result-3]$ ls
     home.log               stdout-in_0x000000000000_10.16.66.107_0-0  think.conf
     scheduler.log          stdout-in_0x000000000000_10.16.66.108_0-0
     scheduler.log-summary  stdout-in_0x000000000000_10.16.66.109_0-0
     [user@portal result-3]$ cat stdout-*
  4. Find executed tasks and the information.

     [user@portal result-3]$ grep 'Pop' scheduler.log
     [1417329838.858313s] Pop without_preference task 0x3d000000000 to 0x10426b30.
     0 tasks remaining.
     [1417329838.864311s] Pop without_preference task 0x3d000010000 to 0x10426d30.
     0 tasks remaining.
     [1417329838.883933s] Pop without_preference task 0x3d000011000 to 0x10426c30.
     0 tasks remaining.
     [1417329838.899824s] Pop without_preference task 0x3d000012000 to 0x10426d30.
     0 tasks remaining.
     [1417329838.908494s] Pop one watcher type from watcherQ. 0 watcher types
  5. Try STDIN.

    STDIN of Puc program is also provided from files as that STDOUT is stored in files. Reading from STDIN is also through memory access as writing to STDOUT. Following is a simple example named read_stdin.c showing how to use STDIN.

     void main() {
         long buf;
         long i;
         for (i = 0; i < 5; i = i + 1) {
             buf = *(long*)0x100000200;
             *(long*)0x100000208 = buf;

    You need to save your STDIN content in a file. Suppose your STDIN file is named as "stdin_file". Then repeat the step 1~4 in the "Programming Process" section. When you want to run the read_stdin.bin program, you need to append the STDIN file into the dt run command.

     $ dt run read_stdin.bin stdin_file

3. What's Next

  • Puc Tutorial 1: Basic Programming Model and Concepts

    We have learned how to develop and run a simple program on D-thinker. Now, let's get deeper into the programming model an concepts of Puc and D-thinker. Detailed information will be in Puc Tutorial 1.

  • Puc Programmer Guide

    You are also recommended to read Puc Programmer Guide to know more development details.