Exercise 1: QDP Hello World
Goals: learning how to compile and run QDP programs
Concepts: QDP initialization
Directory: $HOME/examples/01-hello
How to: $ cd $HOME/examples/01-hello
$ make
$ submit hello

Each QDP program should include <qdp.h>. There are two preprocessor symbols, QDP_Precision and QDP_Nc, which, if defined before including <qdp.h>, instruct it to set the default values of floating point precision and the number of colors to specified values. If left out they will default to the same values used here. In all our examples we keep these definitions and necessary includes in a separate file $HOME/examples/qdp-config.h, which starts as follows:

 1 #include <stdio.h>
3 #define QDP_Precision 'F'
4 #define QDP_Nc 3
5 #include <qdp.h>
7 #define NDIM 4

In this exercise we learn how to write a simple QDP program. After including <qdp-config.h> and defining the lattice size, we proceed to the main():

  1   #include <qdp-config.h>
3 int lattice_size[NDIM] = { 4, 4, 4, 4 };
5 int
6 main(int argc, char *argv[])
7 {

Each QDP program starts with initializing QDP, setting lattice size, and setting up the layout for the rest of the program. These three steps are performed once in a program.

  8     /* start QDP */
9 QDP_initialize(&argc, &argv);
11 /* set lattice size and create layout */
12 QDP_set_latsize(NDIM, lattice_size);
13 QDP_create_layout();

True to the "Hello, World" tradition, the only substantial action is saluting the world. Notice that we do it only on node 0.

15 /* say hello from node 0 */
16 if(QDP_this_node==0)
17 printf("Hello from node %d\n", QDP_this_node);

Before exiting the program one must close QDP by calling QDP_finalize():

19 /* shutdown QDP */
20 QDP_finalize();
22 return 0;
23 }

The job can be started on the Blue Gene with the script $HOME/bin/submit. It does what its name implies, namely, it places a job request into the BG/L queue. One can check the current status of the queue by saying

$ cqstat

Once the job is done, two files will be created in the current directory with names ending in .output and .error.