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

msimple.tpl (revision 1087)
70 70

  
71 71
DATA_SECTION
72 72
  init_int nobs
73
  init_int nrow
74
  matrix Y(1,nrow,1,nobs)
75
  matrix x(1,nrow,1,nobs)
73
  init_int nthread
74
  vector Y(1,nobs)
75
  vector x(1,nobs)
76 76
  number A
77 77
  number B
78 78

  
79
  int chunk_size
80

  
79 81
 LOCAL_CALCS
82
    chunk_size = nobs/nthread  + 1;
80 83
    A = 2.0;
81 84
    B = 4.0;
82 85
    random_number_generator rng(101);
83 86
    dvector err(1,nobs);
84
    for (int i = 1; i <= nrow; i++)
85
    {
86
       x(i).fill_randu(rng);
87
       x(i) *= 100.0;
88
       Y(i) = A*x(i) + B;
89
       err.fill_randn(rng);
90
       Y(i) += 5.0*err;
91
    }
87
    x.fill_randu(rng);
88
    x *= 100.0;
89
    Y = A*x + B;
90
    err.fill_randn(rng);
91
    Y += 5.0*err;
92
    chunk_size = nobs/nthread;
92 93

  
93 94
PARAMETER_SECTION
94 95
  init_number a   
95 96
  init_number b   
96
  vector ff(1,nrow)
97
  //matrix pred_Y(1,nrow, 1,nobs)
97
  vector ff(1,nthread)
98 98
  objective_function_value f
99 99

  
100 100
PRELIMINARY_CALCS_SECTION
......
105 105
  int ngroups=1;
106 106
  ivector ng(1,ngroups);
107 107
  // number of threads in group 1
108
  ng(1)=nrow;
108
  ng(1)=nthread;
109 109

  
110 110
  // create instance of pthread_manager class
111 111
  // third argument is number of bytes in the transfer buffer
112 112
  ad_comm::pthread_manager = new adpthread_manager(ngroups,ng,500);
113 113

  
114 114
  // create data vecor for argument to thread function
115
  new_thread_data* data1 = new new_thread_data[nrow+1];
116
  for (int i=1;i<=nrow;i++)
115
  new_thread_data* data1 = new new_thread_data[nthread+1];
116
  for (int i=1;i<=nthread;i++)
117 117
  {
118 118
    data1[i].thread_no = i; // only the thread number is imortant
119 119
    data1[i].m=0;           // not used
......
127 127
  
128 128
  // send constant data to the threads;
129 129
  // in this case rows of the independent variables
130
  for (int kk=1;kk<=nrow;kk++)
130
  int end_pos = 0;
131
  for (int kk=1;kk<=nthread;kk++)
131 132
  {
133
     int start_pos = end_pos + 1;
134
     end_pos = start_pos+chunk_size-1;
135
     if (end_pos > nobs)
136
         end_pos = nobs;
137
     cerr << " * * * chunk " << kk << " from " << start_pos << " to " << end_pos << endl;
138

  
132 139
     // take control of the constant buffer for sending
133 140
     ad_comm::pthread_manager->cwrite_lock_buffer(kk);
134 141
     // send x and Y
135
     ad_comm::pthread_manager->send_dvector(x(kk),kk);
136
     ad_comm::pthread_manager->send_dvector(Y(kk),kk);
142
     ad_comm::pthread_manager->send_dvector(x(start_pos,end_pos),kk);
143
     ad_comm::pthread_manager->send_dvector(Y(start_pos,end_pos),kk);
137 144
     // release the constant buffer
138 145
     ad_comm::pthread_manager->cwrite_unlock_buffer(kk);
139 146
  }
140 147

  
141

  
142 148
PROCEDURE_SECTION
143 149
  // send variable data to threads
144
  for (int kk=1;kk<=nrow;kk++)
150
  for (int kk=1;kk<=nthread;kk++)
145 151
  {
146 152
     // take control of the variable buffer for sending
147 153
     ad_comm::pthread_manager->write_lock_buffer(kk);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff