14 Integer,
Parameter ::
np = 50
15 Integer,
Parameter ::
nv = 2*
np
16 Integer,
Parameter ::
no =
np-1
17 Integer,
Parameter ::
nd =
np*(
np-1)/2
53 INTEGER,
Dimension(:),
Pointer :: cntvect
56 real*8 time0, time1, time2, time4
57 Integer :: iter1, iter2, iter4
59 Logical :: same12, same14, same24
109 coi_error = coi_createfort( cntvect )
119 coi_error = max( coi_error,
coidef_optfile( cntvect,
'mp_polygon2.opt' ) )
130#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
131 coi_error = max( coi_error,
coidef_license( cntvect, license_int_1, license_int_2, license_int_3, license_text) )
134 If ( coi_error .ne. 0 )
THEN
136 write(*,*)
'**** Fatal Error while loading CONOPT Callback routines.'
138 call flog(
"Skipping Solve due to setup errors", 1 )
148 write(*,*)
'End of Polygon example with one thread. Return code=',coi_error
150 If ( coi_error /= 115 )
then
151 call flog(
"ThreadC = 1 and ThreadS = 2 did not give error return 115.", 1 )
158 time0 = omp_get_wtime()
160 time1 = omp_get_wtime() - time0
163 write(*,*)
'End of Polygon example with 1 threads. Return code=',coi_error
165 If ( coi_error /= 0 )
then
166 call flog(
"Single thread: Errors encountered during solution", 1 )
167 elseif ( stacalls == 0 .or. solcalls == 0 )
then
168 call flog(
"Single thread: Status or Solution routine was not called", 1 )
169 elseif ( sstat /= 1 .or. mstat /= 2 )
then
170 call flog(
"Single thread: Solver and Model Status was not as expected (1,2)", 1 )
178 time0 = omp_get_wtime()
180 time2 = omp_get_wtime() - time0
183 write(*,*)
'End of Polygon example with 2 threads. Return code=',coi_error
185 If ( coi_error /= 0 )
then
186 call flog(
"Double threads: Errors encountered during solution", 1 )
187 elseif ( stacalls == 0 .or. solcalls == 0 )
then
188 call flog(
"Double threads: Status or Solution routine was not called", 1 )
189 elseif ( sstat /= 1 .or. mstat /= 2 )
then
190 call flog(
"Double threads: Solver and Model Status was not as expected (1,2)", 1 )
198 time0 = omp_get_wtime()
200 time4 = omp_get_wtime() - time0
203 write(*,*)
'End of Polygon example with 4 threads. Return code=',coi_error
205 If ( coi_error /= 0 )
then
206 call flog(
"Quad threads: Errors encountered during solution", 1 )
207 elseif ( stacalls == 0 .or. solcalls == 0 )
then
208 call flog(
"Quad threads: Status or Solution routine was not called", 1 )
209 elseif ( sstat /= 1 .or. mstat /= 2 )
then
210 call flog(
"Quad threads: Solver and Model Status was not as expected (1,2)", 1 )
221 write(*,*)
'Solution 2 is different from Solution 1. First diff for index',i
227 write(*,*)
'Solution 4 is different from Solution 1. First diff for index',i
233 write(*,*)
'Solution 4 is different from Solution 2. First diff for index',i
240 write(*,
"('Time for single thread',f10.3)") time1
241 write(*,
"('Time for double thread',f10.3)") time2
242 write(*,
"('Time for quad thread',f10.3)") time4
243 write(*,
"('Speedup double ',f10.3)") time1/time2
244 write(*,
"('Speedup quad ',f10.3)") time1/time4
245 if ( same12 .and. same14 .and. same24 )
then
246 write(*,*)
'All solutions are the same'
248 write(*,*)
'The solutions are NOT the same'
252 if ( coi_free( cntvect ) /= 0 )
call flog(
"Error while freeing control vector", 1 )
254 call flog(
"Successful Solve", 0 )
266 colsta, rowno, value, nlflag, n, m, nz, &
273 integer,
intent (in) :: n
274 integer,
intent (in) :: m
275 integer,
intent (in) :: nz
276 real*8,
intent (in out),
dimension(n) :: lower
277 real*8,
intent (in out),
dimension(n) :: curr
278 real*8,
intent (in out),
dimension(n) :: upper
279 integer,
intent (in out),
dimension(n) :: vsta
281 integer,
intent (out),
dimension(m) ::
type
282 integer,
intent (in out),
dimension(m) :: esta
284 real*8,
intent (in out),
dimension(m) :: rhs
285 integer,
intent (in out),
dimension(n+1) :: colsta
286 integer,
intent (out),
dimension(nz) :: rowno
287 integer,
intent (in out),
dimension(nz) :: nlflag
288 real*8,
intent (in out),
dimension(nz) ::
value
292 real*8,
parameter :: pi = 3.141592
312 curr(i) = 4.d0*i*(
np+1-i)/(1+
np)**2
449Integer Function poly_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
450 n, nz, thread, usrmem )
456 integer,
intent (in) :: n
457 integer,
intent (in) :: rowno
458 integer,
intent (in) :: nz
459 real*8,
intent (in),
dimension(n) :: x
460 real*8,
intent (in out) :: g
461 real*8,
intent (in out),
dimension(n) :: jac
462 integer,
intent (in),
dimension(nz) :: jcnm
464 integer,
intent (in) :: mode
466 integer,
intent (in) :: ignerr
468 integer,
intent (in out) :: errcnt
470 integer,
intent (in) :: thread
481 if ( rowno ==
no+
nd+1 )
then
486 if ( mode .eq. 1 .or. mode .eq. 3 )
then
489 g = g + x(i+1)*x(i)*sin(x(
np+i+1)-x(
np+i))
496 if ( mode .eq. 2 .or. mode .eq. 3 )
then
502 s = 0.5d0*sin(x(
np+i+1)-x(
np+i))
503 jac(i+1) = jac(i+1) + x(i)*s
504 jac(i) = jac(i) + x(i+1)*s
505 c = 0.5d0*x(i+1)*x(i)*cos(x(
np+i+1)-x(
np+i))
506 jac(
np+i+1) = jac(
np+i+1) + c
507 jac(
np+i) = jac(
np+i) - c
511 Else if ( rowno >
no )
then
518 if ( mode .eq. 1 .or. mode .eq. 3 )
then
519 g = x(i)**2 + x(j)**2 -2.d0*x(i)*x(j)*cos(x(j+
np)-x(i+
np))
524 if ( mode .eq. 2 .or. mode .eq. 3 )
then
525 c = cos(x(j+
np)-x(i+
np))
526 jac(i) = 2.d0*(x(i)-x(j)*c)
527 jac(j) = 2.d0*(x(j)-x(i)*c)
528 s = 2.d0*sin(x(j+
np)-x(i+
np))*x(i)*x(j)
533 write(*,*)
'Fdeval called with rowno=',rowno
540Integer Function poly_solution( XVAL, XMAR, XBAS, XSTA, YVAL, YMAR, YBAS, YSTA, N, M, USRMEM )
551 INTEGER,
Intent(IN) :: n, m
552 INTEGER,
Intent(IN),
Dimension(N) :: xbas, xsta
553 INTEGER,
Intent(IN),
Dimension(M) :: ybas, ysta
554 real*8,
Intent(IN),
Dimension(N) :: xval, xmar
555 real*8,
Intent(IN),
Dimension(M) :: yval, ymar
556 real*8,
Intent(IN OUT) :: usrmem(*)
559 CHARACTER*5,
Parameter,
Dimension(4) :: stat = (/
'Lower',
'Upper',
'Basic',
'Super' /)
561 WRITE(10,
"(/' Variable Solution value Reduced cost B-stat')")
563 WRITE(10,
"(1P,I7,E20.6,E16.6,4X,A5 )") i, xval(i), xmar(i), stat(1+xbas(i))
566 WRITE(10,
"(/' Constrnt Activity level Marginal cost B-stat')")
568 WRITE(10,
"(1P,I7,E20.6,E16.6,4X,A5 )") i, yval(i), ymar(i), stat(1+ybas(i))
570 xprim(1:n) = xval(1:n)
575 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 function coidef_fdeval(cntvect, coi_fdeval)
define callback routine for performing function and derivative evaluations.
integer function coidef_errmsg(cntvect, coi_errmsg)
define callback routine for returning error messages for row, column or Jacobian elements.
integer function coidef_message(cntvect, coi_message)
define callback routine for handling messages returned during the solution process.
integer function coidef_readmatrix(cntvect, coi_readmatrix)
define callback routine for providing the matrix data to CONOPT.
integer function coidef_status(cntvect, coi_status)
define callback routine for returning the completion status.
integer function coidef_solution(cntvect, coi_solution)
define callback routine for returning the final solution values.
integer function coidef_optfile(cntvect, optfile)
define callback routine for defining an options file.
integer function coidef_threads(cntvect, threads)
number of threads allowed internally in CONOPT.
integer function coidef_license(cntvect, licint1, licint2, licint3, licstring)
define the License Information.
integer function coidef_threadc(cntvect, threadc)
check for thread compatibility.
integer function coidef_numvar(cntvect, numvar)
defines the number of variables in the model.
integer function coidef_objcon(cntvect, objcon)
defines the Objective Constraint.
integer function coidef_numnz(cntvect, numnz)
defines the number of nonzero elements in the Jacobian.
integer function coidef_optdir(cntvect, optdir)
defines the Optimization Direction.
integer function coidef_numnlnz(cntvect, numnlnz)
defines the Number of Nonlinear Nonzeros.
integer function coidef_numcon(cntvect, numcon)
defines the number of constraints in the model.
integer function coi_solve(cntvect)
method for starting the solving process of CONOPT.
integer function poly_solution(xval, xmar, xbas, xsta, yval, ymar, ybas, ysta, n, m, usrmem)
program polygon
Main program. A simple setup and call of CONOPT.
integer, dimension(np, np) rowmapk
integer, dimension(nd) rowmapi
real *8, dimension(nv) xprim
integer, dimension(nd) rowmapj
real *8, dimension(nv) xprim2
real *8, dimension(nv) xprim1
real *8, dimension(nv) xprim4
subroutine flog(msg, code)
integer function poly_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
integer function poly_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.