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 c 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 double precision e_tmp
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
233 else if (iorder.eq.11) then
234 c broadcast new value of iset
235 call MPI_Bcast(iset,1,MPI_INTEGER,king,FG_COMM,IERROR)
236 else if (iorder.eq.12) then
237 c broadcast new value of iset and
238 c calculate restraint homology energy and
239 c sum it over FG_COMM
240 call MPI_Bcast(iset,1,MPI_INTEGER,king,FG_COMM,IERROR)
241 call e_modeller(e_tmp)
242 call MPI_Barrier(FG_COMM,IERR)
243 call MPI_Reduce(e_tmp,ehomology_constr,1,
244 & MPI_DOUBLE_PRECISION,MPI_SUM,king,FG_COMM,IERR)
245 else if (iorder.eq.13) then
249 write (*,*) 'Processor',fg_rank,' CG group',kolor,
250 & ' absolute rank',myrank,' leves ERGASTULUM.'
251 write(*,*)'Processor',fg_rank,' wait times for respective orders',
252 & (' order[',i,']',time_order(i),i=0,12)
256 ************************************************************************
257 subroutine func(n,x,nf,f,uiparm,urparm,ufparm)
258 implicit real*8 (a-h,o-z)
260 include 'COMMON.DERIV'
261 include 'COMMON.IOUNITS'
264 double precision energia(0:n_ene)
266 double precision ufparm
272 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
276 cd print *,'func',nf,nfl,icg
277 call var_to_geom(n,x)
280 cd write (iout,*) 'ETOTAL called from FUNC'
281 call etotal(energia(0))
285 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
286 c write (iout,*) 'f=',f
291 ************************************************************************
292 subroutine func_restr(n,x,nf,f,uiparm,urparm,ufparm)
293 implicit real*8 (a-h,o-z)
295 include 'COMMON.DERIV'
296 include 'COMMON.IOUNITS'
299 double precision energia(0:n_ene)
301 double precision ufparm
307 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
311 call var_to_geom_restr(n,x)
314 cd write (iout,*) 'ETOTAL called from FUNC'
315 call etotal(energia(0))
319 c write (iout,'(10f8.3)') (rad2deg*x(i),i=1,n)
320 c write (iout,*) 'f=',etot
325 c-------------------------------------------------------
326 subroutine x2xx(x,xx,n)
327 implicit real*8 (a-h,o-z)
330 include 'COMMON.CHAIN'
331 include 'COMMON.INTERACT'
332 double precision xx(maxvar),x(maxvar)
342 if (mask_phi(i).eq.1) then
350 if (mask_theta(i).eq.1) then
358 if (itype(i).ne.10) then
360 if (mask_side(i).eq.1) then
373 subroutine xx2x(x,xx)
374 implicit real*8 (a-h,o-z)
377 include 'COMMON.CHAIN'
378 include 'COMMON.INTERACT'
379 double precision xx(maxvar),x(maxvar)
389 if (mask_phi(i).eq.1) then
397 if (mask_theta(i).eq.1) then
405 if (itype(i).ne.10) then
407 if (mask_side(i).eq.1) then
418 c----------------------------------------------------------
419 subroutine minim_dc(etot,iretcode,nfun)
420 implicit real*8 (a-h,o-z)
422 parameter (liv=60,lv=(77+maxvar*(maxvar+17)/2))
426 include 'COMMON.SETUP'
427 include 'COMMON.IOUNITS'
430 include 'COMMON.MINIM'
431 include 'COMMON.CHAIN'
433 double precision minval,x(maxvar),d(maxvar),v(1:lv),xx(maxvar)
434 c common /przechowalnia/ v
436 double precision energia(0:n_ene)
437 external func_dc,grad_dc,fdum
438 logical not_done,change,reduce
439 double precision g(maxvar),f1
441 call deflt(2,iv,liv,lv,v)
442 * 12 means fresh start, dont call deflt
444 * max num of fun calls
445 if (maxfun.eq.0) maxfun=500
447 * max num of iterations
448 if (maxmin.eq.0) maxmin=1000
452 * selects output unit
454 if (print_min_ini+print_min_stat+print_min_res.gt.0) iv(21)=iout
455 * 1 means to print out result
457 * 1 means to print out summary stats
458 iv(23)=print_min_stat
459 * 1 means to print initial x and d
461 * min val for v(radfac) default is 0.1
463 * max val for v(radfac) default is 4.0
466 * check false conv if (act fnctn decrease) .lt. v(26)*(exp decrease)
467 * the sumsl default is 0.1
469 * false conv if (act fnctn decrease) .lt. v(34)
470 * the sumsl default is 100*machep
472 * absolute convergence
473 if (tolf.eq.0.0D0) tolf=1.0D-4
475 * relative convergence
476 if (rtolf.eq.0.0D0) rtolf=1.0D-4
478 * controls initial step size
480 * large vals of d correspond to small components of step
493 if (ialph(i,1).gt.0) then
502 call sumsl(k,d,x,func_dc,grad_dc,iv,liv,lv,v,idum,rdum,fdum)
512 if (ialph(i,1).gt.0) then
523 cd call func_dc(k,x,nf,f,idum,rdum,fdum)
524 cd call grad_dc(k,x,nf,g,idum,rdum,fdum)
528 cd call func_dc(k,x,nf,f1,idum,rdum,fdum)
530 cd print '(i5,2f15.5)',i,g(i),(f1-f)/1.0D-5
539 subroutine func_dc(n,x,nf,f,uiparm,urparm,ufparm)
540 implicit real*8 (a-h,o-z)
545 include 'COMMON.SETUP'
546 include 'COMMON.DERIV'
547 include 'COMMON.IOUNITS'
549 include 'COMMON.CHAIN'
551 double precision energia(0:n_ene)
552 double precision ufparm
569 if (ialph(i,1).gt.0) then
579 call etotal(energia(0))
582 cd print *,'func_dc ',nf,nfl,f
587 subroutine grad_dc(n,x,nf,g,uiparm,urparm,ufparm)
588 implicit real*8 (a-h,o-z)
593 include 'COMMON.SETUP'
594 include 'COMMON.CHAIN'
595 include 'COMMON.DERIV'
597 include 'COMMON.INTERACT'
598 include 'COMMON.FFIELD'
600 include 'COMMON.IOUNITS'
603 double precision urparm(1)
604 dimension x(maxvar),g(maxvar)
610 cd print *,'grad_dc ',nf,nfl,nf-nfl+1,icg
611 if (nf-nfl+1) 20,30,40
612 20 call func_dc(n,x,nf,f,uiparm,urparm,ufparm)
626 if (ialph(i,1).gt.0) then
636 C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
648 if (ialph(i,1).gt.0) then