Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

fortran pointer seem to work slowly (my IVF is v11.0 )

markailee
Beginner
691 Views
I am student on Fluid dynamics. I am writing large code to solve some equations. Aiming at writing a more general code, I use some advanced feature of fortran, such as type, pointer and allocatable arrays. However, I find the program would become much more slow when I use features. Maybe it's my faults.
My Original global variables:
module globalvar
real,allocatable :: a(:,:,:),b(:,:,:)
end module


Because I need to store information in one block, which has different size from another block,
the new global variables are designed as follows:
module globalvar
type MyStruct
real,allocatable :: a(:,:,:),b(:,:,:)
end type MyStruct

type(MyStruct),allocatable :: AStruct(:)
real,pointer :: a(:,:,:), b(:,:,:)
end module

!! using the global variable in a procedure, avoid using AStruct(i)%a(i,j,k), I put a
!! pointer a=> AStruct(i)%a
subroutine AProcedure(i)
a=> AStruct(i)%a
b=> AStruct(i)%b
...
end subroutine


The new code works exactly right, execept that it works much more slowly than the Original one, about 1/2 the speed as original one. I thougt it's the problem of pointer or type which degrade its effiency.
My Question is: will my program slow down much when using the pointer? How to speed it up?

By the way, I heard the inter fortran 11.0 contains the object-oriented programming. Can I put the procedure inside the type that I can get rid of the pointers? Is there a handbook on that?

Thanks a lot!
0 Kudos
5 Replies
Steven_L_Intel1
Employee
691 Views

It's hard to tell from what you have written here. I'd guess that the compiler is making temporary array copies, but you have not shown any code where that would occur.

If you want to use the object-oriented features, such as polymorphism, you need 11.1 - and the latest update would be best. Type-bound procedures are supported in 11.1. There are several good textbooks on Fortran 2003 available.
0 Kudos
Andrew_Smith
Valued Contributor I
691 Views
Untitled Page

Not sure about the speed question, I will leave that to others.

Regarding type bound procedures, yes this is possible in IVF 11.1. It wont solve the referencing problem because the Fortran standard requires the object to be referenced, unlike most other object oriented languages which allow the shortcut of referencing componts directly within the object scope.

e.g. VB:

class x

public y as double, z as double
public function sum() as double

return y*z

end function

end class

Fortran:

module someModule
implicit none
type x

real(8) y, z
contains

procedure sum

end type
contains

real(8) function sum(a)

type (x) a
sum = a%y*a%z

end function

end module

OO Fortran takes twice as many lines to do the same thing as VB and is less easy to understand.

0 Kudos
markailee
Beginner
691 Views
Quoting - Andrew Smith
Untitled Page

Not sure about the speed question, I will leave that to others.

Regarding type bound procedures, yes this is possible in IVF 11.1. It wont solve the referencing problem because the Fortran standard requires the object to be referenced, unlike most other object oriented languages which allow the shortcut of referencing componts directly within the object scope.

e.g. VB:

class x

public y as double, z as double
public function sum() as double

return y*z

end function

end class

Fortran:

module someModule
implicit none
type x

real(8) y, z
contains

procedure sum

end type
contains

real(8) function sum(a)

type (x) a
sum = a%y*a%z

end function

end module

OO Fortran takes twice as many lines to do the same thing as VB and is less easy to understand.



I see. In OO Fortran, the procedure inside the type cannot directly use the data inside the type like other OOP language.
Maybe I need to find some other ways to get rid of my pointers.

Thanks, Mr. Smith.
0 Kudos
Steven_L_Intel1
Employee
691 Views

Yes, the type-bound procedure gets passed the derived type object implicitly unless you say NOPASS. In Andrew's example, that is "a".
0 Kudos
Reply