Running C jobs on the NGS
C API
This tutorial extends the previous tutorial into the more advanced topics of the globus GRAM API for C. The assumption is made that an understanding of job submission and compiling code was acquired from the previous tutorial. Please consult the previous tutorial if in any doubt.
To run this tutorial you will need access to a Linux machine with Globus installed. You will also need to download the tar file and unzip it in your home directory:
tar -xvzf gram_srb_practical_files.tgz
All the files you need for this tutorial and the following two are now ready.
This tutorial involves some editing of files. To edit a file use the command
nano <filename>
where <filename> is the name of the file you wish to edit (though you may also use the "vi" editor if you would prefer to).
To use a graphical editor you must be able to view X11 clients (for example: under Windows you should start Hummingbird Exceed or Cygwin startx). You can then use:
kwrite <filename> &
The C API
- The first topic for this tutorial is a simple example of the globus C API. A guide to the functions of the GRAM C API may be found at http://www-unix.globus.org/api/c/globus_gram_client/html/index.html.
Before starting this section change to the directory in your account containing the files you need for this tutorial:cd ~/gram2/c_api
Any program that needs to be compiled against an API needs to find the relevant header files (files containing the definitions of the functions), the libraries of the functions and any other relevant definitions. The Globus toolkit provides a method of generating a file containing all the necessary definitions. This file may be used from within a Makefile (a file used by the "make" program to help automate the process of building an application - very similar to the "ant" program for java code) to compile the code. Since globus is a tool available across the spectrum of unix derivatives it needs to be able to handle different variations of compiler and binary format (called flavor's in globus terminology). To compile any code you must select an appropriate for which a run time library (rtl) and development version (dev) are available. Availability of flavors and different configurations can also depend on which parts of the globus API the code being developed will use. For this tutorial one part only is being used - globus_gram_client. To find the available flavors you can use the gpt-query tool (found at $GLOBUS_LOCATION/sbin/gpt-query) which can check for through the details of all the packages that were installed as part of globus (it is possible to only install a subset of the globus packages). This can be a slow process and unfortunately does not scale well in the tutorial environment. Hence a quick way to find the available flavors is:
ls $GLOBUS_LOCATION/etc/gpt/packages/globus_gram_client/*.gpt
You should get the below output
/usr/local/globus_4.0.3/etc/gpt/packages/globus_gram_client/pkg_data_gcc32dbg_dev.gpt /usr/local/globus_4.0.3/etc/gpt/packages/globus_gram_client/pkg_data_gcc32dbgpthr_dev.gpt /usr/local/globus_4.0.3/etc/gpt/packages/globus_gram_client/pkg_data_gcc32dbgpthr_rtl.gpt /usr/local/globus_4.0.3/etc/gpt/packages/globus_gram_client/pkg_data_gcc32dbg_rtl.gptIn this listing the available flavors are "gcc32dbg" and "gcc32dbgpthr". The "gcc32dbgpthr" flavor contains support for the "pthreads" library which is not needed in this tutorial so instead the flavor "gcc32dbg" will be used.
- Having now chosen a suitable flavor a file can be created with all the necessary definitions by using the command:
globus-makefile-header --flavor gcc32dbg globus_gram_client > globus_header
If you examine the file "globus_header" with the command
PRE cat globus_header PRE
the advantage of having an automated system for generating this configuration is apparent.
- Having generated the necessary configuration it can be included in a Makefile and the code compiled. Examine the "Makefile" and you will that "globus_header" is included and the commands that are used to compile your code. Compile the command by typing
make
and then run it with the command
PRE ./apidemo PRE
This code simply tests that the queue "grid-data.rl.ac.uk/jobmanager-pbs" can be contacted (a ping type message is sent). - If you examine the code you will see that it is necessary to initialize the part of the globus api code being used:
PRE globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE); PRE
and similarly to deactivate it. If you miss this out of your code it will still compile, but you will encounter errors at run time. Modify the code and introduce an error into the name of the queue being tested. If make complains about being already up to date use the commandmake clean
before repeating the make command.
