처음부터 일부 시뮬레이션 코드를 작성 중이며 fortran에서 OOP 기능을 사용하여 유지 관리하기 쉽도록하려고합니다. Fortran 워크샵에서 코드의 성능이 중요한 부분에서 OOP 기능을 사용할 때는주의해야한다는 것을 배웠습니다.파생 형식의 다형성 구성 요소 유형 바인딩 절차
내 간단한 첫 번째 방법 (경고 무시)은 다음과 같습니다. 배경은 상호 작용 가능성을 필요로하는 시스템 에너지의 계산입니다. 이 잠재력을 위해 추상적 인 유형 (잠재력)을 사용합니다. 모든 사용자는 자신의 잠재력을 확장 기능으로 추가하고 잠재력을 할당하는 데 사용되는 키워드를 정의 할 수 있습니다. 주 프로그램의 에너지 계산은 변경되지 않습니다.
module system_mod
implicit none
type, abstract :: potential
contains
procedure(init), deferred :: init
procedure(eval), deferred :: eval
end type
type, extends(potential) :: my_potential
! some parameters
contains
procedure :: init => init_my_potential
procedure :: eval => eval_my_potential
end type
! omitted: other extensions of 'potential'
! and abstract interface of potential
type :: system
! some components
class(potential), allocatable :: pair_potential
contains
procedure :: init ! subroutine, which is used to allocate pair_potential depending on a passed keyword
end type
contains
! implementation of all routines
end module system_mod
program main
use system_mod, only: potential, my_potential, system
implicit none
character(len=3) :: keyword !
integer :: i
real :: coordinates(n,3) ! n is a huge number
real :: energy, system_energy
type(system) :: test_system
call test_system%init (keyword)
! keyword tells which of the extensions of 'potential' is allocated
do i = 1, n
energy = test_system%pair_potential%eval (...)
system_energy = system_energy + energy
end do
end program
나는 성능에 관한 내 주요 문제는 내가 컴파일러가 실제로 컴파일시에 수행하고있는 것을 런타임에 수행되는 것을 얻을 수 없다는 것입니다 생각합니다.
그래서 제 질문은 다음과 같습니다
- 방법 또는 때 컴파일러 체크, '평가'의 인스턴스를 사용할 수 있습니까?
- 키워드가 컴파일 타임에 알려지면 루프 반복마다 유형 검사가 있습니까?
- 예를 들어 주 프로그램에서 프로 시저 포인터를 사용하고 처음에이를 'eval'절차에 연결하는 것이 더 좋습니까?
미리 감사드립니다.