conditional calling the subroutines

conditional calling the subroutines

Portrait de wally w.

 Hi all 

      I am trying to compile a test program pasted below, using the conditional compilation directive.

      But it failed,  Could anyone tell me where wrong is the program?

  

Module param
!DEC$ IF DEFINED (d1)
integer,parameter :: nc1 = 10
real*8 dx1
!DEC$ ELSE
integer,parameter :: nc1 = 10
integer,parameter :: nc2 = 10
real*8 dx1
real*8 dx2
!DEC$ ENDIF
end module

program main
use param
implicit none
!DEC$ IF DEFINED (d1)
call sub1
!DEC$ ELSE
call sub1
call sub2
!DEC$ ENDIF
end program

subroutine sub1
use param
implicit none
dx1 = 1.d0/ nc1
end subroutine

subroutine sub2
use param
implicit none
dx2 = 1.d0/ nc2
end subroutine

5 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de IanH

If d1 is defined you don't declare the nc2 and dx2 module variables, but they are still referenced in sub2?

Portrait de jimdempseyatthecove

When d1 is defined, sub2 is invalid (uses undefined variables). Conditionalize it out.
Jim Dempsey

www.quickthreadprogramming.com
Portrait de wally w.

Dear all,
Thank you for your early reply.
As you said, I modified this test program as follows:

!DEC$ IF DEFINED (d1)
subroutine sub1
use param
implicit none
dx1 = 1.d0/ nc1
end subroutine
!DEC$ END IF

!DEC$ IF DEFINED (d2)
subroutine sub2
use param
implicit none
dx2 = 1.d0/ nc2
end subroutine
!DEC$ END IF

Is there any other way to do so?

Portrait de Tim Prince

ifort supports #ifdef ... #endif with /fpp option. Don't know if that's what you mean by "any other way."

Connectez-vous pour laisser un commentaire.