6#if defined(_WIN32) && !defined(_WIN64)
7#define dec_directives_win32
11 Integer,
parameter :: Nobs = 700
12 Integer,
parameter :: DimX = 500
13 real*8,
dimension(Nobs,DimX) ::
a,
b
14 real*8,
dimension(Nobs) ::
obs
24 Integer,
save :: seed = 12359
26 seed = mod(seed*1027+25,1048576)
27 rndx = float(seed)/float(1048576)
39 real*8,
Parameter :: xtarg = -1.0
40 real*8,
Parameter :: noise = 1.0
41 Real,
External :: Rndx
49 o = o +
a(i,j) * xtarg +
b(i,j) * xtarg**2
51 obs(i) = o + noise * rndx()
78#ifdef dec_directives_win32
90 INTEGER,
Dimension(:),
Pointer :: cntvect
93 real*8 time0, time1, time2, time3
113 coi_error = max( coi_error,
coidef_optfile( cntvect,
'mp_leastsq5.opt' ) )
126#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
127 coi_error = max( coi_error,
coidef_license( cntvect, conopt_license_int_1, conopt_license_int_2, conopt_license_int_3, conopt_license_text) )
130 If ( coi_error .ne. 0 )
THEN
132 write(*,*)
'**** Fatal Error while loading CONOPT Callback routines.'
134 call flog(
"Skipping Solve due to setup errors", 1 )
139 time0 = omp_get_wtime()
141 time1 = omp_get_wtime() - time0
144 write(*,*)
'Single Thread: End of Least Square example 5. Return code=',coi_error
146 If ( coi_error /= 0 )
then
147 call flog(
"Single Thread: Errors encountered during solution", 1 )
148 elseif ( stacalls == 0 .or. solcalls == 0 )
then
149 call flog(
"Single Thread: Status or Solution routine was not called", 1 )
150 elseif ( sstat /= 1 .or. mstat /= 2 )
then
151 call flog(
"Single Thread: Solver and Model Status was not as expected (1,2)", 1 )
152 elseif ( abs(
obj - 19.44434311d0 ) > 1.d-7 )
then
153 call flog(
"Single Thread: Incorrect objective returned", 1 )
159 time0 = omp_get_wtime()
161 time2 = omp_get_wtime() - time0
164 write(*,*)
'Multiple Threads: End of Least Square example 5. Return code=',coi_error
166 If ( coi_error /= 0 )
then
167 call flog(
"Multiple Threads: Errors encountered during solution", 1 )
168 elseif ( stacalls == 0 .or. solcalls == 0 )
then
169 call flog(
"Multiple Threads: Status or Solution routine was not called", 1 )
170 elseif ( sstat /= 1 .or. mstat /= 2 )
then
171 call flog(
"Multiple Threads: Solver and Model Status was not as expected (1,2)", 1 )
172 elseif ( abs(
obj - 19.44434311d0 ) > 1.d-7 )
then
173 call flog(
"Multiple Threads: Incorrect objective returned", 1 )
179 time0 = omp_get_wtime()
181 time3 = omp_get_wtime() - time0
184 write(*,*)
'Multiple Threads -2DDir: End of Least Square example 5. Return code=',coi_error
186 If ( coi_error /= 0 )
then
187 call flog(
"Multiple Threads -2DDir: Errors encountered during solution", 1 )
188 elseif ( stacalls == 0 .or. solcalls == 0 )
then
189 call flog(
"Multiple Threads -2DDir: Status or Solution routine was not called", 1 )
190 elseif ( sstat /= 1 .or. mstat /= 2 )
then
191 call flog(
"Multiple Threads -2DDir: Solver and Model Status was not as expected (1,2)", 1 )
192 elseif ( abs(
obj - 19.44434311d0 ) > 1.d-7 )
then
193 call flog(
"Multiple Threads -2DDir: Incorrect objective returned", 1 )
196 if (
coi_free( cntvect ) /= 0 )
call flog(
"Error while freeing control vector", 1 )
199 write(*,
"('Time for single thread ',f10.3)") time1
200 write(*,
"('Time for multi thread incl 2DDir',f10.3)") time2
201 write(*,
"('Time for multi thread excl 2DDir',f10.3)") time3
202 write(*,
"('Speedup incl 2DDir',f10.3)") time1/time2
203 write(*,
"('Efficiency incl 2DDir',f10.3)") time1/time2/omp_get_max_threads()
204 write(*,
"('Speedup excl 2DDir',f10.3)") time1/time3
205 write(*,
"('Efficiency excl 2DDir',f10.3)") time1/time3/omp_get_max_threads()
207 call flog(
"Successful Solve", 0 )
218Integer Function lsq_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
219 colsta, rowno, value, nlflag, n, m, nz, &
221#ifdef dec_directives_win32
226 integer,
intent (in) :: n
227 integer,
intent (in) :: m
228 integer,
intent (in) :: nz
229 real*8,
intent (in out),
dimension(n) :: lower
230 real*8,
intent (in out),
dimension(n) :: curr
231 real*8,
intent (in out),
dimension(n) :: upper
232 integer,
intent (in out),
dimension(n) :: vsta
234 integer,
intent (out),
dimension(m) ::
type
235 integer,
intent (in out),
dimension(m) :: esta
237 real*8,
intent (in out),
dimension(m) :: rhs
238 integer,
intent (in out),
dimension(n+1) :: colsta
239 integer,
intent (out),
dimension(nz) :: rowno
240 integer,
intent (in out),
dimension(nz) :: nlflag
241 real*8,
intent (in out),
dimension(nz) ::
value
326Integer Function lsq_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
327 n, nz, thread, usrmem )
328#ifdef dec_directives_win32
333 integer,
intent (in) :: n
334 integer,
intent (in) :: rowno
335 integer,
intent (in) :: nz
336 real*8,
intent (in),
dimension(n) :: x
337 real*8,
intent (in out) :: g
338 real*8,
intent (in out),
dimension(n) :: jac
339 integer,
intent (in),
dimension(nz) :: jcnm
341 integer,
intent (in) :: mode
343 integer,
intent (in) :: ignerr
345 integer,
intent (in out) :: errcnt
347 integer,
intent (in) :: thread
355 if ( rowno .eq.
nobs+1 )
then
359 if ( mode .eq. 1 .or. mode .eq. 3 )
then
369 if ( mode .eq. 2 .or. mode .eq. 3 )
then
381 if ( mode .eq. 1 .or. mode .eq. 3 )
then
384 s = s +
a(rowno,j)*x(j) +
b(rowno,j)*x(j)**2
391 if ( mode .eq. 2 .or. mode .eq. 3 )
then
393 jac(j) =
a(rowno,j) + 2.d0*
b(rowno,j)*x(j)
405Integer Function lsq_2ddir( X, DX, D2G, ROWNO, JCNM, NODRV, N, NJ, THREAD, USRMEM )
406#ifdef dec_directives_win32
411 INTEGER,
Intent(IN) :: rowno, n,
nj, thread
412 INTEGER,
Intent(IN OUT) :: nodrv
413 INTEGER,
Dimension(NJ),
Intent(IN) :: jcnm
414 real*8,
Dimension(N),
Intent(IN) :: x
415 real*8,
Dimension(N),
Intent(IN) :: dx
416 real*8,
Dimension(N),
Intent(OUT) :: d2g
417 real*8,
Intent(IN OUT) :: usrmem(*)
420 if ( rowno .eq.
nobs+1 )
then
435 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(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_2ddir(cntvect, coi_2ddir)
define callback routine for computing the second derivative for a constraint in a direction.
integer(c_int) function coidef_license(cntvect, licint1, licint2, licint3, licstring)
define the License Information.
integer(c_int) function coidef_thread2d(cntvect, thread2d)
number of threads allowed for simultaneous 2DDir calls.
integer(c_int) function coidef_debugfv(cntvect, debugfv)
turn Debugging of FDEval on and off.
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 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)