SLSTxx/DLSTxx/ILSTxx/CLSTxx/ZLSTxx

List selected vector elements

INTEGER*4

I,N

REAL*8

A,B,D,DLIM,R

REAL*8

F(20000),X(20000),Y(20000),Z(20000)

A = ...

 

B = ...

 

DLIM = ...

 

R = ...

 

N = 20000

 

DO 10 I = 1, N

D = SQRT( X(I)**2 + Y(I)**2 + Z(I)**2 ) - R

IF ( D .GT. DLIM ) THEN

F(I) = A * EXP( B * D )

ELSE

CALL FORCE (D,F(I))

END IF

10 CONTINUE

Change D to an array and introduce array INDX to hold the indices corresponding to the ELSE clause. Split the body of the DO loop into two parts. The first part corresponds to the body of the loop before the IF statement and the THEN clause. It fully optimizes, so, even though it computes a few more exponentials than the original code, it is still considerably faster. DLSTLE is then called to determine the indices for which the ELSE clause must be executed, and the second DO loop executes the ELSE clause for those indices. The resulting program segment is:

INTEGER*4 I,J,N,NINDX,INDX(20000)

REAL*8 A,B,DLIM,R

REAL*8 D(20000),F(20000),X(20000),Y(20000),Z(20000)

A = ...

B = ...

DLIM = ...

R = ...

N = 20000

DO 10 I = 1, N

D(I) = SQRT( X(I)**2 + Y(I)**2 + Z(I)**2 ) - R

F(I) = A * EXP( B * D(I) )

10CONTINUE

CALL DLSTLE (N,D,1,DLIM,NINDX,INDX) DO 20 J = 1, NINDX

I = INDX(J)

CALL FORCE (D(I),F(I)) 20 CONTINUE

102HP MLIB User’s Guide