Software Archive
Read-only legacy content
17061 Discussions

How does subsectioning work?

michael-a-carr
Beginner
402 Views
My question concerns what happens when I call an external subroutine like this:

COMPLEX :: A(100,100,100)
CALL FFT(A(1,1,5:100:5))

Does Fortran,

1) Create a new array on the stack consisting of the subsection, call the routine with it, then copy the new array back to the original? or

2) Somehow magically pass offset and stride information to the subroutine?

I am trying to build up a 3D-FFT from Intel's optimized 1D-FFT in their Math Performance Library. However, their function doesn't allow for arbitrary offset and stride information to be given to the FFT... so I would have to use Fortran90 array sections to achieve this effect.

Thanks for any help!
0 Kudos
4 Replies
Steven_L_Intel1
Employee
402 Views
It depends. If you've provided an explicit interface for which the corresponding argument is a deferred-shape array (dimensioned as (:,:,:) in this case), AND the actual routine is written that way, then the offset and stride information is "magically passed". Otherwise, a copy on the stack is made, the copy is passed, then the results are copied back to the original array - not the fastest thing in the world.

Steve
0 Kudos
michael-a-carr
Beginner
402 Views
OK, let's try this one then. Let's say I have a big matrix and a small matrix:
REAL :: BigM(100,100,100), SmallM(10,10,10), Coefficient

Then I try this:
BigM(5:15,6:16,10:20) = BigM(5:15,6:16,10:20) + Coefficient * SmallM

Is Fortran smart enough to do this without making a copy on the stack?

How can I determine for myself exactly how Fortran is implementing this matrix operation? Is there some sort of listing file I can generate and check?
0 Kudos
Steven_L_Intel1
Employee
402 Views
Ok, this is a completely different question. The compiler tries hard to not generate a temporary in array operations, but I can't say without trying it whether or not a temp is created for this case.

You can generate a listing with machine code and try to figure it out that way. You'd be looking for a large subtract from ESP (the stack pointer) for the temp.

I'll note that in 6.5A, you can get the compiler to give you a run-time message when an array temp is created for passing an argument - /check:arg_temp_created

Steve
0 Kudos
michael-a-carr
Beginner
402 Views
Well, after rewriting the code to avoid creating the temporary variable, my iterations have gone from 0.4 sec to 0.04 sec... nice! Thanks Steve!
0 Kudos
Reply