COMPILER TECHNIQUES FOR MATLAB PROGRAMS ... - CiteSeerX
COMPILER TECHNIQUES FOR MATLAB PROGRAMS ... - CiteSeerX
COMPILER TECHNIQUES FOR MATLAB PROGRAMS ... - CiteSeerX
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
S1: if (A D1 .ne. B D1 .or. A D2 .ne. B D2) then<br />
S2: if (ALLOCATED(A)) DEALLOCATE(A)<br />
S3: A D1 = B D1<br />
S4: A D2 = B D2<br />
S5: ALLOCATE(A(A D1,A D2))<br />
S6: end if<br />
S7: A = B + 0.5<br />
Figure 3.8: Example of shadow variables for shape.<br />
the form A=B+0.5 were unknown at compile time, the compiler would generate the code<br />
presented in Figure 3.8, which uses shadow variables A D1, A D2, B D1, and B D2, to<br />
store the run-time information about the dimensions of A and B. These shadow variables<br />
are initialized to zero at the beginning of the program. This gure shows the general form<br />
for the dynamic allocation. However, only the necessary statements are generated. So, for<br />
example, if this is the rst denition of variable A, statements S1 and S2 are not generated 5 .<br />
Dynamic rank inference is also generated for the correct execution of the code. Consider<br />
again a multiplication of two variables being assigned to a third variable: c = a b. Suppose<br />
that both variables a and b are of type real, but have unknown shape at the end of<br />
the static analysis phase.<br />
The simple solution of generating a single matrix multiplication statement for this expression<br />
(e.g., c = MATMUL(a,b) ) is not possible due to performance and conformability<br />
considerations. Thus, dynamic rank inference is performed in order to select the appropriate<br />
functions to perform the operations according to the rank of a and b. The resulting<br />
Fortran 90 code would be the code sequence 6 shown in Figure 3.9.<br />
The shadow variables of a and b are used to infer the rank of the variables during<br />
execution time. The shadow variable for c is updated according to the operation that is<br />
5 If this denition occurs inside a loop, it is not considered the rst denition because there will be an<br />
articial assignment tonull outside the loop, as described in Section 4.2.2.<br />
6 The compiler assumes the correctness of the original program. It uses the BLAS routines DDOT, DGEMV,<br />
and DGEMM for dot-product, matrix-vector multiplication, and matrix multiplication respectively.<br />
29