6#if defined(_WIN32) && !defined(_WIN64)
7#define dec_directives_win32
33#ifdef dec_directives_win32
44 INTEGER,
Dimension(:),
Pointer :: cntvect
60 real*8 time0, time1, time4
73 coi_error = max( coi_error,
coidef_numnz( cntvect, 2*nr ) )
77 coi_error = max( coi_error,
coidef_optfile( cntvect,
'mp_rosex.opt' ) )
88#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
89 coi_error = max( coi_error,
coidef_license( cntvect, conopt_license_int_1, conopt_license_int_2, conopt_license_int_3, conopt_license_text) )
92 If ( coi_error .ne. 0 )
THEN
94 write(*,*)
'**** Fatal Error while loading CONOPT Callback routines.'
96 call flog(
"Skipping Solve due to setup errors", 1 )
102 time0 = omp_get_wtime()
104 time1 = omp_get_wtime() - time0
105 If ( coi_error /= 0 )
then
106 call flog(
"Solve 1: Errors encountered during solution", 1 )
107 elseif ( stacalls == 0 .or. solcalls == 0 )
then
108 call flog(
"Solve 1: Status or Solution routine was not called", 1 )
109 elseif ( sstat /= 1 .or. mstat /= 2 )
then
110 call flog(
"Solve 1: Solver and Model Status was not as expected (1,2)", 1 )
111 elseif ( abs(
obj-0.0d0 ) > 0.000001d0 )
then
112 call flog(
"Solve 1: Incorrect objective returned", 1 )
115 maxthread = omp_get_max_threads()
116 coi_error = max( coi_error,
coidef_threadc( cntvect, maxthread ) )
118#if defined (complete)
124 time0 = omp_get_wtime()
126 time1a = omp_get_wtime() - time0
127 If ( coi_error /= 0 )
then
128 call flog(
"Solve 1a: Errors encountered during solution", 1 )
129 elseif ( stacalls == 0 .or. solcalls == 0 )
then
130 call flog(
"Solve 1a: Status or Solution routine was not called", 1 )
131 elseif ( sstat /= 1 .or. mstat /= 2 )
then
132 call flog(
"Solve 1a: Solver and Model Status was not as expected (1,2)", 1 )
133 elseif ( abs(
obj-0.0d0 ) > 0.000001d0 )
then
134 call flog(
"Solve 1a: Incorrect objective returned", 1 )
141 time0 = omp_get_wtime()
143 time2 = omp_get_wtime() - time0
144 If ( coi_error /= 0 )
then
145 call flog(
"Solve 2: Errors encountered during solution", 1 )
146 elseif ( stacalls == 0 .or. solcalls == 0 )
then
147 call flog(
"Solve 2: Status or Solution routine was not called", 1 )
148 elseif ( sstat /= 1 .or. mstat /= 2 )
then
149 call flog(
"Solve 2: Solver and Model Status was not as expected (1,2)", 1 )
150 elseif ( abs(
obj-0.0d0 ) > 0.000001d0 )
then
151 call flog(
"Solve 2: Incorrect objective returned", 1 )
154 if ( maxthread >= 4 )
then
160 time0 = omp_get_wtime()
162 time4 = omp_get_wtime() - time0
163 If ( coi_error /= 0 )
then
164 call flog(
"Solve 4: Errors encountered during solution", 1 )
165 elseif ( stacalls == 0 .or. solcalls == 0 )
then
166 call flog(
"Solve 4: Status or Solution routine was not called", 1 )
167 elseif ( sstat /= 1 .or. mstat /= 2 )
then
168 call flog(
"Solve 4: Solver and Model Status was not as expected (1,2)", 1 )
169 elseif ( abs(
obj-0.0d0 ) > 0.000001d0 )
then
170 call flog(
"Solve 4: Incorrect objective returned", 1 )
174 if (
coi_free( cntvect ) /= 0 )
call flog(
"Error while freeing control vector", 1 )
177 write(*,
"('Time for single thread ',f10.3)") time1
178#if defined (complete)
179 write(*,
"('Time for single thread ',f10.3)") time1a
180 write(*,
"('Time for dual threads ',f10.3)") time2
182 if ( maxthread >= 4 )
then
183 write(*,
"('Time for quad threads ',f10.3)") time4
186 write(*,*)
'End of Extended Rosenbrock Function example. Return code=',coi_error
188 call flog(
"Successful Solve", 0 )
199Integer Function ros_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
200 colsta, rowno, value, nlflag, n, m, nz, &
202#ifdef dec_directives_win32
206 integer,
intent (in) :: n
207 integer,
intent (in) :: m
208 integer,
intent (in) :: nz
209 real*8,
intent (in out),
dimension(n) :: lower
210 real*8,
intent (in out),
dimension(n) :: curr
211 real*8,
intent (in out),
dimension(n) :: upper
212 integer,
intent (in out),
dimension(n) :: vsta
214 integer,
intent (out),
dimension(m) ::
type
215 integer,
intent (in out),
dimension(m) :: esta
217 real*8,
intent (in out),
dimension(m) :: rhs
218 integer,
intent (in out),
dimension(n+1) :: colsta
219 integer,
intent (out),
dimension(nz) :: rowno
220 integer,
intent (in out),
dimension(nz) :: nlflag
221 real*8,
intent (in out),
dimension(nz) ::
value
292Integer Function ros_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
293 n, nz, thread, usrmem )
294#ifdef dec_directives_win32
299 integer,
intent (in) :: n
300 integer,
intent (in) :: rowno
301 integer,
intent (in) :: nz
302 real*8,
intent (in),
dimension(n) :: x
303 real*8,
intent (in out) :: g
304 real*8,
intent (in out),
dimension(n) :: jac
305 integer,
intent (in),
dimension(nz) :: jcnm
307 integer,
intent (in) :: mode
309 integer,
intent (in) :: ignerr
311 integer,
intent (in out) :: errcnt
313 integer,
intent (in) :: thread
323 if ( rowno .eq. 1 )
then
327 if ( mode .eq. 1 .or. mode .eq. 3 )
then
330 g = g + (x(2*i-1)-1.d0)**2 + 1.d2*(x(2*i)-x(2*i-1)**2)**2
336 if ( mode .eq. 2 .or. mode .eq. 3 )
then
340 jac(2*i-1) = 2.d0*(x(2*i-1)-1.d0) - 4.d2*(x(2*i)-x(2*i-1)**2)*x(2*i-1)
341 jac(2*i ) = 2.d2*(x(2*i)-x(2*i-1)**2)
351Integer Function ros_solution( XVAL, XMAR, XBAS, XSTA, YVAL, YMAR, YBAS, YSTA, N, M, USRMEM )
352#ifdef dec_directives_win32
361 INTEGER,
Intent(IN) :: n, m
362 INTEGER,
Intent(IN),
Dimension(N) :: xbas, xsta
363 INTEGER,
Intent(IN),
Dimension(M) :: ybas, ysta
364 real*8,
Intent(IN),
Dimension(N) :: xval, xmar
365 real*8,
Intent(IN),
Dimension(M) :: yval, ymar
366 real*8,
Intent(IN OUT) :: usrmem(*)
369 solcalls = solcalls + 1
integer function std_status(modsta, solsta, iter, objval, usrmem)
integer function std_message(smsg, dmsg, nmsg, llen, usrmem, msgv)
integer function std_errmsg(rowno, colno, posno, msglen, usrmem, msg)
integer(c_int) function coidef_message(cntvect, coi_message)
define callback routine for handling messages returned during the solution process.
integer(c_int) function coidef_solution(cntvect, coi_solution)
define callback routine for returning the final solution values.
integer(c_int) function coidef_status(cntvect, coi_status)
define callback routine for returning the completion status.
integer(c_int) function coidef_readmatrix(cntvect, coi_readmatrix)
define callback routine for providing the matrix data to CONOPT.
integer(c_int) function coidef_errmsg(cntvect, coi_errmsg)
define callback routine for returning error messages for row, column or Jacobian elements.
integer(c_int) function coidef_fdeval(cntvect, coi_fdeval)
define callback routine for performing function and derivative evaluations.
integer(c_int) function coidef_optfile(cntvect, optfile)
define callback routine for defining an options file.
integer(c_int) function coidef_license(cntvect, licint1, licint2, licint3, licstring)
define the License Information.
integer(c_int) function coidef_threadc(cntvect, threadc)
check for thread compatibility.
integer(c_int) function coidef_threadf(cntvect, threadf)
number of threads allowed for simultaneous FDEval calls.
integer(c_int) function coidef_threads(cntvect, threads)
number of threads allowed internally in CONOPT.
integer(c_int) function coidef_numvar(cntvect, numvar)
defines the number of variables in the model.
integer(c_int) function coidef_numcon(cntvect, numcon)
defines the number of constraints in the model.
integer(c_int) function coidef_numnlnz(cntvect, numnlnz)
defines the Number of Nonlinear Nonzeros.
integer(c_int) function coidef_optdir(cntvect, optdir)
defines the Optimization Direction.
integer(c_int) function coidef_numnz(cntvect, numnz)
defines the number of nonzero elements in the Jacobian.
integer(c_int) function coidef_objcon(cntvect, objcon)
defines the Objective Constraint.
integer(c_int) function coi_create(cntvect)
initializes CONOPT and creates the control vector.
integer(c_int) function coi_free(cntvect)
frees the control vector.
integer(c_int) function coi_solve(cntvect)
method for starting the solving process of CONOPT.
integer function ros_solution(xval, xmar, xbas, xsta, yval, ymar, ybas, ysta, n, m, usrmem)
subroutine flog(msg, code)
integer function ros_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
integer function ros_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.
program rosex
Main program. A simple setup and call of CONOPT.