Revision as of 19:03, 22 February 2007 by Gamperl (talk | contribs) (New page: {| id="toc" class="toc" summary="Contents"|| * [#Introduction ] * [#Header ] * [#The_SingleWorker ] * [#The_SingleTask ] * [#The_SingleFactory ] * [#The_main_program ] * [#Compile_the_pro...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  • [#Introduction ]
  • [#Header ]
  • [#The_SingleWorker ]
  • [#The_SingleTask ]
  • [#The_SingleFactory ]
  • [#The_main_program ]
  • [#Compile_the_program ]
  • [#Run_the_program ]


This tutorial describes, how to write a single task application using parts of the ALPS libary (e.g the parameter libary, the lattice libary or the model libary).

The ALPS Scheduler needs a worker class, a task class and a factory class. We will develop implementaions of these classes to implement a version of the most famos programm in the world: The hello world example.


First wir have to load the ALPS::Scheudler library:

   #include <alps/scheduler.h>
   #include <alps/osiris/comm.h>
   #include <stdexcept>

The SingleWorker

In the worker class all the work is done. This is the only call you have to change, to write your own application. We inherit our worker class from the alps::scheduler::Worker class, a generic prototype of a worker class:

   class SingleWorker: public alps::scheduler::Worker {
           SingleWorker(const alps::ProcessList$amp; where, const alps::Parameters$amp; p, int node):
           alps::scheduler::Worker(where, p, node)
           void dostep() {
                   std::cout << parms["MESSAGE"] << std::endl << std::endl;
           static void print_copyright(std::ostream$amp; out ) {}

In the dostep function all the Work is done. If you develop your own application, this function ist the point to call your applicaiton. You should also put your copyright in the print_copyright function.

You should notice the term parms["MESSAGE"]. This Message is passed from the parameterfile. The params member variable is a protected member of the alps::scheduler::Worker class and represents all parameter passt throu the paramter file.

The SingleTask

The Task class is only needed to call the Worker class:

   class SingleTask: public alps::scheduler::WorkerTask {
           SingleTask(const alps::ProcessList$amp; where, const boost::filesystem::path$amp; p):
           alps::scheduler::WorkerTask(where, p)
           { construct(); }
           SingleTask(const alps::ProcessList$amp; where, const alps::Parameters$amp; p):
           WorkerTask(where, p)
           { construct(); }
           void dostep () {
           std::string worker_tag() const { return "SingleTask"; }
           static void print_copyright(std::ostream$amp; out ) {}

The SingleFactory

The scheduler needs a factory to create instances of the worker and the task class. There is a generic class in ALPS to create factories:

   typedef alps::scheduler::BasicFactory<SingleTask, SingleWorker> SingleFactory;

The main program

We're nearly done. All components are avalable only the main file is missing:

   int main(int argc, char** argv) {
           try {
                   return alps::scheduler::start(argc, argv, SingleFactory());
           } catch (std::exception$amp; exc) {
                   std::cerr << exc.what() << "\n";
                   return -1;
           } catch (...) {
                   std::cerr << "Fatal Error: Unknown Exception!\n";
                   return -2;

Compile the program

We don't want to write a makefile for a single file application, so we can compile it by hand. If ALPS is installed in $HOME/ALPS and boost in $HOME/boost the follwoing command compiles our very exciting and sofisticated application:

   g++ -O3 -o helloworld.out \
   -I$HOME/boost \
   -I$HOME/ALPS/include \
   -L$HOME/ALPS/lib \
   -lalps \
   -lcomm-sgl \
   -lexpat \

Run the program

To run the program we need a parameterfile to pass the task parameter to the schedler. Here we can pass our message to the world:

   {MESSAGE="Hello World";}

Thats it. To create the task XML-files we can call the parameters2xml programm

   parameter2xml params

and get a params.in.xml among some other files. Now we can call our application

   helloworld.out params.in.xml

$copy; 2007 by Lukas Gamper