6#if defined(_WIN32) && !defined(_WIN64)
7#define dec_directives_win32
33#ifdef dec_directives_win32
44 INTEGER,
Dimension(:),
Pointer :: cntvect
86 real*8 time0, time1, time2
99 coi_error = max( coi_error,
coidef_numnz( cntvect, 6*ne ) )
103 coi_error = max( coi_error,
coidef_optfile( cntvect,
'mp_elec.opt' ) )
114#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
115 coi_error = max( coi_error,
coidef_license( cntvect, conopt_license_int_1, conopt_license_int_2, conopt_license_int_3, conopt_license_text) )
118 If ( coi_error .ne. 0 )
THEN
120 write(*,*)
'**** Fatal Error while loading CONOPT Callback routines.'
122 call flog(
"Skipping Solve due to setup errors", 1 )
128 time0 = omp_get_wtime()
130 time1 = omp_get_wtime() - time0
133 write(*,*)
'End of Electron example single thread. Return code=',coi_error
135 If ( coi_error /= 0 )
then
136 call flog(
"One Thread: Errors encountered during solution", 1 )
137 elseif ( stacalls == 0 .or. solcalls == 0 )
then
138 call flog(
"One Thread: Status or Solution routine was not called", 1 )
139 elseif ( sstat /= 1 .or. mstat /= 2 )
then
140 call flog(
"One Thread: Solver and Model Status was not as expected (1,2)", 1 )
147 time0 = omp_get_wtime()
149 time2 = omp_get_wtime() - time0
152 write(*,*)
'End of Electron example multi thread. Return code=',coi_error
154 If ( coi_error /= 0 )
then
155 call flog(
"Multi Thread: Errors encountered during solution", 1 )
156 elseif ( stacalls == 0 .or. solcalls == 0 )
then
157 call flog(
"Multi Thread: Status or Solution routine was not called", 1 )
158 elseif ( sstat /= 1 .or. mstat /= 2 )
then
159 call flog(
"Multi Thread: Solver and Model Status was not as expected (1,2)", 1 )
162 if (
coi_free( cntvect ) /= 0 )
call flog(
"Error while freeing control vector", 1 )
165 write(*,
"('Time for single thread',f10.3)") time1
166 write(*,
"('Time for multi thread',f10.3)") time2
167 write(*,
"('Speedup ',f10.3)") time1/time2
168 write(*,
"('Efficiency ',f10.3)") time1/time2/omp_get_max_threads()
170 call flog(
"Successful Solve", 0 )
181 seed = mod(seed*1027+25,1048576)
182 rndx = float(seed)/float(1048576)
193Integer Function elec_readmatrix( lower, curr, upper, vsta, type, rhs, esta, &
194 colsta, rowno, value, nlflag, n, m, nz, &
196#ifdef dec_directives_win32
200 integer,
intent (in) :: n
201 integer,
intent (in) :: m
202 integer,
intent (in) :: nz
203 real*8,
intent (in out),
dimension(n) :: lower
204 real*8,
intent (in out),
dimension(n) :: curr
205 real*8,
intent (in out),
dimension(n) :: upper
206 integer,
intent (in out),
dimension(n) :: vsta
208 integer,
intent (out),
dimension(m) ::
type
209 integer,
intent (in out),
dimension(m) :: esta
211 real*8,
intent (in out),
dimension(m) :: rhs
212 integer,
intent (in out),
dimension(n+1) :: colsta
213 integer,
intent (out),
dimension(nz) :: rowno
214 integer,
intent (in out),
dimension(nz) :: nlflag
215 real*8,
intent (in out),
dimension(nz) ::
value
220 real*8,
parameter :: pi = 3.141592
222 Real,
External ::
rndx
233 curr(i ) = cos(theta)*sin(phi)
234 curr(i+ ne) = sin(theta)*sin(phi)
235 curr(i+2*ne) = cos(phi)
317Integer Function elec_fdeval( x, g, jac, rowno, jcnm, mode, ignerr, errcnt, &
318 n, nz, thread, usrmem )
319#ifdef dec_directives_win32
323 integer,
intent (in) :: n
324 integer,
intent (in) :: rowno
325 integer,
intent (in) :: nz
326 real*8,
intent (in),
dimension(n) :: x
327 real*8,
intent (in out) :: g
328 real*8,
intent (in out),
dimension(n) :: jac
329 integer,
intent (in),
dimension(nz) :: jcnm
331 integer,
intent (in) :: mode
333 integer,
intent (in) :: ignerr
335 integer,
intent (in out) :: errcnt
337 integer,
intent (in) :: thread
342 real*8 :: dist, dist32, tx, ty, tz
348 if ( rowno == ne+1 )
then
352 if ( mode .eq. 1 .or. mode .eq. 3 )
then
356 dist = (x(i)-x(j))**2 + (x(i+ne)-x(j+ne))**2 + (x(i+2*ne)-x(j+2*ne))**2
357 g = g + 1.d0/sqrt(dist)
364 if ( mode .eq. 2 .or. mode .eq. 3 )
then
370 dist = (x(i)-x(j))**2 + (x(i+ne)-x(j+ne))**2 + (x(i+2*ne)-x(j+2*ne))**2
371 dist32 = (1.d0/sqrt(dist))**3
372 tx = -(x(i)-x(j))*dist32
373 ty = -(x(i+ne)-x(j+ne))*dist32
374 tz = -(x(i+2*ne)-x(j+2*ne))*dist32
377 jac(i+ne) = jac(i+ne) + ty
378 jac(j+ne) = jac(j+ne) - ty
379 jac(i+2*ne) = jac(i+2*ne) + tz
380 jac(j+2*ne) = jac(j+2*ne) - tz
390 if ( mode .eq. 1 .or. mode .eq. 3 )
then
391 g = x(i)**2 + x(i+ne)**2 + x(i+2*ne)**2
396 if ( mode .eq. 2 .or. mode .eq. 3 )
then
398 jac(i+ne) = 2.d0*x(i+ne)
399 jac(i+2*ne) = 2.d0*x(i+2*ne)
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 elec_fdeval(x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem)
Compute nonlinear terms and non-constant Jacobian elements.
integer function elec_readmatrix(lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem)
Define information about the model.
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_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.
float rndx()
Defines a pseudo random number between 0 and 1.
program electron
Main program. A simple setup and call of CONOPT.
subroutine flog(msg, code)