Go up to Tutorial Go forward to Quicksort |
// -------------------------------------------------------------------------- // Hello, World! // -------------------------------------------------------------------------- #include <rt++.h> // the RT++ header file #include <iostream.h> // the C++ header files // -------------------------------------------------------------------------- // the RT++ main program // -------------------------------------------------------------------------- int hello(int argc, char *argv[]) { cout << "Hello, World!\n"; return(0); } // -------------------------------------------------------------------------- // the C++ main program // -------------------------------------------------------------------------- int main(int argc, char *argv[]) { Rt_Argument rtarg; // RT++ runtime parameters rtarg.proc = 1; // 1 process rtarg.memory = 1000000; // 1 MB shared memory rtarg.heap = 100000; // 100 KB initial heap rtarg.blocks = 4; // 4 heap blocks per process rtarg.stack = 15000; // 15 KB thread stack rtarg.verbose = 1; // print statistics exit(rt_main(hello, argc, argv, rtarg, 0)); // pass control to RT++ and exit }
Every RT++ program includes the header file rt++.h (among all other C++ header files that the program requires). The RT++ program is represented by a user-defined function with an arbitrary name prog and prototype
The parameters argc and argv have the same interpretation as in the C++ main function (but it is up to the programmer to provide the argument values, see below). The return value of prog is an integer that denotes the success respectively failure of program execution.int
prog(int argc, char *
argv[])
In order to start up the RT++ runtime environment, the programmer has to
explicitly pass control from the sequential C++ program to the RT++ main
function. This is done by a call of rt_main
which takes as arguments
the function prog and the argc and argv passed to
prog.
When the RT++ program terminates normally (e.g. by returning from
prog) or abnormally (e.g. by a runtime error), control is
returned to the caller of rt_main
. The C++ program may then continue
execution or start another RT++ program.
The argument rtarg is not passed to prog but used by RT++ itself to set up the runtime environment. The programmer here specifies the number of processes, the maximum amount of shared memory, the initial size of the garbage collected heap, the number of heap blocks per process, the size of the stack of each concurrent thread and whether the output of statistical information is wished or not.
The last argument of rt_main
can be used to retrieve the statistical
information in a program variable for those cases where the programmer wants
to process this information on her own. Otherwise, we just pass a 0 (null)
pointer instead.
That's all there is! We can now compile and link the program like any other C++ program with a command line similar to the following:
The program uses the RT++ library librt++.a which in turn is based (in its current implementation) on the QuickThreads library libqt.a. If these libraries and the associated header files are not installed in standard places, one has to provide additional -I and -K arguments that tell the compiler/linker where to search for the corresponding files.g++ -O -Wall prog.cc -lrt++ -lqt -o prog
The resulting program can be called as
and produces the output depicted below../prog
------------------------------------------------------------------------------ RT++ 1.0 (C) 1996 Wolfgang Schreiner <Wolfgang.Schreiner@risc.uni-linz.ac.at> proc: 1, mem: 1000000, heap: 100032, blocks: 4, stack: 15000 ------------------------------------------------------------------------------ Hello, World! ------------------------------------------------------------------------------ RT++ execution Return code: 0 Real time(ms): 10 Proc time(ms): 10 All procs(ms): 10 RT++ garbage collections Number: 0 Increments: 0 Waiting(ms): 0 Collecting(ms): 0 Blocks: 0 Bytes: 0 ------------------------------------------------------------------------------The statistical information printed by RT++ includes the return code of the RT++ program (not that of the C++ program!), the real time spent in the RT++ program, the time spent in the RT++ program by the initial process respectively by all processes, the number of garbage collections, the number of times the garbage-collected heap was increased, the amount of real time spent for synchronization before garbage collection was performed, the amount of real time actually spent in garbage collection, the number of heap blocks and the number of bytes reclaimed.
If the verbose
flag in rtarg is set to 0, all RT++ output is
switched off and the program output simply is
Hello, World!