Vectorization of component arrays 
Author Message
 Vectorization of component arrays

Hello,

I have a few questions to specialists in vectorization.
I used compilation for Pentium M specific and added vectorization
information from BuildLog to comments. Let's have a look at simple
but interesting code:

Code:
module Types
    implicit none

    type PointerVector
        real, pointer :: Array(:)
    end type

    type AllocatableVector
        real, allocatable :: Array(:)
    end type

    interface operator(+)
        module procedure SumPointerVectors, SumAllocatableVectors
    end interface operator(+)

    interface operator(.plus.)
        module procedure SumPointerVectorsViaPointers
    end interface operator(.plus.)

    integer, parameter :: N = 1000000

contains
    function SumPointerVectors( vector1, vector2 ) result(result)
        type(PointerVector) result
        type(PointerVector), intent(in) :: vector1, vector2

        allocate( result%Array(Size( vector1%Array )) )

        ! loop was not vectorized: subscript too complex.
        result%Array = vector1%Array + vector2%Array
    end function SumPointerVectors

    function SumPointerVectorsViaPointers( vector1, vector2 )
result(result)
        type(PointerVector) result
        type(PointerVector), intent(in) :: vector1, vector2
        real, pointer :: array(:), array1(:), array2(:)

        allocate( result%Array(Size( vector1%Array )) )

        array => result%Array
        array1 => vector1%Array
        array2 => vector2%Array

        ! LOOP WAS VECTORIZED.
        ! LOOP WAS VECTORIZED.
        array = array1 + array2
    end function SumPointerVectorsViaPointers

    function SumAllocatableVectors( vector1, vector2 ) result(result)
        type(AllocatableVector) result
        type(AllocatableVector), intent(in) :: vector1, vector2

        allocate( result%Array(Size( vector1%Array )) )

        ! loop was not vectorized: subscript too complex.
        result%Array = vector1%Array + vector2%Array
    end function SumAllocatableVectors
end module Types

Code:
program Alloc
    use Types

    implicit none

    type(PointerVector) Vector1Pointer, Vector2Pointer
    type(AllocatableVector) Vector1Allocatable, Vector2Allocatable

    allocate( Vector1Pointer%Array(N), Vector2Pointer%Array(N),&
        Vector1Allocatable%Array(N), Vector2Allocatable%Array(N) )

    ! LOOP WAS VECTORIZED.
    Vector1Pointer%Array = 1

    ! LOOP WAS VECTORIZED.
    Vector2Pointer%Array = 2

    ! LOOP WAS VECTORIZED.
    Vector1Allocatable%Array = 3

    ! LOOP WAS VECTORIZED.
    Vector2Allocatable%Array = 4

    Vector1Pointer = Vector1Pointer + Vector2Pointer

    Vector1Pointer = Vector1Pointer .plus. Vector2Pointer

    ! loop was not vectorized: unsupported loop structure.
    Vector1Allocatable = Vector1Allocatable + Vector2Allocatable

    read *

end program Alloc
1. Why it [technically] impossible to vectorize
result%Array = vector1%Array + vector2%Array
2. Why loop in SumPointerVectorsViaPointers
array = array1 + array2
was vectorized twice while intrinsic arrays would be vectorized only
once?
3. To get vectorization I have to use additional pointers. But I
can't do the same with allocatable components because components
can't have target attribute. That's why there is no
"SumAllocatableVectorsViaPointers" procedure. Is it possible in
fortran 2003? I just would like to use allocatable components, but
don't loose vectorization.
4. Is there another approach to get vectorization in this case?
5. Itanium "doesn't" have vectorization. Why so if it's true?
And what about vectorization in IA-64 in the future?
Any answers will be appreciated.



Thu, 24 Jul 2008 07:10:46 GMT  
 Vectorization of component arrays
I'm not at all an expert in vectorization, so I'll ignore most of this,
but...

Quote:

> I can't do the same with allocatable components because
> components can't have target attribute.

This is not correct.

You cannot specify the target attribute for a component in a derived
type definition. That is true and is probably what is misleading you.
but a component *CAN* have the target attribute. A component has the
target attribute if the thing it was a component of has the target
attribute. So you just specify the target attribute obne "level" higher.

Basically, you can only give the target attribugte to a particular
object. You can't specify the target attribute for all objects of a
given type, which is what specifying the target attribute in a type
definition would amount to.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain



Thu, 24 Jul 2008 08:30:17 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. DEALLOCATE of a derived type array containing pointer array components

2. array components containing arrays

3. Sending Variant Arrays to An Active X Component

4. Component Pascal, pointer to array element?

5. Unconstrained Arrays in components.

6. anonymous arrays not allowed as components

7. Question about anonymous arrays as record components

8. Why no allocatable arrays as structure components?

9. F90 derived type component as array

10. Question about anonymous arrays as record components

11. array of pointers without component name?

12. allocatable array component with intent(out)

 

 
Powered by phpBB® Forum Software