Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion efficiency of arrays memory allocation of derived type with type-bound procedures
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
glen herrmannsfeldt  
View profile  
 More options Oct 24 2012, 3:42 am
Newsgroups: comp.lang.fortran
From: glen herrmannsfeldt <g...@ugcs.caltech.edu>
Date: Wed, 24 Oct 2012 07:42:40 +0000 (UTC)
Local: Wed, Oct 24 2012 3:42 am
Subject: Re: efficiency of arrays memory allocation of derived type with type-bound procedures

Stefano Zaghi <stefano.za...@gmail.com> wrote:
> I am trying to figure out if the use of type-bound procedures could
> compromise the efficiency of memory allocation.
> Suppose you have e derived type like the following:
> type, public:: Type_Vector_Eff
>  sequence
>  real:: x,y,z
> end type Type_Vector_Eff
> type(Type_Vector_Eff):: vec_eff(1:1000,1:1000)
> Because of the presence of "sequence" statement the 2D array
> "vec_eff" has its own elements allocated sequentially thus the
> loops operations over them are efficient.

What do you mean by allocated sequentially?

Without SEQUENCE the compiler is allowed to rearrange structure
members, so it might come out Y,Z,X or Z,X,Y, though it is
pretty hard to see why it would do that.

In the case of members of different size, it might save padding,
but not in this case.

There are cases where there is an efficiency (mostly cache)
difference between array of structures and structure of
arrays, though as far as I know the compiler normally
won't do that.

(There is a story about a C compiler doing it for a SPEC
benchmark program, though it isn't supposed to be done
in C, either.)

> Now suppose you want to modify the above derived type and introduce
> some type-bound procedures. In this case the "sequence"
> statement is not legal:
> type, public:: Type_Vector
>  real:: x,y,z
>  contains
>    procedure:: init
> end type Type_Vector
> type(Type_Vector):: vec(1:1000,1:1000)
> Now how are allocated the elements of "vec"?

I would be surprised to see it change.

> Is it possible that its elements are not sequentially allocated
> thus the access to them is not efficient into loops operations?

The structure is small enough that I would be surprised to
see a difference, but it is possible.

> Is it possible that the type-bound procedure "init" makes not
> efficient the access to the memory of array "vec"?

Possible, yes, but not likely. But you don't say how you are
accessing the array, so it is hard to say more.

-- glen


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.