Revision 1096 branches/threaded2/examples/threaded/multisimple/msimple.tpl

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

  
......
75 77
  vector x(1,nobs)
76 78
  number A
77 79
  number B
80
  number S
78 81

  
79 82
  int chunk_size
80 83

  
......
82 85
    chunk_size = nobs/nthread  + 1;
83 86
    A = 2.0;
84 87
    B = 4.0;
88
    S = 7.0;
85 89
    random_number_generator rng(101);
86 90
    dvector err(1,nobs);
87 91
    x.fill_randu(rng);
88 92
    x *= 100.0;
89 93
    Y = A*x + B;
94

  
95

  
90 96
    err.fill_randn(rng);
91
    Y += 5.0*err;
97
    Y += S*err;
92 98
    chunk_size = nobs/nthread;
99
    // for log-normal error
100
    //Y = elem_prod(Y,exp(S*err));
93 101

  
94 102
    /*
95 103
    cout << "chunk_size = " << chunk_size << endl;
......
111 119
PARAMETER_SECTION
112 120
  init_number a   
113 121
  init_number b   
122
  number s;
114 123
  vector ff(1,nthread)
115 124
  objective_function_value f
116 125

  
117 126
PRELIMINARY_CALCS_SECTION
118 127
  a = 1.0;
119 128
  b = 2.0;
129
  crit = 1e-3;
120 130

  
121 131
  // number of thread groups
122 132
  int ngroups=1;
......
126 136

  
127 137
  // create instance of pthread_manager class
128 138
  // third argument is number of bytes in the transfer buffer
129
  ad_comm::pthread_manager = new adpthread_manager(ngroups,ng,500);
139
  //ad_comm::pthread_manager = new adpthread_manager(ngroups,ng,500);
140
  ad_comm::pthread_manager = new adpthread_manager(ngroups,ng,32005);
130 141

  
131 142
  // create data vecor for argument to thread function
132 143
  new_thread_data* data1 = new new_thread_data[nthread+1];
......
151 162
     end_pos = start_pos+chunk_size-1;
152 163
     if (kk == nthread)
153 164
         end_pos = nobs;
154
     cerr << " * * * chunk " << kk << " from " << start_pos << " to " << end_pos << endl;
155 165

  
156 166
     // take control of the constant buffer for sending
157 167
     ad_comm::pthread_manager->cwrite_lock_buffer(kk);
158 168
     // send x and Y
169
     cerr << " * * * send x chunk " << kk << " from " << start_pos << " to " << end_pos << endl;
159 170
     ad_comm::pthread_manager->send_dvector(x(start_pos,end_pos),kk);
171
     cerr << " * * * send Y chunk " << kk << " from " << start_pos << " to " << end_pos << endl;
160 172
     ad_comm::pthread_manager->send_dvector(Y(start_pos,end_pos),kk);
161 173
     // release the constant buffer
162 174
     ad_comm::pthread_manager->cwrite_unlock_buffer(kk);
......
188 200
      ad_comm::pthread_manager->read_unlock_buffer(kk);
189 201
  }
190 202
  // sum the results to compute the objective function
191
  f = sum(ff);
192
  f = nobs/2.*log(f);    // make it a likelihood function so that
193
                              // covariance matrix is correct
203
  s = sum(ff);
204
  f = nobs/2.*log(s);    // make it a likelihood function so that
205
                         // covariance matrix is correct
194 206

  
195 207

  
196 208
REPORT_SECTION
197
  report << "A = " << A << "; B = " << B <<endl;
198
  report << "a = " << a << "; b = " << b <<endl;
209
  s = sqrt(s/nobs);
210
  report << "A = " << A << "; B = " << B << "; S = " << S <<endl;
211
  report << "a = " << a << "; b = " << b << "; s = " << s << endl;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff