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.TIME1'
134 double precision z(maxres6),d_a_tmp(maxres6)
135 double precision edum(0:n_ene),time_order(0:10)
136 double precision Gcopy(maxres2,maxres2)
137 common /przechowalnia/ Gcopy
139 C Workers wait for variables and NF, and NFL from the boss
141 do while (iorder.ge.0)
142 c write (*,*) 'Processor',fg_rank,' CG group',kolor,
143 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
153 c & 'Processor',fg_rank,' completed receive MPI_BCAST order',iorder
154 if (iorder.eq.0) then
157 c write (2,*) "After etotal"
158 c write (2,*) "dimen",dimen," dimen3",dimen3
160 else if (iorder.eq.2) then
162 call etotal_short(edum)
163 c write (2,*) "After etotal_short"
164 c write (2,*) "dimen",dimen," dimen3",dimen3
166 else if (iorder.eq.3) then
168 call etotal_long(edum)
169 c write (2,*) "After etotal_long"
170 c write (2,*) "dimen",dimen," dimen3",dimen3
172 else if (iorder.eq.1) then
174 c write (2,*) "After sum_gradient"
175 c write (2,*) "dimen",dimen," dimen3",dimen3
177 else if (iorder.eq.4) then
178 call ginv_mult(z,d_a_tmp)
179 else if (iorder.eq.5) then
180 c Setup MD things for a slave
181 dimen=(nct-nnt+1)+nside
182 dimen1=(nct-nnt)+(nct-nnt+1)
184 c write (2,*) "dimen",dimen," dimen3",dimen3
186 call int_bounds(dimen,igmult_start,igmult_end)
187 igmult_start=igmult_start-1
188 call MPI_Allgather(3*igmult_start,1,MPI_INTEGER,
189 & ng_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
190 my_ng_count=igmult_end-igmult_start
191 call MPI_Allgather(3*my_ng_count,1,MPI_INTEGER,ng_counts(0),1,
192 & MPI_INTEGER,FG_COMM,IERROR)
193 c write (2,*) "ng_start",(ng_start(i),i=0,nfgtasks-1)
194 c write (2,*) "ng_counts",(ng_counts(i),i=0,nfgtasks-1)
195 myginv_ng_count=maxres2*my_ng_count
196 c write (2,*) "igmult_start",igmult_start," igmult_end",
197 c & igmult_end," my_ng_count",my_ng_count
199 call MPI_Allgather(maxres2*igmult_start,1,MPI_INTEGER,
200 & nginv_start(0),1,MPI_INTEGER,FG_COMM,IERROR)
201 call MPI_Allgather(myginv_ng_count,1,MPI_INTEGER,
202 & nginv_counts(0),1,MPI_INTEGER,FG_COMM,IERROR)
203 c write (2,*) "nginv_start",(nginv_start(i),i=0,nfgtasks-1)
204 c write (2,*) "nginv_counts",(nginv_counts(i),i=0,nfgtasks-1)
206 c call MPI_Barrier(FG_COMM,IERROR)
208 call MPI_Scatterv(ginv(1,1),nginv_counts(0),
209 & nginv_start(0),MPI_DOUBLE_PRECISION,gcopy(1,1),
210 & myginv_ng_count,MPI_DOUBLE_PRECISION,king,FG_COMM,IERR)
212 time_scatter_ginv=time_scatter_ginv+MPI_Wtime()-time00
219 c write (2,*) "dimen",dimen," dimen3",dimen3
220 c write (2,*) "End MD setup"
222 c write (iout,*) "My chunk of ginv_block"
223 c call MATOUT2(my_ng_count,dimen3,maxres2,maxers2,ginv_block)
224 else if (iorder.eq.6) then
225 call int_from_cart1(.false.)
226 else if (iorder.eq.7) then
228 else if (iorder.eq.8) then
230 else if (iorder.eq.9) then
231 call fricmat_mult(z,d_a_tmp)
232 else if (iorder.eq.10) then
236 write (*,*) 'Processor',fg_rank,' CG group',kolor,
237 & ' absolute rank',myrank,' leves ERGASTULUM.'
238 write(*,*)'Processor',fg_rank,' wait times for respective orders',
239 & (' order[',i,']',time_order(i),i=0,10)
243 ************************************************************************
244 subroutine func(n,x,nf,f,uiparm,urparm,ufparm)
245 implicit real*8 (a-h,o-z)
247 include 'COMMON.DERIV'
248 include 'COMMON.IOUNITS'
251 double precision energia(0:n_ene)
253 double precision ufparm
259 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
263 cd print *,'func',nf,nfl,icg
264 call var_to_geom(n,x)
267 cd write (iout,*) 'ETOTAL called from FUNC'
268 call etotal(energia(0))
272 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
273 c write (iout,*) 'f=',etot
278 ************************************************************************
279 subroutine func_restr(n,x,nf,f,uiparm,urparm,ufparm)
280 implicit real*8 (a-h,o-z)
282 include 'COMMON.DERIV'
283 include 'COMMON.IOUNITS'
286 double precision energia(0:n_ene)
288 double precision ufparm
294 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
298 call var_to_geom_restr(n,x)
301 cd write (iout,*) 'ETOTAL called from FUNC'
302 call etotal(energia(0))
306 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
307 c write (iout,*) 'f=',etot
312 c-------------------------------------------------------
313 subroutine x2xx(x,xx,n)
314 implicit real*8 (a-h,o-z)
317 include 'COMMON.CHAIN'
318 include 'COMMON.INTERACT'
319 double precision xx(maxvar),x(maxvar)
329 if (mask_phi(i).eq.1) then
337 if (mask_theta(i).eq.1) then
345 if (itype(i).ne.10) then
347 if (mask_side(i).eq.1) then
360 subroutine xx2x(x,xx)
361 implicit real*8 (a-h,o-z)
364 include 'COMMON.CHAIN'
365 include 'COMMON.INTERACT'
366 double precision xx(maxvar),x(maxvar)
376 if (mask_phi(i).eq.1) then
384 if (mask_theta(i).eq.1) then
392 if (itype(i).ne.10) then
394 if (mask_side(i).eq.1) then
405 c----------------------------------------------------------
406 subroutine minim_dc(etot,iretcode,nfun)
407 implicit real*8 (a-h,o-z)
409 parameter (liv=60,lv=(77+maxvar*(maxvar+17)/2))
413 include 'COMMON.SETUP'
414 include 'COMMON.IOUNITS'
417 include 'COMMON.MINIM'
418 include 'COMMON.CHAIN'
420 double precision minval,x(maxvar),d(maxvar),v(1:lv),xx(maxvar)
421 common /przechowalnia/ v
423 double precision energia(0:n_ene)
424 external func_dc,grad_dc,fdum
425 logical not_done,change,reduce
426 double precision g(maxvar),f1
428 call deflt(2,iv,liv,lv,v)
429 * 12 means fresh start, dont call deflt
431 * max num of fun calls
432 if (maxfun.eq.0) maxfun=500
434 * max num of iterations
435 if (maxmin.eq.0) maxmin=1000
439 * selects output unit
441 if (print_min_ini+print_min_stat+print_min_res.gt.0) iv(21)=iout
442 * 1 means to print out result
444 * 1 means to print out summary stats
445 iv(23)=print_min_stat
446 * 1 means to print initial x and d
448 * min val for v(radfac) default is 0.1
450 * max val for v(radfac) default is 4.0
453 * check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
454 * the sumsl default is 0.1
456 * false conv if (act fnctn decrease) .lt. v(34)
457 * the sumsl default is 100*machep
459 * absolute convergence
460 if (tolf.eq.0.0D0) tolf=1.0D-4
462 * relative convergence
463 if (rtolf.eq.0.0D0) rtolf=1.0D-4
465 * controls initial step size
467 * large vals of d correspond to small components of step
480 if (ialph(i,1).gt.0) then
488 call sumsl(k,d,x,func_dc,grad_dc,iv,liv,lv,v,idum,rdum,fdum)
498 if (ialph(i,1).gt.0) then
509 cd call func_dc(k,x,nf,f,idum,rdum,fdum)
510 cd call grad_dc(k,x,nf,g,idum,rdum,fdum)
514 cd call func_dc(k,x,nf,f1,idum,rdum,fdum)
516 cd print '(i5,2f15.5)',i,g(i),(f1-f)/1.0D-5
525 subroutine func_dc(n,x,nf,f,uiparm,urparm,ufparm)
526 implicit real*8 (a-h,o-z)
531 include 'COMMON.SETUP'
532 include 'COMMON.DERIV'
533 include 'COMMON.IOUNITS'
535 include 'COMMON.CHAIN'
537 double precision energia(0:n_ene)
538 double precision ufparm
555 if (ialph(i,1).gt.0) then
565 call etotal(energia(0))
568 cd print *,'func_dc ',nf,nfl,f
573 subroutine grad_dc(n,x,nf,g,uiparm,urparm,ufparm)
574 implicit real*8 (a-h,o-z)
579 include 'COMMON.SETUP'
580 include 'COMMON.CHAIN'
581 include 'COMMON.DERIV'
583 include 'COMMON.INTERACT'
584 include 'COMMON.FFIELD'
586 include 'COMMON.IOUNITS'
589 double precision urparm(1)
590 dimension x(maxvar),g(maxvar)
596 cd print *,'grad_dc ',nf,nfl,nf-nfl+1,icg
597 if (nf-nfl+1) 20,30,40
598 20 call func_dc(n,x,nf,f,uiparm,urparm,ufparm)
612 if (ialph(i,1).gt.0) then
622 C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
634 if (ialph(i,1).gt.0) then