13#if defined(_WIN32) && !defined(_WIN64)
14#define dec_directives_win32
18 Integer,
Parameter :: NP = 50
19 Integer,
Parameter :: NV = 2*np
20 Integer,
Parameter ::
no = np-1
21 Integer,
Parameter ::
nd = np*(np-1)/2
46#ifdef dec_directives_win32
57 INTEGER,
Dimension(:),
Pointer :: cntvect
60 real*8 time0, time1, time2, time4
61 Integer :: iter1, iter2, iter4
63 Logical :: same12, same14, same24
123 coi_error = max( coi_error,
coidef_optfile( cntvect,
'mp_polygon2.opt' ) )
134#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
135 coi_error = max( coi_error,
coidef_license( cntvect, conopt_license_int_1, conopt_license_int_2, conopt_license_int_3, conopt_license_text) )
138 If ( coi_error .ne. 0 )
THEN
140 write(*,*)
'**** Fatal Error while loading CONOPT Callback routines.'
142 call flog(
"Skipping Solve due to setup errors", 1 )
152 write(*,*)
'End of Polygon example with one thread. Return code=',coi_error
154 If ( coi_error /= 115 )
then
155 call flog(
"ThreadC = 1 and ThreadS = 2 did not give error return 115.", 1 )
162 time0 = omp_get_wtime()
164 time1 = omp_get_wtime() - time0
167 write(*,*)
'End of Polygon example with 1 threads. Return code=',coi_error
169 If ( coi_error /= 0 )
then
170 call flog(
"Single thread: Errors encountered during solution", 1 )
171 elseif ( stacalls == 0 .or. solcalls == 0 )
then
172 call flog(
"Single thread: Status or Solution routine was not called", 1 )
173 elseif ( sstat /= 1 .or. mstat /= 2 )
then
174 call flog(
"Single thread: Solver and Model Status was not as expected (1,2)", 1 )
182 time0 = omp_get_wtime()
184 time2 = omp_get_wtime() - time0
187 write(*,*)
'End of Polygon example with 2 threads. Return code=',coi_error
189 If ( coi_error /= 0 )
then
190 call flog(
"Double threads: Errors encountered during solution", 1 )
191 elseif ( stacalls == 0 .or. solcalls == 0 )
then
192 call flog(
"Double threads: Status or Solution routine was not called", 1 )
193 elseif ( sstat /= 1 .or. mstat /= 2 )
then
194 call flog(
"Double threads: Solver and Model Status was not as expected (1,2)", 1 )
202 time0 = omp_get_wtime()
204 time4 = omp_get_wtime() - time0
207 write(*,*)
'End of Polygon example with 4 threads. Return code=',coi_error
209 If ( coi_error /= 0 )
then
210 call flog(
"Quad threads: Errors encountered during solution", 1 )
211 elseif ( stacalls == 0 .or. solcalls == 0 )
then
212 call flog(
"Quad threads: Status or Solution routine was not called", 1 )
213 elseif ( sstat /= 1 .or. mstat /= 2 )
then
214 call flog(
"Quad threads: Solver and Model Status was not as expected (1,2)", 1 )
225 write(*,*)
'Solution 2 is different from Solution 1. First diff for index',i
231 write(*,*)
'Solution 4 is different from Solution 1. First diff for index',i
237 write(*,*)
'Solution 4 is different from Solution 2. First diff for index',i
244 write(*,
"('Time for single thread',f10.3)") time1
245 write(*,
"('Time for double thread',f10.3)") time2
246 write(*,
"('Time for quad thread',f10.3)") time4
247 write(*,
"('Speedup double ',f10.3)") time1/time2
248 write(*,
"('Speedup quad ',f10.3)") time1/time4
249 if ( same12 .and. same14 .and. same24 )
then
250 write(*,*)
'All solutions are the same'
252 write(*,*)
'The solutions are NOT the same'
256 if (
coi_free( cntvect ) /= 0 )
call flog(
"Error while freeing control vector", 1 )
258 call flog(
"Successful Solve", 0 )
269Integer Function poly_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
270 colsta, rowno, value, nlflag, n, m, nz, &
272#ifdef dec_directives_win32
277 integer,
intent (in) :: n
278 integer,
intent (in) :: m
279 integer,
intent (in) :: nz
280 real*8,
intent (in out),
dimension(n) :: lower
281 real*8,
intent (in out),
dimension(n) :: curr
282 real*8,
intent (in out),
dimension(n) :: upper
283 integer,
intent (in out),
dimension(n) :: vsta
285 integer,
intent (out),
dimension(m) ::
type
286 integer,
intent (in out),
dimension(m) :: esta
288 real*8,
intent (in out),
dimension(m) :: rhs
289 integer,
intent (in out),
dimension(n+1) :: colsta
290 integer,
intent (out),
dimension(nz) :: rowno
291 integer,
intent (in out),
dimension(nz) :: nlflag
292 real*8,
intent (in out),
dimension(nz) ::
value
296 real*8,
parameter :: pi = 3.141592
316 curr(i) = 4.d0*i*(
np+1-i)/(1+
np)**2
453Integer Function poly_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
454 n, nz, thread, usrmem )
455#ifdef dec_directives_win32
460 integer,
intent (in) :: n
461 integer,
intent (in) :: rowno
462 integer,
intent (in) :: nz
463 real*8,
intent (in),
dimension(n) :: x
464 real*8,
intent (in out) :: g
465 real*8,
intent (in out),
dimension(n) :: jac
466 integer,
intent (in),
dimension(nz) :: jcnm
468 integer,
intent (in) :: mode
470 integer,
intent (in) :: ignerr
472 integer,
intent (in out) :: errcnt
474 integer,
intent (in) :: thread
485 if ( rowno ==
no+
nd+1 )
then
490 if ( mode .eq. 1 .or. mode .eq. 3 )
then
493 g = g + x(i+1)*x(i)*sin(x(
np+i+1)-x(
np+i))
500 if ( mode .eq. 2 .or. mode .eq. 3 )
then
506 s = 0.5d0*sin(x(
np+i+1)-x(
np+i))
507 jac(i+1) = jac(i+1) + x(i)*s
508 jac(i) = jac(i) + x(i+1)*s
509 c = 0.5d0*x(i+1)*x(i)*cos(x(
np+i+1)-x(
np+i))
510 jac(
np+i+1) = jac(
np+i+1) + c
511 jac(
np+i) = jac(
np+i) - c
515 Else if ( rowno >
no )
then
522 if ( mode .eq. 1 .or. mode .eq. 3 )
then
523 g = x(i)**2 + x(j)**2 -2.d0*x(i)*x(j)*cos(x(j+
np)-x(i+
np))
528 if ( mode .eq. 2 .or. mode .eq. 3 )
then
530 jac(i) = 2.d0*(x(i)-x(j)*c)
531 jac(j) = 2.d0*(x(j)-x(i)*c)
532 s = 2.d0*sin(x(j+
np)-x(i+
np))*x(i)*x(j)
537 write(*,*)
'Fdeval called with rowno=',rowno
544Integer Function poly_solution( XVAL, XMAR, XBAS, XSTA, YVAL, YMAR, YBAS, YSTA, N, M, USRMEM )
545#ifdef dec_directives_win32
555 INTEGER,
Intent(IN) :: n, m
556 INTEGER,
Intent(IN),
Dimension(N) :: xbas, xsta
557 INTEGER,
Intent(IN),
Dimension(M) :: ybas, ysta
558 real*8,
Intent(IN),
Dimension(N) :: xval, xmar
559 real*8,
Intent(IN),
Dimension(M) :: yval, ymar
560 real*8,
Intent(IN OUT) :: usrmem(*)
563 CHARACTER*5,
Parameter,
Dimension(4) :: stat = (/
'Lower',
'Upper',
'Basic',
'Super' /)
565 WRITE(10,
"(/' Variable Solution value Reduced cost B-stat')")
567 WRITE(10,
"(1P,I7,E20.6,E16.6,4X,A5 )") i, xval(i), xmar(i), stat(1+xbas(i))
570 WRITE(10,
"(/' Constrnt Activity level Marginal cost B-stat')")
572 WRITE(10,
"(1P,I7,E20.6,E16.6,4X,A5 )") i, yval(i), ymar(i), stat(1+ybas(i))
574 xprim(1:n) = xval(1:n)
577 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_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 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 recursive function poly_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.