Exercise 4: Readning the gauge field
Goals: QDP I/O facilities
Concepts: Reading data from a file
Directory: $HOME/examples/04-reading-gauge
How to: $ cd $HOME/examples/04-reading-gauge
$ make
$ submit plaquette /scratch/data/beta6_gauge_8x8x8x16

To be useful, QDP must be able to read and write lattices from a file. To be really useful, it would do it in a portable manner. QDP is really useful.

Data files that QDP likes most are highly structured and use LIME to store information needed to understand file contents. The lattice data is stored in a binary form, however, QDP I/O routines automatically handle details of data representation, e.g., one can write a file on a big-endian machine 2048 node and read it back on a little-endian 30 node machine without having to worry that these machines use very different representation of the floating point numbers.

In this exercise we compute the plaquette again. This time, however, the gauge field is not generated by our program, instead we read it from the file. There are two files containing gauge fields in /scratch/data. In addition there is a file containing a propagator in the same directory.

$ ls -l /scratch/data
total 13849
-r--r--r--  1 root root 2362176 2007-06-21 01:33 beta6_gauge_8x8x8x16
-r--r--r--  1 root root 9439480 2007-06-20 18:48 propagator_8x8x8x16
-r--r--r--  1 root root 2361328 2007-06-20 18:48 random_gauge_8x8x8x16

The I/O facilities of the QDP library are somewhat different from the usual stream I/O. There are separate datatypes for files open for reading and writing, QDP_Reader and QDP_Writer repsectively.  In this exercise we concentrate on reading the file. It is convenient to abstract the read operation into a function. File read-gauge.c contains the code. We start with associating the reader with the file to be read.

  1   #include <qdp-config.h>
3 int
4 read_gauge(QDP_ColorMatrix *link[], char *name)
5 {
6 QDP_String *id = QDP_string_create();
7 QDP_Reader *reader;
9 reader = QDP_open_read(id, name);
10 if (reader == 0) {
11 printf0("open_read(%s) failed\n", name);
12 return 1;
13 }

The file contains four lattice matrices which we read on line 18

 18     if( QDP_vread_M(reader, id, link, 4) ) {

Once done, the file is closed and read_gauge() returns

 26     QDP_close_read(reader);
27 QDP_string_destroy(id);
28 return 0;
29 }

In main() the story should be familiar by now. We get the gauge field from argv[1], and process it as usual.

 31     /* read gauge field */
32 if (read_gauge(U, argv[1]) != 0) {
33 printf0("ERROR: read_gauge(%s)\n", argv[1]);
34 goto end;
35 }