I’ve been enjoying the discussions in this discourse group and often learning from them!
I was wondering about something. In a code, I had to solve efficiently a bunch of tri-diagonal systems, and I have two different subroutines depending on the boundary conditions. The relevant part of the code looks like this (I guess it is not so important to give more detail):
if(bcz(0)//bcz(1).eq.'PP') then call gaussel_periodic(n(1),n(2),n(3)-q,a,b,c,lambdaxy,pz) else call gaussel( n(1),n(2),n(3)-q,a,b,c,lambdaxy,pz) endif
I somehow find it a bit more elegant to have a procedure pointer at the beginning of the calling subroutine that, depending on the type of boundary condition, would point to the right subroutine. Something like:
procedure (), pointer :: tridsolve => null() if(bcz(0)//bcz(1).eq.'PP') then tridsolve => gaussel_periodic else tridsolve => gaussel endif (...) call tridsolve(n(1),n(2),n(3)-q,a,b,c,lambdaxy,pz)
I remember that I did not implement things like this because I was concerned about losing performance; perhaps I read somewhere that I could lose some room for e.g. inline optimization if I would implement things in this way… Do you see a significant disadvantage in terms of performance/optimization when using the second approach?