Next: Conclusions and further
Up: Splice and template
Previous: Optimization of the
Some information is given here to explain how Splice can be used in
conjunction with Optimize to automate code generation. Specifically, it is
necessary to keep track of the number of optimization variables introduced during
the optimization process, in order to make appropriate type and dimension
declarations.
In FORTRAN, it is possible to declare all optimization variables to be
the same type by using implicit statement declarations as mentioned
previously. In C this is not possible and there are several strategies which may
be adopted, the simplest of which is outlined below.
- Use the option OptimizeFormat->False. This has the effect of generating the
optimization variables in array form o[i] (the default is a concatenated format
oi which is more memory efficient). This is facilitated by a finishing touch during
formatting, where optimization variables are returned in consecutively numbered form
o[1], o[2],....
- It is difficult to judge in advance exactly how many optimizations will be
performed. Optimize returns a list of the form {optseq,optexpr}.
The dimension of the optimization array corresponds to Length[optseq].
- Use a two-pass Splice. The first pass fills in the body of the procedure
and contains statements such as o(ToExpression["<* arraydim *>"]). The second pass
is used to fill in the array dimension arraydim.