## `generate::Macrofort::setOptimizedOption` -- sets optimization

#### Introduction

`Mac::setOptimizedOption` (where `Mac:=generate::Macrofort`) is a switch which allows MuPAD's optimizer `generate::optimize` to be applied to the expressions and arrays of the FORTRAN code generated by `Mac::genFor`.

#### Call(s)

`generate::Macrofort::setOptimizedOption(b)`

#### Parameters

`b` | - | TRUE or FALSE.

#### Returns

the void object of domain type `DOM_NULL`

#### Side Effects

Optimized FORTRAN code if the setting is TRUE.

#### Related Functions

`generate::optimize`, `generate::Macrofort::init`, `generate::Macrofort::genFor`

#### Details

- `Mac::setOptimizedOption` (where `Mac:=generate::Macrofort`) is used with `Mac::genFor` and `Mac::init` (see these programs for more details) and adjusts Macrofort (internal) the settings for optimization. The default setting for this variable made by an initial call to `Mac::init` is FALSE i.e. no optimization for the resulting FORTRAN code.

  First, to understand how the optimizer works, consult `generate::optimize`. When a boolean value of TRUE is injected to `Mac::setOptimizedOption`, the `Mac::genFor` procedure tailors its FORTRAN code from the results of the optimizer. In the case of arrays, the input array is converted into a computational sequence in the form of a list before submission to the optimizer to facilitate the generation of readable FORTRAN code.

#### Example 1

    >> Mac := generate::Macrofort:
       Mac::init():

Note that the default mode for the optimizer set by generate::Macrofort::init is FALSE (meaning off).

    >> Mac::openOutputFile("test.f"):
       Mac::genFor(["equal", [[a, 1 + sin(t)],
                              [b, cos(t) + sin(t)], [c, 1 + cos(t)]]]):
       Mac::closeOutputFile();
       delete a,b,c,t:

Switch the optimizer and send output to a different file.

    >> Mac::openOutputFile("test2.f"):
       Mac::setOptimizedOption(TRUE):
       Mac::genFor(["equal", [[a, 1 + sin(t)],
                              [b, cos(t) + sin(t)], [c, 1 + cos(t)]]]):
       Mac::closeOutputFile():
       delete a, b, c, t:

The output file `test.f` is:

                a = sin(t)+1
                b = cos(t)+sin(t)
                c = cos(t)+1

The ``optimized'' output file `test2.f` is:

                t1 = sin(t)
                a = t1+1
                t2 = cos(t)
                b = t1+t2
                c = t2+1

This example only shows how to call `Mac::setOptimizedOption` but does not show the advantages given by optimization. To appreciate these advantages, see the help-files of `generate::optimize` and `Mac::genFor` for a more comprehensive list of examples.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000