7 Integer,
parameter ::
nobs = 700
8 Integer,
parameter ::
dimx = 500
9 real*8,
dimension(Nobs,DimX) ::
a,
b
10 real*8,
dimension(Nobs) ::
obs
20 Integer,
save :: seed = 12359
22 seed = mod(seed*1027+25,1048576)
23 rndx = float(seed)/float(1048576)
35 real*8,
Parameter :: xtarg = -1.0
36 real*8,
Parameter :: noise = 1.0
37 Real,
External :: Rndx
45 o = o +
a(i,j) * xtarg +
b(i,j) * xtarg**2
47 obs(i) = o + noise * rndx()
86 INTEGER,
Dimension(:),
Pointer :: cntvect
89 real*8 time0, time1, time2, time3
99 coi_error = coi_createfort( cntvect )
109 coi_error = max( coi_error,
coidef_optfile( cntvect,
'mp_leastsq5.opt' ) )
122#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
123 coi_error = max( coi_error,
coidef_license( cntvect, license_int_1, license_int_2, license_int_3, license_text) )
126 If ( coi_error .ne. 0 )
THEN
128 write(*,*)
'**** Fatal Error while loading CONOPT Callback routines.'
130 call flog(
"Skipping Solve due to setup errors", 1 )
135 time0 = omp_get_wtime()
137 time1 = omp_get_wtime() - time0
140 write(*,*)
'Single Thread: End of Least Square example 5. Return code=',coi_error
142 If ( coi_error /= 0 )
then
143 call flog(
"Single Thread: Errors encountered during solution", 1 )
144 elseif ( stacalls == 0 .or. solcalls == 0 )
then
145 call flog(
"Single Thread: Status or Solution routine was not called", 1 )
146 elseif ( sstat /= 1 .or. mstat /= 2 )
then
147 call flog(
"Single Thread: Solver and Model Status was not as expected (1,2)", 1 )
148 elseif ( abs(
obj - 19.44434311d0 ) > 1.d-7 )
then
149 call flog(
"Single Thread: Incorrect objective returned", 1 )
155 time0 = omp_get_wtime()
157 time2 = omp_get_wtime() - time0
160 write(*,*)
'Multiple Threads: End of Least Square example 5. Return code=',coi_error
162 If ( coi_error /= 0 )
then
163 call flog(
"Multiple Threads: Errors encountered during solution", 1 )
164 elseif ( stacalls == 0 .or. solcalls == 0 )
then
165 call flog(
"Multiple Threads: Status or Solution routine was not called", 1 )
166 elseif ( sstat /= 1 .or. mstat /= 2 )
then
167 call flog(
"Multiple Threads: Solver and Model Status was not as expected (1,2)", 1 )
168 elseif ( abs(
obj - 19.44434311d0 ) > 1.d-7 )
then
169 call flog(
"Multiple Threads: Incorrect objective returned", 1 )
175 time0 = omp_get_wtime()
177 time3 = omp_get_wtime() - time0
180 write(*,*)
'Multiple Threads -2DDir: End of Least Square example 5. Return code=',coi_error
182 If ( coi_error /= 0 )
then
183 call flog(
"Multiple Threads -2DDir: Errors encountered during solution", 1 )
184 elseif ( stacalls == 0 .or. solcalls == 0 )
then
185 call flog(
"Multiple Threads -2DDir: Status or Solution routine was not called", 1 )
186 elseif ( sstat /= 1 .or. mstat /= 2 )
then
187 call flog(
"Multiple Threads -2DDir: Solver and Model Status was not as expected (1,2)", 1 )
188 elseif ( abs(
obj - 19.44434311d0 ) > 1.d-7 )
then
189 call flog(
"Multiple Threads -2DDir: Incorrect objective returned", 1 )
192 if ( coi_free( cntvect ) /= 0 )
call flog(
"Error while freeing control vector", 1 )
195 write(*,
"('Time for single thread ',f10.3)") time1
196 write(*,
"('Time for multi thread incl 2DDir',f10.3)") time2
197 write(*,
"('Time for multi thread excl 2DDir',f10.3)") time3
198 write(*,
"('Speedup incl 2DDir',f10.3)") time1/time2
199 write(*,
"('Efficiency incl 2DDir',f10.3)") time1/time2/omp_get_max_threads()
200 write(*,
"('Speedup excl 2DDir',f10.3)") time1/time3
201 write(*,
"('Efficiency excl 2DDir',f10.3)") time1/time3/omp_get_max_threads()
203 call flog(
"Successful Solve", 0 )
215 colsta, rowno, value, nlflag, n, m, nz, &
222 integer,
intent (in) :: n
223 integer,
intent (in) :: m
224 integer,
intent (in) :: nz
225 real*8,
intent (in out),
dimension(n) :: lower
226 real*8,
intent (in out),
dimension(n) :: curr
227 real*8,
intent (in out),
dimension(n) :: upper
228 integer,
intent (in out),
dimension(n) :: vsta
230 integer,
intent (out),
dimension(m) ::
type
231 integer,
intent (in out),
dimension(m) :: esta
233 real*8,
intent (in out),
dimension(m) :: rhs
234 integer,
intent (in out),
dimension(n+1) :: colsta
235 integer,
intent (out),
dimension(nz) :: rowno
236 integer,
intent (in out),
dimension(nz) :: nlflag
237 real*8,
intent (in out),
dimension(nz) ::
value
322Integer Function lsq_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
323 n, nz, thread, usrmem )
329 integer,
intent (in) :: n
330 integer,
intent (in) :: rowno
331 integer,
intent (in) :: nz
332 real*8,
intent (in),
dimension(n) :: x
333 real*8,
intent (in out) :: g
334 real*8,
intent (in out),
dimension(n) :: jac
335 integer,
intent (in),
dimension(nz) :: jcnm
337 integer,
intent (in) :: mode
339 integer,
intent (in) :: ignerr
341 integer,
intent (in out) :: errcnt
343 integer,
intent (in) :: thread
351 if ( rowno .eq.
nobs+1 )
then
355 if ( mode .eq. 1 .or. mode .eq. 3 )
then
365 if ( mode .eq. 2 .or. mode .eq. 3 )
then
377 if ( mode .eq. 1 .or. mode .eq. 3 )
then
380 s = s +
a(rowno,j)*x(j) +
b(rowno,j)*x(j)**2
387 if ( mode .eq. 2 .or. mode .eq. 3 )
then
389 jac(j) =
a(rowno,j) + 2.d0*
b(rowno,j)*x(j)
401Integer Function lsq_2ddir( X, DX, D2G, ROWNO, JCNM, NODRV, N, NJ, THREAD, USRMEM )
407 INTEGER,
Intent(IN) :: rowno, n,
nj, thread
408 INTEGER,
Intent(IN OUT) :: nodrv
409 INTEGER,
Dimension(NJ),
Intent(IN) :: jcnm
410 real*8,
Dimension(N),
Intent(IN) :: x
411 real*8,
Dimension(N),
Intent(IN) :: dx
412 real*8,
Dimension(N),
Intent(OUT) :: d2g
413 real*8,
Intent(IN OUT) :: usrmem(*)
416 if ( rowno .eq.
nobs+1 )
then
431 d2g(j) = 2.d0*
b(rowno,j)*dx(j)
integer function std_solution(xval, xmar, xbas, xsta, yval, ymar, ybas, ysta, n, m, usrmem)
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_2ddir(cntvect, coi_2ddir)
define callback routine for computing the second derivative for a constraint in a direction.
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_debugfv(cntvect, debugfv)
turn Debugging of FDEval on and off.
integer function coidef_license(cntvect, licint1, licint2, licint3, licstring)
define the License Information.
integer function coidef_thread2d(cntvect, thread2d)
number of threads allowed for simultaneous 2DDir calls.
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 lsq_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
integer function lsq_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.
integer function lsq_2ddir(x, dx, d2g, rowno, jcnm, nodrv, n, nj, thread, usrmem)
Computes the second derivative of a constraint in a direction.
void defdata()
Defines the data for the problem.
float rndx()
Defines a pseudo random number between 0 and 1.
program leastsquare
Main program. A simple setup and call of CONOPT.
real *8, dimension(nobs) obs
real *8, dimension(nobs, dimx) a
real *8, dimension(nobs, dimx) b
subroutine flog(msg, code)