Skip to content

Commit

Permalink
added cisgrp to find sparsity of individual functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dalekopera committed Oct 17, 2023
1 parent c00ff62 commit d1a42e8
Show file tree
Hide file tree
Showing 10 changed files with 652 additions and 15 deletions.
10 changes: 10 additions & 0 deletions man/man3/cutest.3
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ evaluate the sparse gradients of the objective function and constraints.
.B cutest_ccfg \fP(unthreaded) and \fBcutest_ccfg_threaded \fP(threaded)
evaluate the values and gradients of the constraints.
.TP
.B cutest_cigr \fP(unthreaded) and \fBcutest_cigr_threaded \fP(threaded)
evaluate the gradient of the objective or an individual constraint.
.TP
.B cutest_cisgr \fP(unthreaded) and \fBcutest_cisgr_threaded \fP(threaded)
evaluate the sparse gradient of the objective or an individual constraint.
.TP
.B cutest_cisgrp \fP(unthreaded) and \fBcutest_cisgrp_threaded \fP(threaded)
evaluate the sparse pattern of the gradient of the objective or an
individual constraint.
.TP
.B cutest_ccfsg \fP(unthreaded) and \fBcutest_ccfsg_threaded \fP(threaded)
evaluate the values and sparse gradients of the constraints.
.TP
Expand Down
101 changes: 101 additions & 0 deletions man/man3/cutest_cisgrp.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'\" e @(#)cutest_cisgrp v1.0 10/2023;
.TH cutest_cisgrp 3M "17 Oct 2023" "CUTEst user documentation" "CUTEst user documentation"
.SH NAME
CUTEST_cisgrp \- CUTEst tool to evaluate the sparsity pattern of
the gradient of a problem function.
.SH SYNOPSIS
.HP 1i
CALL CUTEST_cisgrp( status, n, iprob, nnzg, lg, G_var )
.SH DESCRIPTION
The CUTEST_cisgrp subroutine evaluates the sparsity pattern of
the gradient of either the objective function or a constraint function
of the problem decoded from a SIF file by the script
\fIsifdecoder\fP, in the constrained minimization case.
The problem under consideration
is to minimize or maximize an objective function
.EQ
f(x)
.EN
over all
.EQ
x
.EN
\(mo
.EQ
R sup n
.EN
subject to
general equations
.EQ
c sub i (x) ~=~ 0,
.EN
.EQ
~(i
.EN
\(mo
.EQ
{ 1 ,..., m sub E } ),
.EN
general inequalities
.EQ
c sub i sup l ~<=~ c sub i (x) ~<=~ c sub i sup u,
.EN
.EQ
~(i
.EN
\(mo
.EQ
{ m sub E + 1 ,..., m }),
.EN
and simple bounds
.EQ
x sup l ~<=~ x ~<=~ x sup u.
.EN
The objective function is group-partially separable and
all constraint functions are partially separable.

.LP
.SH ARGUMENTS
The arguments of CUTEST_cisgrp are as follows
.TP 5
.B status \fP[out] - integer
the outputr status: 0 for a succesful call, 1 for an array
allocation/deallocation error, 2 for an array bound error,
3 for an evaluation error,
.TP
.B n \fP[in] - integer
the number of variables for the problem,
.TP 5
.B iprob \fP[in] - integer
the number of the problem function to be considered. If iprob = 0, the
value of the objective function will be evaluated, while if iprob =
i > 0, that of the i-th constraint will be evaluated,
.TP
.B nnzg \fP[out] - integer
the number of nonzeros in G_var,
.TP
.B lg \fP[in] - integer
the declared length of G_var,
.TP
.B G_var \fP[out] - integer
an array whose i-th component is the unique index of a variable within
the sparsity pattern of the gradient.
.LP
.SH AUTHORS
I. Bongartz, A.R. Conn, N.I.M. Gould, D. Orban and Ph.L. Toint
.SH "SEE ALSO"
\fICUTEst: a Constrained and Unconstrained Testing
Environment with safe threads\fP,
N.I.M. Gould, D. Orban and Ph.L. Toint,
Computational Optimization and Applications \fB60\fP:3, pp.545-557, 2014.

\fICUTEr (and SifDec): A Constrained and Unconstrained Testing
Environment, revisited\fP,
N.I.M. Gould, D. Orban and Ph.L. Toint,
ACM TOMS, \fB29\fP:4, pp.373-394, 2003.

\fICUTE: Constrained and Unconstrained Testing Environment\fP,
I. Bongartz, A.R. Conn, N.I.M. Gould and Ph.L. Toint,
ACM TOMS, \fB21\fP:1, pp.123-160, 1995.

sifdecoder(1), cutest_cigr(3), cutest_cisgr(3)
105 changes: 105 additions & 0 deletions man/man3/cutest_cisgrp_threaded.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
'\" e @(#)cutest_cisgrp_threaded v1.0 10/2023;
.TH cutest_cisgrp_threaded 3M "17 Oct 2023" "CUTEst user documentation" "CUTEst user documentation"
.SH NAME
CUTEST_cisgrp_threaded \- CUTEst tool to evaluate the sparsity pattern of
gradient of a problem function.
.SH SYNOPSIS
.HP 1i
CALL CUTEST_cisgrp_threaded( status, n, iprob, nnzg, lg, G_var, thread )
.SH DESCRIPTION
The CUTEST_cisgrp_threaded subroutine evaluates the sparsity pattern of
the gradient of either the objective function or a constraint function
of the problem decoded from a SIF file by the script
\fIsifdecoder\fP, in the constrained minimization case.
The problem under consideration
is to minimize or maximize an objective function
.EQ
f(x)
.EN
over all
.EQ
x
.EN
\(mo
.EQ
R sup n
.EN
subject to
general equations
.EQ
c sub i (x) ~=~ 0,
.EN
.EQ
~(i
.EN
\(mo
.EQ
{ 1 ,..., m sub E } ),
.EN
general inequalities
.EQ
c sub i sup l ~<=~ c sub i (x) ~<=~ c sub i sup u,
.EN
.EQ
~(i
.EN
\(mo
.EQ
{ m sub E + 1 ,..., m }),
.EN
and simple bounds
.EQ
x sup l ~<=~ x ~<=~ x sup u.
.EN
The objective function is group-partially separable and
all constraint functions are partially separable.

.LP
.SH ARGUMENTS
The arguments of CUTEST_cisgrp_threaded are as follows
.TP 5
.B status \fP[out] - integer
the outputr status: 0 for a succesful call, 1 for an array
allocation/deallocation error, 2 for an array bound error,
3 for an evaluation error, 4 for an out-of-range thread,
.TP
.B n \fP[in] - integer
the number of variables for the problem,
.TP 5
.B iprob \fP[in] - integer
the number of the problem function to be considered. If iprob = 0, the
value of the objective function will be evaluated, while if iprob =
i > 0, that of the i-th constraint will be evaluated,
.TP
.B nnzg \fP[out] - integer
the number of nonzeros in G_var,
.TP
.B lg \fP[in] - integer
the declared length of G_var,
.TP
.B G_var \fP[out] - integer
an array whose i-th component is the unique index of a variable within
the sparsity pattern of the gradient.
.TP
.B thread \fP[in] - integer
thread chosen for the evaluation; threads are numbered
from 1 to the value threads set when calling CUTEST_csetup_threaded.
.LP
.SH AUTHORS
I. Bongartz, A.R. Conn, N.I.M. Gould, D. Orban and Ph.L. Toint
.SH "SEE ALSO"
\fICUTEst: a Constrained and Unconstrained Testing
Environment with safe threads\fP,
N.I.M. Gould, D. Orban and Ph.L. Toint,
Computational Optimization and Applications \fB60\fP:3, pp.545-557, 2014.

\fICUTEr (and SifDec): A Constrained and Unconstrained Testing
Environment, revisited\fP,
N.I.M. Gould, D. Orban and Ph.L. Toint,
ACM TOMS, \fB29\fP:4, pp.373-394, 2003.

\fICUTE: Constrained and Unconstrained Testing Environment\fP,
I. Bongartz, A.R. Conn, N.I.M. Gould and Ph.L. Toint,
ACM TOMS, \fB21\fP:1, pp.123-160, 1995.

sifdecoder(1), cutest_cigr(3), cutest_cisgr(3), cutest_setup_threaded(3M).
40 changes: 40 additions & 0 deletions src/test/ctest.f90
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ PROGRAM CUTEST_test_constrained_tools
IF ( status /= 0 ) GO TO 900
CALL WRITE_SG( out, G_ne, l_g, G_val, G_var )

! and its sparsity pattern

WRITE( out, "( ' CALL CUTEST_cisgrp for the objective function' )" )
CALL CUTEST_cisgrp( status, n, icon, G_ne, l_g, G_var )
IF ( status /= 0 ) GO TO 900
CALL WRITE_G_sparsity_pattern( out, G_ne, l_g, G_var )

! compute the number of nonzeros in the sparse Jacobian

WRITE( out, "( ' CALL CUTEST_cdimsj' )" )
Expand Down Expand Up @@ -389,6 +396,13 @@ PROGRAM CUTEST_test_constrained_tools
IF ( status /= 0 ) GO TO 900
CALL WRITE_SJI( out, icon, Ji_ne, n, Ji, J_var )

! and its sparsity pattern

WRITE( out, "( ' CALL CUTEST_cisgrp for a constraint' )" )
CALL CUTEST_cisgrp( status, n, icon, G_ne, l_g, G_var )
IF ( status /= 0 ) GO TO 900
CALL WRITE_G_sparsity_pattern( out, G_ne, l_g, G_var )

! compute the dense Hessian value

WRITE( out, "( ' CALL CUTEST_cdh' )" )
Expand Down Expand Up @@ -1037,6 +1051,32 @@ SUBROUTINE WRITE_JT_dense( out, n, m, l_j2_1, l_j2_2, J2_val )
END DO
END SUBROUTINE WRITE_JT_dense

SUBROUTINE WRITE_G_sparsity_pattern( out, G_ne, l_g, G_ind )
INTEGER :: l_g, G_ne, out
INTEGER, DIMENSION( l_g ) :: G_ind
INTEGER :: i
WRITE( out, "( ' * G(sparse)' )" )
WRITE( out, "( ' * ', 5( ' ind' ) )" )
DO i = 1, G_ne, 5
IF ( i + 4 <= G_ne ) THEN
WRITE( out, "( ' * ', 5( I7 ) )" ) &
G_ind( i ), G_ind( i + 1 ), G_ind( i + 2 ), G_ind( i + 3 ), &
G_ind( i + 4 )
ELSE IF ( i + 3 <= G_ne ) THEN
WRITE( out, "( ' * ', 4( I7 ) )" ) &
G_ind( i ), G_ind( i + 1 ), G_ind( i + 2 ), G_ind( i + 3 )
ELSE IF ( i + 2 <= G_ne ) THEN
WRITE( out, "( ' * ', 3( I7 ) )" ) &
G_ind( i ), G_ind( i + 1 ), G_ind( i + 2 )
ELSE IF ( i + 1 <= G_ne ) THEN
WRITE( out, "( ' * ', 2( I7 ) )" ) &
G_ind( i ), G_ind( i + 1 )
ELSE
WRITE( out, "( ' * ', I7 )" ) G_ind( i )
END IF
END DO
END SUBROUTINE WRITE_G_sparsity_pattern

SUBROUTINE WRITE_H_sparsity_pattern( out, H_ne, l_h, H_row, H_col )
INTEGER :: l_h, H_ne, out
INTEGER, DIMENSION( l_h ) :: H_row, H_col
Expand Down
45 changes: 42 additions & 3 deletions src/test/ctest_threaded.f90
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ PROGRAM CUTEST_test_constrained_tools
INTEGER :: equality_constraints, linear_constraints
INTEGER :: nnz_vector, nnz_result
INTEGER :: CHP_ne, l_chp, l_j2_1, l_j2_2, l_j, icon, iprob
REAL ( KIND = wp ) :: f, ci, x0
REAL ( KIND = wp ) :: f, ci, y0
LOGICAL :: grad, byrows, goth, gotj
LOGICAL :: grlagf, jtrans
CHARACTER ( len = 10 ) :: p_name
Expand Down Expand Up @@ -243,6 +243,13 @@ PROGRAM CUTEST_test_constrained_tools
IF ( status /= 0 ) GO TO 900
CALL WRITE_SG( out, G_ne, l_g, G_val, G_var )

! and its sparsity pattern

WRITE( out, "( ' CALL CUTEST_cisgrp for the objective function' )" )
CALL CUTEST_cisgrp_threaded( status, n, icon, G_ne, l_g, G_var, thread )
IF ( status /= 0 ) GO TO 900
CALL WRITE_G_sparsity_pattern( out, G_ne, l_g, G_var )

! compute the number of nonzeros in the sparse Jacobian

WRITE( out, "( ' CALL CUTEST_cdimsj' )" )
Expand Down Expand Up @@ -393,6 +400,13 @@ PROGRAM CUTEST_test_constrained_tools
IF ( status /= 0 ) GO TO 900
CALL WRITE_SJI( out, icon, Ji_ne, n, Ji, J_var )

! and its sparsity pattern

WRITE( out, "( ' CALL CUTEST_cisgrp for a constraint' )" )
CALL CUTEST_cisgrp_threaded( status, n, icon, G_ne, l_g, G_var, thread )
IF ( status /= 0 ) GO TO 900
CALL WRITE_G_sparsity_pattern( out, G_ne, l_g, G_var )

! compute the dense Hessian value

WRITE( out, "( ' CALL CUTEST_cdh' )" )
Expand Down Expand Up @@ -494,11 +508,10 @@ PROGRAM CUTEST_test_constrained_tools
y0 = 2.0_wp
WRITE( out, "( ' CALL CUTEST_cshj' )" )
CALL CUTEST_cshj_threaded( status, n, m, X, y0, Y, &
H_ne, l_h, H_val, H_row, H_col )
H_ne, l_h, H_val, H_row, H_col, thread )
IF ( status /= 0 ) GO TO 900
CALL WRITE_H_sparse( out, H_ne, l_h, H_val, H_row, H_col )


! compute the sparse Hessian value of the objective or a constraint

iprob = 0
Expand Down Expand Up @@ -1049,6 +1062,32 @@ SUBROUTINE WRITE_JT_dense( out, n, m, l_j2_1, l_j2_2, J2_val )
END DO
END SUBROUTINE WRITE_JT_dense

SUBROUTINE WRITE_G_sparsity_pattern( out, G_ne, l_g, G_ind )
INTEGER :: l_g, G_ne, out
INTEGER, DIMENSION( l_g ) :: G_ind
INTEGER :: i
WRITE( out, "( ' * G(sparse)' )" )
WRITE( out, "( ' * ', 5( ' ind' ) )" )
DO i = 1, G_ne, 5
IF ( i + 4 <= G_ne ) THEN
WRITE( out, "( ' * ', 5( I7 ) )" ) &
G_ind( i ), G_ind( i + 1 ), G_ind( i + 2 ), G_ind( i + 3 ), &
G_ind( i + 4 )
ELSE IF ( i + 3 <= G_ne ) THEN
WRITE( out, "( ' * ', 4( I7 ) )" ) &
G_ind( i ), G_ind( i + 1 ), G_ind( i + 2 ), G_ind( i + 3 )
ELSE IF ( i + 2 <= G_ne ) THEN
WRITE( out, "( ' * ', 3( I7 ) )" ) &
G_ind( i ), G_ind( i + 1 ), G_ind( i + 2 )
ELSE IF ( i + 1 <= G_ne ) THEN
WRITE( out, "( ' * ', 2( I7 ) )" ) &
G_ind( i ), G_ind( i + 1 )
ELSE
WRITE( out, "( ' * ', I7 )" ) G_ind( i )
END IF
END DO
END SUBROUTINE WRITE_G_sparsity_pattern

SUBROUTINE WRITE_H_sparsity_pattern( out, H_ne, l_h, H_row, H_col )
INTEGER :: l_h, H_ne, out
INTEGER, DIMENSION( l_h ) :: H_row, H_col
Expand Down
Loading

0 comments on commit d1a42e8

Please sign in to comment.