next up previous contents
Next: class LocBlocksIndex Up: class Index Previous: Methods

Translation of overall construct by macro expansion

The most naive translation of the overall construct is by using the standard C preprocessor to expand the macros

  #define OVERALL(i) for(apgStack.push(&apg), apg.restrict(i.dim), \
                         i.begin() ; i.test() ; i.next())

  #define ALLOVER(i) apgStack.pop(&apg)

Effectively, the loop

  OVERALL(i) {
    ...
  } ALLOVER(i) ;

becomes

  apgStack.push(&apg) ;
  apg.restrict(i.dim) ;
  for(i.begin() ; i.test() ; i.next()) {
    ...
  }
  apgStack.pop(&apg) ;

We moved the apg manipulations (see section 2.7) outside the for construct to improve readability. The begin(), test() and next() members of Index are used in the for loop to enumerate the local elements of the range.

This translation is trivial to implement, but it is very inefficient. First we have the overhead of the calls to the iterator members of Index in every iteration. Secondly (probably even more seriously) every array or range subscripting operation in the body of the loop involves calls to member functions. The overhead of all these library calls can easily downgrade performance by an order of magnitude or more relative to a comparable sequential for loop.



Guansong Zhang
Fri Oct 9 12:29:23 EDT 1998