Revision 1636

trunk/src/nh99/profmin.cpp (revision 1636)
1
/*
2
 * $Id$
3
 *
4
 * Author: David Fournier
5
 * Copyright (c) 2008-2012 Regents of the University of California
6
 */
7
#include <admodel.h>
8

  
9
void fooledit2(void){;}
10

  
11
void fooledit(void)
12
{
13
  fooledit2();
14
}
15

  
16
#if defined(USE_ADPVM)
17
int check_pvm_message(int i,int j)
18
{
19
  int arrived=0;
20
 /*
21
  int mestag=-1;
22
  int arrived=pvm_probe(ad_comm::pvm_manager->id(i,j),mestag);
23
  if (arrived) fooledit();
24
 */
25
  return arrived;
26
}
27

  
28
void function_minimizer::pvm_master_function_evaluation_profile(double& f,
29
  independent_variables& x,const dvector & _g,int nvar,int iprof,double weight,
30
  double new_value)
31
{
32
  dvector & g=(dvector &) _g;
33

  
34
  grad_chk();
35
  dvariable vf=0.0;
36
  dvar_vector vx=dvar_vector(x);
37
  vf=initial_params::reset(vx);
38
  send_x_to_slaves(vx);
39
  *objective_function_value::pobjfun=0.0;
40
  userfunction();
41
  dvariable tv=likeprof_params::likeprofptr[iprof]->variable();
42
  vf+=weight*square(new_value-tv);
43
  vf+=*objective_function_value::pobjfun;
44
  imatrix im=get_int_from_slaves();
45
  if (im(1,1)!=67)
46
  {
47
    cout << "Error in im" << endl;
48
    ad_exit(1);
49
  }
50

  
51
  dvar_matrix fslave=get_f_from_slaves();
52
  vf+=sum(fslave);
53
  f=value(vf);
54
  gradcalc(nvar,g);
55
  int arrived=check_pvm_message(1,1);
56
  if (arrived)
57
    cout << arrived << endl;
58
  // !!! dave
59
  grad_chk();
60
}
61

  
62

  
63
  void function_minimizer::pvm_master_prof_minimize(int iprof, double sigma,
64
    double new_value, const double& _fprof,const int underflow_flag,
65
    double global_min, const double& _penalties,
66
    const double& _final_weight)
67
  {
68
    double& penalties=(double&) _penalties;
69
    double& fprof=(double&) _fprof;
70
    double& final_weight=(double&) _final_weight;
71
    int arrived=check_pvm_message(1,1);
72
   send_int_to_slaves(underflow_flag);
73
   if (!underflow_flag)
74
   {
75
    //int max_profile_phases=1;
76
    int max_profile_phases=3;
77
    int profile_phase=1;
78
    initial_params::current_phase = initial_params::max_number_phases;
79
    while (profile_phase <= max_profile_phases)
80
    {
81
     {
82
      send_int_to_slaves(5);
83
      // get the number of active parameters
84
      int nvar=initial_params::nvarcalc();
85
      dvector g(1,nvar);
86
      independent_variables x(1,nvar);
87
      // get the initial values into the x vector
88
      initial_params::xinit(x);
89
      fmm fmc(nvar);
90
      fmc.maxfn= maxfn;
91
      fmc.iprint= iprint;
92
      fmc.crit = crit;
93
      fmc.imax = imax;
94
      fmc.dfn= dfn;
95
      fmc.scroll_flag= scroll_flag;
96
      fmc.min_improve=min_improve;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff