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'
20 include 'COMMON.CONTROL'
23 double precision minval,x(maxvar),d(maxvar),v(1:lv),xx(maxvar)
24 double precision energia(0:n_ene)
25 external func,gradient,fdum
26 external func_restr,grad_restr
27 logical not_done,change,reduce
28 c common /przechowalnia/ v
36 call deflt(2,iv,liv,lv,v)
37 * 12 means fresh start, dont call deflt
39 * max num of fun calls
40 if (maxfun.eq.0) maxfun=500
42 * max num of iterations
43 if (maxmin.eq.0) maxmin=1000
49 if (print_min_ini+print_min_stat+print_min_res.gt.0) iv(21)=iout
50 * 1 means to print out result
52 * 1 means to print out summary stats
54 * 1 means to print initial x and d
56 * min val for v(radfac) default is 0.1
58 * max val for v(radfac) default is 4.0
61 * check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
62 * the sumsl default is 0.1
64 * false conv if (act fnctn decrease) .lt. v(34)
65 * the sumsl default is 100*machep
67 * absolute convergence
68 if (tolf.eq.0.0D0) tolf=1.0D-4
70 * relative convergence
71 if (rtolf.eq.0.0D0) rtolf=1.0D-4
73 * controls initial step size
75 * large vals of d correspond to small components of step
82 cd print *,'Calling SUMSL'
83 c call var_to_geom(nvar,x)
85 c call etotal(energia(0))
88 call x2xx(x,xx,nvar_restr)
89 call sumsl(nvar_restr,d,xx,func_restr,grad_restr,
90 & iv,liv,lv,v,idum,rdum,fdum)
93 call sumsl(nvar,d,x,func,gradient,iv,liv,lv,v,idum,rdum,fdum)
97 cd print *,'Exit SUMSL; return code:',iretcode,' energy:',etot
98 cd write (iout,'(/a,i4/)') 'SUMSL return code:',iv(1)
101 call var_to_geom(nvar,x)
103 c write (iout,'(a)') 'Reduction worked, minimizing again...'
108 c call etotal(energia(0))
110 c call enerprint(energia(0))
113 c write (*,*) 'Processor',MyID,' leaves MINIMIZE.'
120 c----------------------------------------------------------------------------
121 subroutine ergastulum
122 implicit real*8 (a-h,o-z)
127 include 'COMMON.SETUP'
128 include 'COMMON.DERIV'
130 include 'COMMON.IOUNITS'
131 include 'COMMON.FFIELD'
132 include 'COMMON.INTERACT'
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'
146 call MPI_Bcast(iorder,1,MPI_INTEGER,king,FG_COMM,IERR)
147 time_Bcast=time_Bcast+MPI_Wtime()-time00
148 if (icall.gt.4 .and. iorder.ge.0)
149 & time_order(iorder)=time_order(iorder)+MPI_Wtime()-time00
152 c & 'Processor',fg_rank,' completed receive MPI_BCAST order',iorder
153 if (iorder.eq.0) then
156 c write (2,*) "After etotal"
157 c write (2,*) "dimen",dimen," dimen3",dimen3
159 else if (iorder.eq.2) then
161 call etotal_short(edum)
162 c write (2,*) "After etotal_short"
163 c write (2,*) "dimen",dimen," dimen3",dimen3
165 else if (iorder.eq.3) then
167 call etotal_long(edum)
168 c write (2,*) "After etotal_long"
169 c write (2,*) "dimen",dimen," dimen3",dimen3
171 else if (iorder.eq.1) then
173 c write (2,*) "After sum_gradient"
174 c write (2,*) "dimen",dimen," dimen3",dimen3
176 else if (iorder.eq.4) then
177 call ginv_mult(z,d_a_tmp)
178 else if (iorder.eq.5) then
179 c Setup MD things for a slave
180 dimen=(nct-nnt+1)+nside
181 dimen1=(nct-nnt)+(nct-nnt+1)
183 c write (2,*) "dimen",dimen," dimen3",dimen3
185 call int_bounds(dimen,igmult_start,igmult_end)
186 igmult_start=igmult_start-1
187 call MPI_Allgather(3*igmult_start,1,MPI_INTEGER,
188 & ng_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
189 my_ng_count=igmult_end-igmult_start
190 call MPI_Allgather(3*my_ng_count,1,MPI_INTEGER,ng_counts(0),1,
191 & MPI_INTEGER,FG_COMM,IERROR)
192 c write (2,*) "ng_start",(ng_start(i),i=0,nfgtasks-1)
193 c write (2,*) "ng_counts",(ng_counts(i),i=0,nfgtasks-1)
194 myginv_ng_count=maxres2*my_ng_count
195 c write (2,*) "igmult_start",igmult_start," igmult_end",
196 c & igmult_end," my_ng_count",my_ng_count
198 call MPI_Allgather(maxres2*igmult_start,1,MPI_INTEGER,
199 & nginv_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
200 call MPI_Allgather(myginv_ng_count,1,MPI_INTEGER,
201 & nginv_counts(0),1,MPI_INTEGER,FG_COMM,IERROR)
202 c write (2,*) "nginv_start",(nginv_start(i),i=0,nfgtasks-1)
203 c write (2,*) "nginv_counts",(nginv_counts(i),i=0,nfgtasks-1)
205 c call MPI_Barrier(FG_COMM,IERROR)
207 call MPI_Scatterv(ginv(1,1),nginv_counts(0),
208 & nginv_start(0),MPI_DOUBLE_PRECISION,gcopy(1,1),
209 & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
211 time_scatter_ginv=time_scatter_ginv+MPI_Wtime()-time00
218 c write (2,*) "dimen",dimen," dimen3",dimen3
219 c write (2,*) "End MD setup"
221 c write (iout,*) "My chunk of ginv_block"
222 c call MATOUT2(my_ng_count,dimen3,maxres2,maxers2,ginv_block)
223 else if (iorder.eq.6) then
224 call int_from_cart1(.false.)
225 else if (iorder.eq.7) then
227 else if (iorder.eq.8) then
229 else if (iorder.eq.9) then
230 call fricmat_mult(z,d_a_tmp)
231 else if (iorder.eq.10) then
235 write (*,*) 'Processor',fg_rank,' CG group',kolor,
236 & ' absolute rank',myrank,' leves ERGASTULUM.'
237 write(*,*)'Processor',fg_rank,' wait times for respective orders',
238 & (' order[',i,']',time_order(i),i=0,10)
242 ************************************************************************
243 subroutine func(n,x,nf,f,uiparm,urparm,ufparm)
244 implicit real*8 (a-h,o-z)
246 include 'COMMON.DERIV'
247 include 'COMMON.IOUNITS'
250 double precision energia(0:n_ene)
252 double precision ufparm
258 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
262 cd print *,'func',nf,nfl,icg
263 call var_to_geom(n,x)
266 cd write (iout,*) 'ETOTAL called from FUNC'
267 call etotal(energia(0))
271 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
272 c write (iout,*) 'f=',etot
277 ************************************************************************
278 subroutine func_restr(n,x,nf,f,uiparm,urparm,ufparm)
279 implicit real*8 (a-h,o-z)
281 include 'COMMON.DERIV'
282 include 'COMMON.IOUNITS'
285 double precision energia(0:n_ene)
287 double precision ufparm
293 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
297 call var_to_geom_restr(n,x)
300 cd write (iout,*) 'ETOTAL called from FUNC'
301 call etotal(energia(0))
305 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
306 c write (iout,*) 'f=',etot
311 c-------------------------------------------------------
312 subroutine x2xx(x,xx,n)
313 implicit real*8 (a-h,o-z)
316 include 'COMMON.CHAIN'
317 include 'COMMON.INTERACT'
318 double precision xx(maxvar),x(maxvar)
328 if (mask_phi(i).eq.1) then
336 if (mask_theta(i).eq.1) then
344 if (itype(i).ne.10) then
346 if (mask_side(i).eq.1) then
359 subroutine xx2x(x,xx)
360 implicit real*8 (a-h,o-z)
363 include 'COMMON.CHAIN'
364 include 'COMMON.INTERACT'
365 double precision xx(maxvar),x(maxvar)
375 if (mask_phi(i).eq.1) then
383 if (mask_theta(i).eq.1) then
391 if (itype(i).ne.10) then
393 if (mask_side(i).eq.1) then
404 c----------------------------------------------------------
405 subroutine minim_dc(etot,iretcode,nfun)
406 implicit real*8 (a-h,o-z)
408 parameter (liv=60,lv=(77+maxvar*(maxvar+17)/2))
412 include 'COMMON.SETUP'
413 include 'COMMON.IOUNITS'
416 include 'COMMON.MINIM'
417 include 'COMMON.CHAIN'
419 double precision minval,x(maxvar),d(maxvar),v(1:lv),xx(maxvar)
420 c common /przechowalnia/ v
422 double precision energia(0:n_ene)
423 external func_dc,grad_dc,fdum
424 logical not_done,change,reduce
425 double precision g(maxvar),f1
427 call deflt(2,iv,liv,lv,v)
428 * 12 means fresh start, dont call deflt
430 * max num of fun calls
431 if (maxfun.eq.0) maxfun=500
433 * max num of iterations
434 if (maxmin.eq.0) maxmin=1000
438 * selects output unit
440 if (print_min_ini+print_min_stat+print_min_res.gt.0) iv(21)=iout
441 * 1 means to print out result
443 * 1 means to print out summary stats
444 iv(23)=print_min_stat
445 * 1 means to print initial x and d
447 * min val for v(radfac) default is 0.1
449 * max val for v(radfac) default is 4.0
452 * check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
453 * the sumsl default is 0.1
455 * false conv if (act fnctn decrease) .lt. v(34)
456 * the sumsl default is 100*machep
458 * absolute convergence
459 if (tolf.eq.0.0D0) tolf=1.0D-4
461 * relative convergence
462 if (rtolf.eq.0.0D0) rtolf=1.0D-4
464 * controls initial step size
466 * large vals of d correspond to small components of step
479 if (ialph(i,1).gt.0) then
487 call sumsl(k,d,x,func_dc,grad_dc,iv,liv,lv,v,idum,rdum,fdum)
497 if (ialph(i,1).gt.0) then
508 cd call func_dc(k,x,nf,f,idum,rdum,fdum)
509 cd call grad_dc(k,x,nf,g,idum,rdum,fdum)
513 cd call func_dc(k,x,nf,f1,idum,rdum,fdum)
515 cd print '(i5,2f15.5)',i,g(i),(f1-f)/1.0D-5
524 subroutine func_dc(n,x,nf,f,uiparm,urparm,ufparm)
525 implicit real*8 (a-h,o-z)
530 include 'COMMON.SETUP'
531 include 'COMMON.DERIV'
532 include 'COMMON.IOUNITS'
534 include 'COMMON.CHAIN'
536 double precision energia(0:n_ene)
537 double precision ufparm
554 if (ialph(i,1).gt.0) then
564 call etotal(energia(0))
567 cd print *,'func_dc ',nf,nfl,f
572 subroutine grad_dc(n,x,nf,g,uiparm,urparm,ufparm)
573 implicit real*8 (a-h,o-z)
578 include 'COMMON.SETUP'
579 include 'COMMON.CHAIN'
580 include 'COMMON.DERIV'
582 include 'COMMON.INTERACT'
583 include 'COMMON.FFIELD'
585 include 'COMMON.IOUNITS'
588 double precision urparm(1)
589 dimension x(maxvar),g(maxvar)
595 cd print *,'grad_dc ',nf,nfl,nf-nfl+1,icg
596 if (nf-nfl+1) 20,30,40
597 20 call func_dc(n,x,nf,f,uiparm,urparm,ufparm)
611 if (ialph(i,1).gt.0) then
621 C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
633 if (ialph(i,1).gt.0) then