20 integer,
Parameter ::
vpp = 7
21 integer,
Parameter ::
epp = 6
22 real*8,
Dimension(Tmax, Tmax*Vpp) :: xkeep
23 real*8,
Dimension(Tmax, Tmax*Vpp) :: xkeep1
24 real*8,
Dimension(Tmax, Tmax*Vpp) :: xkeep2
30 Integer,
Dimension(:),
Pointer :: cntvect
78 Integer,
Dimension(:),
pointer :: cntvect
79 real*8,
Dimension(:),
Allocatable :: usrmem
85 Integer :: maxthreadomp, maxthreadcon, maxthread, thread
86 real*8 time0, time1, time2, time3, time4
87 Logical dif12, dif13, dif23
88 Integer :: ndif12, ndif13, ndif23
97 open(12,file=
'Thread1.txt',status=
'Unknown');
98 open(13,file=
'Thread2.txt',status=
'Unknown');
99 open(14,file=
'Thread3.txt',status=
'Unknown');
100 open(15,file=
'Thread4.txt',status=
'Unknown');
106 coi_error = coi_createfort( cntvect )
107 maxthreadomp = omp_get_max_threads()
108 write(*,*)
'Initial MaxThread=',maxthreadomp,
' from OpenMP'
110 write(*,*)
'Initial MaxThread=',maxthreadcon,
' from COIGET_MaxThreads'
111 If ( maxthreadcon /= maxthreadomp )
Then
112 call flog(
"Error in COIGET_MaxThread functions", 1 )
114 If ( maxthreadomp < 4 )
then
116 call omp_set_num_threads(maxthread)
117 write(*,*)
'Revised MaxThread=',maxthread
119 maxthread = maxthreadomp
122 write(*,*)
'Revised MaxThread=',maxthreadcon,
' from COIGET_MaxThreads'
124 coi_error = coi_free( cntvect )
132 Allocate( usrmem(2*maxthread) )
133 DO thread = 1, maxthread
134 coi_error = max( coi_error, coi_createfort( cntvect ) )
163 coi_error = max( coi_error,
coidef_usrmem( cntvect, usrmem(2*thread-1) ) )
165#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
166 coi_error = max( coi_error,
coidef_license( cntvect, license_int_1, license_int_2, license_int_3, license_text) )
170 If ( coi_error .ne. 0 )
THEN
172 write(*,*)
'**** Fatal Error while loading CONOPT Callback routines.'
174 call flog(
"Skipping First Solve due to setup errors", 1 )
187 time0 = omp_get_wtime()
190 write(*,*)
'Sequential: Solving period',t,
' using thread',thread
191 write(11,*)
'Sequential: Starting period',t,
' using thread',thread
193 write(10,*)
'Sequential: Starting period',t,
' using thread',thread
194 usrmem(2*thread-1) = dfloat(t)
195 usrmem(2*thread ) = dfloat(thread)
209 coi_error = max( coi_error,
coidef_numnz( cntvect, 17 * t + 4 * (t-1) ) )
216 If ( coi_error .ne. 0 )
THEN
218 write(*,*)
'**** Fatal Error while Solving for T=',t,
' COI_Error=',coi_error
220 call flog(
"Errors encountered during Solve.", 1 )
223 time1 = omp_get_wtime() - time0
225 time0 = omp_get_wtime()
226 write(*,*)
'Finished single-thread loop. Going to start static multi-threading loop'
227 write(11,*)
'Finished single-thread loop. Going to start static multi-threading loop'
229 write(10,*)
'Finished single-thread loop. Going to start static multi-threading loop'
239 thread = 1+omp_get_thread_num()
242 write(*,*)
'Static: Solving period',t,
' using thread',thread
243 write(11,*)
'Static: Starting period',t,
' using thread',thread
245 write(10,*)
'Static: Starting period',t,
' using thread',thread
246 usrmem(2*thread-1) = dfloat(t)
247 usrmem(2*thread ) = dfloat(thread)
261 coi_error = max( coi_error,
coidef_numnz( cntvect, 17 * t + 4 * (t-1) ) )
267 If ( maxthreadcon /= 1 )
Then
270 write(*,*)
'**** Fatal Error in MaxThread while Solving Parallel for T=',t
274 coi_error = abs(coi_error)
278 If ( coi_error .ne. 0 )
THEN
280 write(*,*)
'**** Fatal Error while Solving Static OMP loop. COI_Error=',coi_error
282 call flog(
"Errors encountered during Solvein Static OMP loop.", 1 )
284 time2 = omp_get_wtime() - time0
286 time0 = omp_get_wtime()
287 write(*,*)
'Finished static multi-thread loop. Going to start dynamic multi-threading loop'
288 write(11,*)
'Finished static multi-thread loop. Going to start dynamic multi-threading loop'
290 write(10,*)
'Finished static multi-thread loop. Going to start dynamic multi-threading loop'
297 thread = 1+omp_get_thread_num()
300 write(*,*)
'Dynamic: Solving period',t,
' using thread',thread
301 write(11,*)
'Dynamic: Starting period',t,
' using thread',thread
303 write(10,*)
'Dynamic: Starting period',t,
' using thread',thread
304 usrmem(2*thread-1) = dfloat(t)
305 usrmem(2*thread ) = dfloat(thread)
319 coi_error = max( coi_error,
coidef_numnz( cntvect, 17 * t + 4 * (t-1) ) )
326 coi_error = abs(coi_error)
329 If ( coi_error .ne. 0 )
THEN
331 write(*,*)
'**** Fatal Error while Solving Dynamic OMP loop. COI_Error=',coi_error
333 call flog(
"Errors encountered during Solvein Dynamic OMP loop.", 1 )
335 time3 = omp_get_wtime() - time0
336 time0 = omp_get_wtime()
337 write(*,*)
'Finished dynamic multi-thread loop. Going to start guided multi-threading loop'
338 write(11,*)
'Finished dynamic multi-thread loop. Going to start guided multi-threading loop'
340 write(10,*)
'Finished dynamic multi-thread loop. Going to start guided multi-threading loop'
347 thread = 1+omp_get_thread_num()
350 write(*,*)
'Guided: Solving period',t,
' using thread',thread
351 write(11,*)
'Guided: Starting period',t,
' using thread',thread
353 write(10,*)
'Guided: Starting period',t,
' using thread',thread
354 usrmem(2*thread-1) = dfloat(t)
355 usrmem(2*thread ) = dfloat(thread)
369 coi_error = max( coi_error,
coidef_numnz( cntvect, 17 * t + 4 * (t-1) ) )
376 coi_error = abs(coi_error)
379 If ( coi_error .ne. 0 )
THEN
381 write(*,*)
'**** Fatal Error while Solving Guided OMP loop. COI_Error=',coi_error
383 call flog(
"Errors encountered during Solvein Guided OMP loop.", 1 )
385 write(*,*)
'Finished guided multi-thread loop.'
386 write(11,*)
'Finished guided multi-thread loop.'
388 write(10,*)
'Finished guided multi-thread loop.'
389 time4 = omp_get_wtime() - time0
393 DO thread = 1, maxthread
394 coi_error = max( coi_error, coi_free(
cntvect1(thread)%CntVect ) )
399 write(*,*)
'End of PinThread Model.'
402 dif12 = .false.; ndif12 = 0
405 if ( xkeep1(t,i) .ne. xkeep2(t,i) )
then
408 if ( ndif12 <= 10 ) &
409 write(*,1000) t, i,
thbase(t),
' XBase =',xkeep1(t,i),
thstatic(t),
' XStat =',xkeep2(t,i), (xkeep1(t,i)-xkeep2(t,i))
414 write(*,*)
'Difference between base and static solutions =',dif12
416 dif13 = .false.; ndif13 = 0
419 if ( xkeep(t,i) .ne. xkeep1(t,i) )
then
422 if ( ndif13 <= 10 ) &
423 write(*,1000) t, i,
thbase(t),
' XBase =',xkeep1(t,i),
thdynamic(t),
' XDynm =',xkeep(t,i), (xkeep1(t,i)-xkeep(t,i))
428 write(*,*)
'Difference between base and dynamic solutions =',dif13
430 dif23 = .false.; ndif23 = 0
433 if ( xkeep(t,i) .ne. xkeep2(t,i) )
then
436 if ( ndif23 <= 10 ) &
437 write(*,1000) t, i,
thstatic(t),
' XStat =',xkeep2(t,i),
thdynamic(t),
' XDynm =',xkeep(t,i), (xkeep2(t,i)-xkeep(t,i))
442 write(*,*)
'Difference between static and dynamic solutions=',dif23
4441000
Format(
'T=',i2,
' I=',i3,
' Thread=',i2,a9,1p,e22.14/ &
445 10x,
' Thread=',i2,a9,1p,e22.14,
' Diff=',1p,e22.14)
446 write(*,*)
'MaxThread =',maxthread
447 write(*,*)
'Time Single thread =',time1
448 write(*,*)
'Time Static Multi thread =',time2
449 write(*,*)
'Time Dynamic Multi thread =',time3
450 write(*,*)
'Time Guided Multi thread =',time4
451 write(*,*)
'Speedup, static =',time1/time2
452 write(*,*)
'Speedup, dynamic =',time1/time3
453 write(*,*)
'Efficiency, static =',time1/time2/maxthread
454 write(*,*)
'Efficiency, dynamic =',time1/time3/maxthread
455 write(*,*)
'Efficiency, guided =',time1/time4/maxthread
462 call flog(
"Successful Solve", 0 )
465 call flog(
"Base and Static solutions are not identical",1)
466 else if ( dif13 )
then
467 call flog(
"Base and Dynamic solutions are not identical",1)
468 else if ( dif23 )
then
469 call flog(
"Static and Dynamic solutions are not identical",1)
471 call flog(
"Successful Solve", 0 )
481Integer Function pin_option( ncall, rval, ival, lval, usrmem, name )
485 integer ncall, ival, lval
486 character(Len=*) :: name
512 colsta, rowno, value, nlflag, n, m, nz, usrmem )
518 integer,
intent (in) :: n
519 integer,
intent (in) :: m
520 integer,
intent (in) :: nz
521 real*8,
intent (in out),
dimension(n) :: lower
522 real*8,
intent (in out),
dimension(n) :: curr
523 real*8,
intent (in out),
dimension(n) :: upper
524 integer,
intent (in out),
dimension(n) :: vsta
526 integer,
intent (out),
dimension(m) ::
type
527 integer,
intent (in out),
dimension(m) :: esta
529 real*8,
intent (in out),
dimension(m) :: rhs
530 integer,
intent (in out),
dimension(n+1) :: colsta
531 integer,
intent (out),
dimension(nz) :: rowno
532 integer,
intent (in out),
dimension(nz) :: nlflag
533 real*8,
intent (in out),
dimension(nz) ::
value
536 Integer :: it, is, i, icol, iz
565 curr(is+4) = curr(is+1) - curr(is+3)
566 if ( it .gt. 1 )
then
567 curr(is+5) = curr(is+5-
vpp) - curr(is+4)
569 curr(is+5) = 500.d0 - curr(is+4)
597 rhs(is+1) = 1.d0+2.3d0*1.015d0**(it-1)
602 rhs(2) = rhs(2) + 0.87d0*18.d0
606 rhs(3) = 0.75d0*6.5d0
661 if ( it .lt. t )
then
679 if ( it .lt. t )
then
702 if ( it .lt. t )
then
736 if ( it .lt. t )
then
763 value(iz) = 1.05d0**(1-it)
784Integer Function pin_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
785 n, nz, thread, usrmem )
793 integer,
intent (in) :: n
794 integer,
intent (in) :: rowno
795 integer,
intent (in) :: nz
796 real*8,
intent (in),
dimension(n) :: x
797 real*8,
intent (in out) :: g
798 real*8,
intent (in out),
dimension(n) :: jac
799 integer,
intent (in),
dimension(nz) :: jcnm
801 integer,
intent (in) :: mode
803 integer,
intent (in) :: ignerr
805 integer,
intent (in out) :: errcnt
807 integer,
intent (in) :: thread
812 Integer :: maxthreads
822 If ( maxthreads /= 1 )
Then
824 write(*,*)
'In parallel FDEval. COIGET_MaxThreads=',maxthreads,
' and expected 1.'
826 call flog(
"Error in COIGET_MaxThreads in Parallel FDEval", 1 )
831 write(*,*)
'In parallel FDEval. COIGET_MaxThreads=',maxthreads,
' and expected',
maxthreadini
833 call flog(
"Error in COIGET_MaxThreads in Sequential FDEval", 1 )
843 if ( rowno == (it-1)*
epp+3 )
then
847 h1 = (1.1d0+0.1d0*x(is+6))
848 h2 = 1.02d0**(-x(is+2)/7.d0)
849 if ( mode == 1 .or. mode == 3 )
then
852 if ( mode == 2 .or. mode == 3 )
then
853 jac(is+2) = h1*h2*log(1.02d0)/7.d0
854 jac(is+6) = -h2*0.1d0
856 elseif ( rowno == (it-1)*
epp+7 )
then
860 if ( mode == 1 .or. mode == 3 )
then
861 g = -x(is+4)*(x(is+6)-250.d0/x(is+5))
863 if ( mode == 2 .or. mode == 3 )
then
864 jac(is+4) = -(x(is+6)-250.d0/x(is+5))
865 jac(is+5) = -x(is+4)*250d0/x(is+5)**2
873 write(*,*)
'Error. FDEval called with rowno=',rowno
882INTEGER FUNCTION pin_solution( XVAL, XMAR, XBAS, XSTA, YVAL, YMAR, YBAS, YSTA, N, M, USRMEM )
889 INTEGER,
Intent(IN) :: n, m
890 INTEGER,
Intent(IN),
Dimension(N) :: xbas, xsta
891 INTEGER,
Intent(IN),
Dimension(M) :: ybas, ysta
892 real*8,
Intent(IN),
Dimension(N) :: xval, xmar
893 real*8,
Intent(IN),
Dimension(M) :: yval, ymar
894 real*8,
Intent(IN OUT) :: usrmem(*)
899 xkeep(t, 1:n) = xval(1:n)
907Integer Function pin_status( MODSTA, SOLSTA, ITER, OBJVAL, USRMEM )
914 INTEGER,
Intent(IN) :: modsta, solsta, iter
915 real*8,
Intent(IN) :: objval
916 real*8,
Intent(IN OUT) :: usrmem(*)
918 stacalls = stacalls + 1
927Integer Function pin_message( SMSG, DMSG, NMSG, LLEN, USRMEM, MSGV )
935 INTEGER,
Intent(IN) :: smsg, dmsg, nmsg
936 INTEGER,
Intent(IN) ,
Dimension(*) :: llen
937 CHARACTER(Len=133),
Intent(IN),
Dimension(*) :: msgv
938 real*8,
Intent(IN OUT) :: usrmem(*)
940 integer :: t, thread, i
946 write(11,
"(i2,':',A)") t, msgv(i)(1:llen(i))
951 write(11+thread,
"(i2,':',A)") t, msgv(i)(1:llen(i))
959Integer Function pin_errmsg( ROWNO, COLNO, POSNO, MSGLEN, USRMEM, MSG )
967 INTEGER,
Intent(IN) :: rowno, colno, posno, msglen
968 CHARACTER(Len=*),
Intent(IN) :: msg
969 real*8,
Intent(IN OUT) :: usrmem(*)
980 IF ( rowno .EQ. 0 )
THEN
981 WRITE(11,1001) t, colno, msg(1:msglen)
982 ELSEIF ( colno .EQ. 0 )
THEN
983 WRITE(11,1002) t, rowno, msg(1:msglen)
985 WRITE(11,1000) t, colno, rowno, msg(1:msglen)
989 IF ( rowno .EQ. 0 )
THEN
990 WRITE(11+thread,1001) t, colno, msg(1:msglen)
991 ELSEIF ( colno .EQ. 0 )
THEN
992 WRITE(11+thread,1002) t, rowno, msg(1:msglen)
994 WRITE(11+thread,1000) t, colno, rowno, msg(1:msglen)
9981001
FORMAT(i2,
':Variable',i8,
' : ',a)
9991002
FORMAT(i2,
':Equation',i8,
' : ',a)
10001000
FORMAT(i2,
':Variable',i8,
' appearing in Equation',i8,
' : ',a)
integer function pin_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.
integer function pin_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
integer function pin_solution(xval, xmar, xbas, xsta, yval, ymar, ybas, ysta, n, m, usrmem)
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_option(cntvect, coi_option)
define callback routine for defining runtime options.
integer function coidef_usrmem(cntvect, usrmem)
provides a pointer to user memory that is available in all callback functions. NOTE: this is not a ca...
integer function coidef_license(cntvect, licint1, licint2, licint3, licstring)
define the License Information.
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 coidef_inifort(cntvect)
initialisation method for Fortran applications.
integer function coiget_maxthreads(cntvect)
returns the maximum number of threads that can be used by CONOPT.
integer function coi_solve(cntvect)
method for starting the solving process of CONOPT.
program pinthread
Main program. A simple setup and call of CONOPT.
integer function pin_errmsg(rowno, colno, posno, msglen, usrmem, msg)
integer function pin_status(modsta, solsta, iter, objval, usrmem)
integer function pin_message(smsg, dmsg, nmsg, llen, usrmem, msgv)
integer, dimension(tmax) thguided
integer, dimension(tmax) thstatic
type(controlv), dimension(:), pointer cntvect1
integer, dimension(tmax) thbase
integer, dimension(tmax) thdynamic
subroutine flog(msg, code)
integer function pin_option(ncall, rval, ival, lval, usrmem, name)
Sets runtime options.