Inlining
In this lab you are going to make an implementation of
complex arrays, using separate arrays for the real- and imaginary parts
(even though Fortran and C99 have support for complex numbers). You
should also implement the elementwise product of the complex vectors in
two different ways and then compare the execution times.
Write a subroutine (void function in C)
subroutine mult ( re_a, im_a, re_b, im_b, re_c, im_c )
that computes the the product a = b * c
where a, b and c are
complex (a = a_re + sqrt(-1) * a_im
etc.). Note that
mult should work with scalars and not arrays (re_a
,
im_a
etc. are scalars).
Create six arrays re_a,im_a,re_b,im_b,re_c
and im_c
of length 20000 and use the routine above to form the product element
by element (use a loop) using mult
. repeat the loop 4000 times
to get accurate measurements.
Important: store mult in a separate file.
Then inline mult, by hand, and run again.
Compare the times and draw conclusions. Explain what happens!
If you write the code in C, the inlined version may be slower (depends on how you write mult), this is most likely an aliasing issue. So, it is easier to get the expected result in Fortran.