The TaskGraph
Meta-programming Library is a C++ package that supports
You can
download the current release of the library from here.
The library is presented in
a talk
and a paper
(however this distribution has a tidied and more typesafe design).
#include <stdio.h>
#include <stdlib.h>
#include <TaskGraph>
using namespace tg;
typedef TaskGraph<int, int> TG_IntResIntArg;
int main( int argc, char *argv[] ) {
TG_IntResIntArg T;
int n = atoi( argv[1] );
taskgraph( TG_IntResIntArg,
T, tuple1(a) ) {
tVar(int, i);
tVar(int, j);
tFor(i, 0, n-1)
{
tFor(j, 0, n-1) {
tPrintf("Iteration i=%d, j=%d\n", i, j);
}
}
tReturn(a + n);
}
InterchangeSettings inter;
inter.firstLoop =
LoopIdentifier ( 1 );
inter.secondLoop =
LoopIdentifier ( 1, 1 );
T.applyOptimisation (
"interchange", &inter );
T.compile( tg::GCC, true );
printf( "T(%d) =
%d\n", n, T(n) );
}
If you run this with input 2, it
prints:
Iteration i=0, j=0Iteration i=1, j=0Iteration i=0, j=1Iteration i=1, j=1T(2) = 4
At runtime it generates the
following code:
extern int printf(char *, ...);extern int taskGraph_0(void **); extern int taskGraph_0(void **params) { int *a; int i; int j; static char string0_[23] = "Iteration i=%d, j=%d\n"; a = *params; for (j = 0; j <= 1; j++) { for (i = 0; i <= 1; i++) { printf(string0_, i, j); } } return *a + 2; }
This code and documentation is
copyright by the authors and
If you wish to use the software for
any practical purpose, permission must be gained from Paul Kelly.
No charge will be made to academic
and research users of this version of the software.
The library cannot sensibly be
distributed in binary form, as it needs to invoke your compiler at
runtime. Instead, you need to
expand the tarball on your machine and recompile. This works on Linux, and also on Windows
using the Cygwin package. See the
"INSTALL" file in the distribution - basically, run a setup script
and then run make.
The distribution has been tested
under various recent Linux distributions (using gcc 3.3,3.4,4.0,4.1), and
Windows XP with Cygwin (using gcc 3.x). If you have the Intel C/C++
compiler installed as well, this can be invoked at runtime.
./addc 1
This should print "T(b) = 2"!