Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28630 Discussions

Revised: How to optimize this simple code?

Nan_Deng
Beginner
262 Views

The post I made yesterday was not clear on many aspects as gurus have pointed out. The following is the code section inmy program:

FUNCTION
FIND_LOC8(X,VAL,N)
INTEGER*8, INTENT(IN), DIMENSION(:) :: X
INTEGER*8, INTENT(IN) :: VAL
INTEGER*8 :: FIND_LOC8
INTEGER*8 :: I, N
! N = SIZE(X)
DO I=1, N
IF(X(I)==VAL) THEN
FIND_LOC8 = I
RETURN
END IF
END DO
FIND_LOC8 = 0
RETURN
END FUNCTION FIND_LOC8

My problem is, this simple function is inside 3-level of do-loops. As the loops become bigger, the time spent on this little function increase tramendously.

Can this simple code be optimized/vectorized/parallelized? Or, is there any more efficient internal routine/command that performs the same function but faster?


0 Kudos
2 Replies
mecej4
Honored Contributor III
262 Views
I believe that the question was answered satisfactorily in your previous thread on this topic, "How to optimize this simple code". It is expected on grounds of common courtesy that the originator of a question should read the answers given before posting a minor variation of the same question and starting a new thread.

By creating a new function such as FIND_LOC8 to determine the matching index, whereas the former code had inline Fortran code, you are making it more difficult for the compiler to optimize.
0 Kudos
Nan_Deng
Beginner
262 Views
By creating a new function such as FIND_LOC8 to determine the matching index, whereas the former code had inline Fortran code, you are making it more difficult for the compiler to optimize

So instead ofmaking the comparison aseparate function, make the comparison inline should make the conde runfaster?

0 Kudos
Reply