Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

A way to avoid IF statements.

AT
Beginner
123 Views

Imagine I have following do loop

do i = 1,imax
    if(period) then
        call g_period()
    else
        call g()
    endif
enddo

I have this several places and sometimes several If loops within a do loop which checks whether I should call function X or Y. What is common for all this is that period is defined in the input file, and it is unchanged during the whole run time. Is there a way to avoid the if statements - because my speed is killed by all the checking stuff? Although, I want to maintain the generic why of being able to run the program one time with period = true and other times with period=false.

I thought maybe this could be solved with the concept of polymorphism or similar?

0 Kudos
1 Solution
Steve_Lionel
Black Belt Retired Employee
123 Views

I'd suggest a procedure pointer that you assign at the beginning and then just call through the pointer.

View solution in original post

1 Reply
Steve_Lionel
Black Belt Retired Employee
124 Views

I'd suggest a procedure pointer that you assign at the beginning and then just call through the pointer.

View solution in original post

Reply