1 subroutine minimize(etot,x,iretcode,nfun)
2 implicit real*8 (a-h,o-z)
4 parameter (liv=60,lv=(77+maxvar*(maxvar+17)/2))
5 *********************************************************************
6 * OPTIMIZE sets up SUMSL or DFP and provides a simple interface for *
7 * the calling subprogram. *
8 * when d(i)=1.0, then v(35) is the length of the initial step, *
9 * calculated in the usual pythagorean way. *
10 * absolute convergence occurs when the function is within v(31) of *
11 * zero. unless you know the minimum value in advance, abs convg *
12 * is probably not useful. *
13 * relative convergence is when the model predicts that the function *
14 * will decrease by less than v(32)*abs(fun). *
15 *********************************************************************
16 include 'COMMON.IOUNITS'
19 include 'COMMON.MINIM'
22 double precision minval,x(maxvar),d(maxvar),v(1:lv),xx(maxvar)
23 double precision energia(0:n_ene)
24 external func,gradient,fdum
25 external func_restr,grad_restr
26 logical not_done,change,reduce
27 common /przechowalnia/ v
35 call deflt(2,iv,liv,lv,v)
36 * 12 means fresh start, dont call deflt
38 * max num of fun calls
39 if (maxfun.eq.0) maxfun=500
41 * max num of iterations
42 if (maxmin.eq.0) maxmin=1000
48 if (print_min_ini+print_min_stat+print_min_res.gt.0) iv(21)=iout
49 * 1 means to print out result
51 * 1 means to print out summary stats
53 * 1 means to print initial x and d
55 * min val for v(radfac) default is 0.1
57 * max val for v(radfac) default is 4.0
60 * check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
61 * the sumsl default is 0.1
63 * false conv if (act fnctn decrease) .lt. v(34)
64 * the sumsl default is 100*machep
66 * absolute convergence
67 if (tolf.eq.0.0D0) tolf=1.0D-4
69 * relative convergence
70 if (rtolf.eq.0.0D0) rtolf=1.0D-4
72 * controls initial step size
74 * large vals of d correspond to small components of step
81 cd print *,'Calling SUMSL'
82 c call var_to_geom(nvar,x)
84 c call etotal(energia(0))
87 call x2xx(x,xx,nvar_restr)
88 call sumsl(nvar_restr,d,xx,func_restr,grad_restr,
89 & iv,liv,lv,v,idum,rdum,fdum)
92 call sumsl(nvar,d,x,func,gradient,iv,liv,lv,v,idum,rdum,fdum)
96 cd print *,'Exit SUMSL; return code:',iretcode,' energy:',etot
97 cd write (iout,'(/a,i4/)') 'SUMSL return code:',iv(1)
100 call var_to_geom(nvar,x)
102 c write (iout,'(a)') 'Reduction worked, minimizing again...'
107 c call etotal(energia(0))
109 c call enerprint(energia(0))
112 c write (*,*) 'Processor',MyID,' leaves MINIMIZE.'
119 c----------------------------------------------------------------------------
120 subroutine ergastulum
121 implicit real*8 (a-h,o-z)
126 include 'COMMON.SETUP'
127 include 'COMMON.DERIV'
129 include 'COMMON.IOUNITS'
130 include 'COMMON.FFIELD'
131 include 'COMMON.INTERACT'
133 include 'COMMON.LAGRANGE'
134 include 'COMMON.TIME1'
135 double precision z(maxres6),d_a_tmp(maxres6)
136 double precision edum(0:n_ene),time_order(0:10)
137 double precision Gcopy(maxres2,maxres2)
138 common /przechowalnia/ Gcopy
140 C Workers wait for variables and NF, and NFL from the boss
142 do while (iorder.ge.0)
143 c write (*,*) 'Processor',fg_rank,' CG group',kolor,
144 c & ' receives order from Master'
147 call MPI_Bcast(iorder,1,MPI_INTEGER,king,FG_COMM,IERR)
148 time_Bcast=time_Bcast+MPI_Wtime()-time00
149 if (icall.gt.4 .and. iorder.ge.0)
150 & time_order(iorder)=time_order(iorder)+MPI_Wtime()-time00
154 c & 'Processor',fg_rank,' completed receive MPI_BCAST order',iorder
155 if (iorder.eq.0) then
158 c write (2,*) "After etotal"
159 c write (2,*) "dimen",dimen," dimen3",dimen3
161 else if (iorder.eq.2) then
163 call etotal_short(edum)
164 c write (2,*) "After etotal_short"
165 c write (2,*) "dimen",dimen," dimen3",dimen3
167 else if (iorder.eq.3) then
169 call etotal_long(edum)
170 c write (2,*) "After etotal_long"
171 c write (2,*) "dimen",dimen," dimen3",dimen3
173 else if (iorder.eq.1) then
175 c write (2,*) "After sum_gradient"
176 c write (2,*) "dimen",dimen," dimen3",dimen3
178 else if (iorder.eq.4) then
179 call ginv_mult(z,d_a_tmp)
180 else if (iorder.eq.5) then
181 c Setup MD things for a slave
182 dimen=(nct-nnt+1)+nside
183 dimen1=(nct-nnt)+(nct-nnt+1)
185 c write (2,*) "dimen",dimen," dimen3",dimen3
187 call int_bounds(dimen,igmult_start,igmult_end)
188 igmult_start=igmult_start-1
189 call MPI_Allgather(3*igmult_start,1,MPI_INTEGER,
190 & ng_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
191 my_ng_count=igmult_end-igmult_start
192 call MPI_Allgather(3*my_ng_count,1,MPI_INTEGER,ng_counts(0),1,
193 & MPI_INTEGER,FG_COMM,IERROR)
194 c write (2,*) "ng_start",(ng_start(i),i=0,nfgtasks-1)
195 c write (2,*) "ng_counts",(ng_counts(i),i=0,nfgtasks-1)
196 myginv_ng_count=maxres2*my_ng_count
197 c write (2,*) "igmult_start",igmult_start," igmult_end",
198 c & igmult_end," my_ng_count",my_ng_count
200 call MPI_Allgather(maxres2*igmult_start,1,MPI_INTEGER,
201 & nginv_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
202 call MPI_Allgather(myginv_ng_count,1,MPI_INTEGER,
203 & nginv_counts(0),1,MPI_INTEGER,FG_COMM,IERROR)
204 c write (2,*) "nginv_start",(nginv_start(i),i=0,nfgtasks-1)
205 c write (2,*) "nginv_counts",(nginv_counts(i),i=0,nfgtasks-1)
207 c call MPI_Barrier(FG_COMM,IERROR)
209 call MPI_Scatterv(ginv(1,1),nginv_counts(0),
210 & nginv_start(0),MPI_DOUBLE_PRECISION,gcopy(1,1),
211 & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
213 time_scatter_ginv=time_scatter_ginv+MPI_Wtime()-time00
220 c write (2,*) "dimen",dimen," dimen3",dimen3
221 c write (2,*) "End MD setup"
223 c write (iout,*) "My chunk of ginv_block"
224 c call MATOUT2(my_ng_count,dimen3,maxres2,maxers2,ginv_block)
225 else if (iorder.eq.6) then
226 call int_from_cart1(.false.)
227 else if (iorder.eq.7) then
229 else if (iorder.eq.8) then
231 else if (iorder.eq.9) then
232 call fricmat_mult(z,d_a_tmp)
233 else if (iorder.eq.10) then
237 write (*,*) 'Processor',fg_rank,' CG group',kolor,
238 & ' absolute rank',myrank,' leves ERGASTULUM.'
239 write(*,*)'Processor',fg_rank,' wait times for respective orders',
240 & (' order[',i,']',time_order(i),i=0,10)
244 ************************************************************************
245 subroutine func(n,x,nf,f,uiparm,urparm,ufparm)
246 implicit real*8 (a-h,o-z)
248 include 'COMMON.DERIV'
249 include 'COMMON.IOUNITS'
252 double precision energia(0:n_ene)
254 double precision ufparm
260 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
264 cd print *,'func',nf,nfl,icg
265 call var_to_geom(n,x)
267 call chainbuild_extconf
268 cd write (iout,*) 'ETOTAL called from FUNC'
269 call etotal(energia(0))
273 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
274 c write (iout,*) 'f=',etot
279 ************************************************************************
280 subroutine func_restr(n,x,nf,f,uiparm,urparm,ufparm)
281 implicit real*8 (a-h,o-z)
283 include 'COMMON.DERIV'
284 include 'COMMON.IOUNITS'
287 double precision energia(0:n_ene)
289 double precision ufparm
295 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
299 call var_to_geom_restr(n,x)
301 call chainbuild_extconf
302 cd write (iout,*) 'ETOTAL called from FUNC'
303 call etotal(energia(0))
307 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
308 c write (iout,*) 'f=',etot
313 c-------------------------------------------------------
314 subroutine x2xx(x,xx,n)
315 implicit real*8 (a-h,o-z)
318 include 'COMMON.CHAIN'
319 include 'COMMON.INTERACT'
320 double precision xx(maxvar),x(maxvar)
330 if (mask_phi(i).eq.1) then
338 if (mask_theta(i).eq.1) then
346 if (itype(i).ne.10) then
348 if (mask_side(i).eq.1) then
361 subroutine xx2x(x,xx)
362 implicit real*8 (a-h,o-z)
365 include 'COMMON.CHAIN'
366 include 'COMMON.INTERACT'
367 double precision xx(maxvar),x(maxvar)
377 if (mask_phi(i).eq.1) then
385 if (mask_theta(i).eq.1) then
393 if (itype(i).ne.10) then
395 if (mask_side(i).eq.1) then
406 c----------------------------------------------------------
407 subroutine minim_dc(etot,iretcode,nfun)
408 implicit real*8 (a-h,o-z)
410 parameter (liv=60,lv=(77+maxvar*(maxvar+17)/2))
414 include 'COMMON.CONTROL'
415 include 'COMMON.SETUP'
416 include 'COMMON.IOUNITS'
419 include 'COMMON.MINIM'
420 include 'COMMON.CHAIN'
422 double precision minval,x(maxvar),d(maxvar),v(1:lv),xx(maxvar)
423 common /przechowalnia/ v
425 double precision energia(0:n_ene)
426 external func_dc,grad_dc,fdum
427 logical not_done,change,reduce
428 double precision g(maxvar),f1
430 call deflt(2,iv,liv,lv,v)
431 * 12 means fresh start, dont call deflt
433 * max num of fun calls
434 if (maxfun.eq.0) maxfun=500
436 * max num of iterations
437 if (maxmin.eq.0) maxmin=1000
441 * selects output unit
443 if (print_min_ini+print_min_stat+print_min_res.gt.0) iv(21)=iout
444 * 1 means to print out result
446 * 1 means to print out summary stats
447 iv(23)=print_min_stat
448 * 1 means to print initial x and d
450 * min val for v(radfac) default is 0.1
452 * max val for v(radfac) default is 4.0
455 * check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
456 * the sumsl default is 0.1
458 * false conv if (act fnctn decrease) .lt. v(34)
459 * the sumsl default is 100*machep
461 * absolute convergence
462 if (tolf.eq.0.0D0) tolf=1.0D-4
464 * relative convergence
465 if (rtolf.eq.0.0D0) rtolf=1.0D-4
467 * controls initial step size
469 * large vals of d correspond to small components of step
482 if (ialph(i,1).gt.0) then
490 c write (iout,*) "checkgrad before SUMSL"
493 c call exec_checkgrad
496 call sumsl(k,d,x,func_dc,grad_dc,iv,liv,lv,v,idum,rdum,fdum)
498 c write (iout,*) "checkgrad after SUMSL"
499 c call exec_checkgrad
510 if (ialph(i,1).gt.0) then
521 cd call func_dc(k,x,nf,f,idum,rdum,fdum)
522 cd call grad_dc(k,x,nf,g,idum,rdum,fdum)
526 cd call func_dc(k,x,nf,f1,idum,rdum,fdum)
528 cd print '(i5,2f15.5)',i,g(i),(f1-f)/1.0D-5
537 subroutine func_dc(n,x,nf,f,uiparm,urparm,ufparm)
538 implicit real*8 (a-h,o-z)
543 include 'COMMON.SETUP'
544 include 'COMMON.DERIV'
545 include 'COMMON.IOUNITS'
547 include 'COMMON.CHAIN'
549 double precision energia(0:n_ene)
550 double precision ufparm
567 if (ialph(i,1).gt.0) then
577 call etotal(energia(0))
580 cd print *,'func_dc ',nf,nfl,f
585 subroutine grad_dc(n,x,nf,g,uiparm,urparm,ufparm)
586 implicit real*8 (a-h,o-z)
591 include 'COMMON.SETUP'
592 include 'COMMON.CHAIN'
593 include 'COMMON.DERIV'
595 include 'COMMON.INTERACT'
596 include 'COMMON.FFIELD'
598 include 'COMMON.IOUNITS'
601 double precision urparm(1)
602 dimension x(maxvar),g(maxvar)
608 cd print *,'grad_dc ',nf,nfl,nf-nfl+1,icg
609 if (nf-nfl+1) 20,30,40
610 20 call func_dc(n,x,nf,f,uiparm,urparm,ufparm)
624 if (ialph(i,1).gt.0) then
634 C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
646 if (ialph(i,1).gt.0) then