HP MLIB User's Guide Vol. 1 7th Ed.

Chapter 2 Basic Vector Operations 101
List selected vector elements SLSTxx/DLSTxx/ILSTxx/CLSTxx/ZLSTxx
Output nindx If n 0, then nindx = 0. Otherwise, nindx is the
number of elements of x that satisfy the relationship
with a specified by the subprogram name.
indx Array filled with the list of indices i of the elements x
i
of x that satisfy the relationship with a specified by the
subprogram name. Only the first nindx elements of
indx are changed. Recall that x
i
is stored in
x((i1)×|incx|+1).
Notes These subprograms are sometimes useful for optimizing a loop containing an IF
statement. Refer to “Example 2” on page 101.
Fortran
Equivalent
SUBROUTINE SLSTEQ (N,X,INCX,A,NI,INDX)
REAL*4 X(*),A
INTEGER*4 INDX(*)
INCXA = ABS ( INCX )
IX = 1
NI = 0
DO 10 I = 1, N
IF ( X(IX) .EQ. A ) THEN
NI = NI + 1
INDX(NI) = I
END IF
IX = IX + INCXA
10 CONTINUE
RETURN
END
Example 1 Build a list of the indices of the positive elements of a REAL*8 vector x, where x
is a vector 10 elements long stored in a one-dimensional array X of dimension
20.
INTEGER*4 N,INCX,NINDX,INDX(20)
REAL*8 A,X(20)
N = 10
INCX = 1
A = 0.0D0
CALL DLSTGT (N,X,INCX,A,NINDX,INDX)
Example 2 Optimize the following program segment, where the THEN clause of the IF
statement is much more likely than the ELSE clause.