Inlining
In Fortran double precision complex (i.e. where both the real part and the imaginary part are double precision numbers) is a built-in type. C does not have any complex type at all. A portable way of writing programs using C is to have separate arrays for the real- and imaginary parts and to implement complex arithmetic as procedures. It does not seem unreasonable, however, that this may slow things down, how much is what you are going to find out next:
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). Do the same even if you are using Fortran
90.
create six arrays re_a,im_a,re_b,im_b,re_c
and im_c
of length 10000 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.
Now repeat the same thing but store mult in the same file as the main program.
Compare the times and draw conclusions. Explain what happens!