Revision 1174 branches/threaded2merge/tests/threads/msimple/msimple.tpl

msimple.tpl (revision 1174)
5 5
  #include <fvar.hpp>
6 6
  #include <adthread.h>
7 7

  
8
 
9 8
  // write the function to run on the threads
10 9
  void* simple_thread(void* ptr)
11 10
  {
......
21 20
      // get the thread number
22 21
      ad_comm::pthread_manager->set_slave_number(tptr->thread_no);
23 22

  
24
    
25 23
      // take control of the constant buffer for reading
26 24
      ad_comm::pthread_manager->cread_lock_buffer(0);
27 25
      // read the independent variables IN THE SAME ORDER AS THEY ARE SENT
......
29 27
      cerr << " * * *  got x chunk " << tptr->thread_no << " from " << x.indexmin() << " to " << x.indexmax() << endl;
30 28
      dvector Y = ad_comm::pthread_manager->get_dvector(0);
31 29
      cerr << " * * *  got Y chunk " << tptr->thread_no << " from " << Y.indexmin() << " to " << Y.indexmax() << endl;
32
     // release the constant buffer
30
      // release the constant buffer
33 31
      ad_comm::pthread_manager->cread_unlock_buffer(0);
34 32

  
35 33
      do
36 34
      {
37 35
         // take control of the variable buffer for reading
38 36
         ad_comm::pthread_manager->read_lock_buffer(0);
37

  
39 38
         // read the finished signal
40 39
         int lflag=ad_comm::pthread_manager->get_int(0);
41 40
         if (lflag == 0) break;
......
63 62
   
64 63
         // compute derivative contribution for this thread 
65 64
         slave_gradcalc();
66
      }
67
      while (1);
65
      } while (1);
66

  
68 67
      // close thread
69 68
      pthread_exit(ptr);
70 69
   }
71 70

  
72

  
73 71
DATA_SECTION
74 72
  init_int nobs
75 73
  init_int nthread
......
92 90
    x *= 100.0;
93 91
    Y = A*x + B;
94 92

  
95

  
96 93
    err.fill_randn(rng);
97 94
    Y += S*err;
98 95
    chunk_size = nobs/nthread;
......
115 112
    if (1) exit(1);
116 113
    */
117 114

  
118

  
119 115
PARAMETER_SECTION
120 116
  init_number a   
121 117
  init_number b   
......
152 148
  // create the threads
153 149
  ad_comm::pthread_manager->create_all(data1);
154 150

  
155
  
156 151
  // send constant data to the threads;
157 152
  // in this case rows of the independent variables
158 153
  int end_pos = 0;
......
160 155
  {
161 156
     int start_pos = end_pos + 1;
162 157
     end_pos = start_pos+chunk_size-1;
163
     if (kk == nthread)
164
         end_pos = nobs;
158
     if (kk == nthread) end_pos = nobs;
165 159

  
166 160
     // take control of the constant buffer for sending
167 161
     ad_comm::pthread_manager->cwrite_lock_buffer(kk);
......
187 181
     ad_comm::pthread_manager->send_dvariable(b,kk); 
188 182
     // release the variable buffer
189 183
     ad_comm::pthread_manager->write_unlock_buffer(kk);
190
  
191 184
  }
192 185

  
193 186
  // get results of thread computations
......
196 189
      // take control of the variable buffer for reading
197 190
      ad_comm::pthread_manager->read_lock_buffer(kk);
198 191
      ff(kk) = ad_comm::pthread_manager->get_dvariable(kk);
199
     // release the variable buffer
192
      // release the variable buffer
200 193
      ad_comm::pthread_manager->read_unlock_buffer(kk);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff