Revision 1100 branches/threaded2/examples/threaded/mforest/mforest.tpl

mforest.tpl (revision 1100)
3 3
  #include <admodel.h>
4 4
  #include <adthread.h>
5 5

  
6
  #include "trace.h"
7 6

  
7
  /**
8
  Specialized class to encapsulate variables needed to run the model.
9
  In the original forest.tpl example, the functions 
10
     dvariable trapzd(double a,double b,int n);
11
     dvariable adromb(double a, double b, int ns);
12
  are included in the function_minimzer class so that they would be inherited
13
  by the model_data class. It is probably a bad idea to use such shared objects
14
  in threads. Moving them to this thread_funnel class eliminates the possiblity
15
  of false sharing and the static variables in trapzd.
16
  */
8 17
  class thread_funnel
9 18
  {
10 19
   public:
......
14 23

  
15 24
     // constant model objects
16 25
     int nsteps;
17
     //int k;
18 26
     dvector a;
19
     //dvector freq;
20 27
     int a_index;
21 28
  
22 29
     // variable objects
......
27 34
     dvariable tau;
28 35
     dvariable nu;
29 36
     dvariable sigma;
30
     //dvar_vector S;
31
     //dvariable f;
32 37
  
33 38
     int get_constant_objects();
34 39
     int get_variable_objects();
......
38 43
     dvariable trapzd(double a,double b,int n);
39 44
     dvariable adromb(double a, double b, int ns);
40 45
  };
41
  /*
42
  dvariable tfh(thread_funnel* p, const dvariable& z)
43
  {
44
      return p->h(z);
45 46

  
46
  }
47
  /**
48
  Formerly FUNCTION dvariable h(const dvariable& z) in the
49
  original example. Since it is now a class member, there it is unnecessary to
50
  pass a pointer to the function. Passing a pointer to a member function also
51
  also violates C++ rules make making it necessary to do a lot of obscure casts.
47 52
  */
48

  
49
  //FUNCTION dvariable h(const dvariable& z)
50 53
  dvariable thread_funnel::h(const dvariable& z)
51 54
  {
52 55
     dvariable tmp;
......
74 77
      for (sum=0.0,j=1;j<=interval;j++,x+=hn) sum += h(x);
75 78
      interval *= 2;
76 79
      s=0.5*(s+(b-a)*sum/num_interval);
77
      //TTRACE(x,s);
78 80
      return s;
79 81
    }
80 82

  
......
112 114

  
113 115
      // read the independent variables IN THE SAME ORDER AS THEY ARE SENT
114 116
      nsteps = ad_comm::pthread_manager->get_int(0);
115
      //TRACE(nsteps)
116 117
      a = ad_comm::pthread_manager->get_dvector(0);
117
      //TRACE(a)
118 118
      a_index = ad_comm::pthread_manager->get_int(0);
119
      TRACE(a_index)
120 119
      
121 120
      // release the constant buffer
122 121
      ad_comm::pthread_manager->cread_unlock_buffer(0);
......
156 155
      // get the thread number
157 156
      ad_comm::pthread_manager->set_slave_number(tptr->thread_no);
158 157

  
158
      // create instance of thread_funnel for this thread
159 159
      thread_funnel tf;
160
      //TTRACE(tptr->thread_no,tf.a_index)
161 160
      tf.get_constant_objects();
162
      //TTRACE(tptr->thread_no,tf.a_index)
163 161
      if (tptr->thread_no != tf.a_index)
164 162
          cerr << "error getting a_index" << endl;
165 163
      do
166 164
      {
167 165
         int lflag = tf.get_variable_objects();
168
         //TRACE(lflag)
169 166
         if (lflag == 1) break;
170 167
    
171 168
         dvariable Integral=tf.adromb(-3.0,3.0,tf.nsteps);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff