- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, the type-bound procedure gets passed the derived type object implicitly unless you say NOPASS. In Andrew's example, that is "a".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page