Revision 757 branches/threaded2/tests/nst/adpthread_manager.cpp

adpthread_manager.cpp (revision 757)
47 47
    {
48 48
      transfer_buffer[i]=new char[bs];
49 49
      tb_save[i] = transfer_buffer[i];
50
      TTTRACE(i,(void*)transfer_buffer[i],(void*)tb_save[i])
51 50
      buffend[i]=transfer_buffer[i]+bs-1;
52
      TTTRACE(i,(void*)transfer_buffer[i],(void*)buffend[i])
53 51
    }
54 52
    //tb_lock=new pthread_rwlock_t[ns+1];
55 53
    //tb_lock--;
......
101 99
    for (int i=1;i<=nslaves;i++)
102 100
    {
103 101
      pthread_mutex_lock(smutex+i);
104
      TTTRACE(i,(void*)tb_save[i],(void*)transfer_buffer[i]);
105 102
      transfer_buffer[i]=tb_save[i];
106
      TTTRACE(i,(void*)tb_save[i],(void*)transfer_buffer[i]);
107 103
      pthread_mutex_init(smutex+i,NULL);
108
      TTTRACE(i,mflag[i],sflag[i])
109 104
      mflag[i] = 0;
110 105
      sflag[i] = 0;
111
      TTTRACE(i,mflag[i],sflag[i])
112 106
      //smutex[i] = PTHREAD_MUTEX_INITIALIZER;
113 107
      scondition[i] = PTHREAD_COND_INITIALIZER;
114 108
      mcondition[i] = PTHREAD_COND_INITIALIZER;
......
126 120
};
127 121
//a_union au;
128 122

  
123
void send_dvector_to_slave(const dvector &x,void * transfer_buffer,int sno)
124
{
125
  char * b = (char*)(transfer_buffer);
126
  int mmin=x.indexmin();
127
  int mmax=x.indexmax();
128
  int sz=mmax-mmin+1;
129
  pthread_mutex_lock(smutex+sno);
130
  // only write if buffer empty
131
  while (mflag[sno] == 1 || sflag[sno] ==1 ) 
132
    pthread_cond_wait(mcondition+sno,smutex+sno);
133
  memcpy(b,&mmin,sizeof(int));
134
  b+=sizeof(int);
135
  memcpy(b,&mmax,sizeof(int));
136
  b+=sizeof(int);
137
  memcpy(b,&(x(mmin)),sz*sizeof(double));
138

  
139
  mflag[sno] = 1;
140
  pthread_mutex_unlock(smutex+sno);
141
  pthread_cond_signal(scondition+sno);
142
}
143

  
144
dvariable get_dvariable_from_slave(void * transfer_buffer, int sno)
145
{
146
  dvariable x;
147

  
148
  value(x)=get_double_from_slave(transfer_buffer,sno);
149
  TTRACE(sno,x)
150

  
151
  save_identifier_string("C");
152
  x.save_prevariable_position();
153
  save_identifier_string("D");
154
  save_pointer_value(transfer_buffer);
155
  save_int_value(sno);
156
  save_identifier_string("G2");
157
  gradient_structure::GRAD_STACK1->
158
            set_gradient_stack(adpthreads_master_pack_number_derivative);
159
  return x;
160
}
161

  
162
double adpthread_manager::get_double_from_slave(int sno)
163
{
164
  return ::get_double_from_slave(transfer_buffer[sno],sno);
165
}
166

  
129 167
double get_double_from_slave(void * transfer_buffer, int sno)
130 168
{
131 169
  pthread_mutex_lock(smutex+sno);
......
144 182
  return x;
145 183
}
146 184

  
185
void adpthreads_master_pack_number_derivative(void)
186
{
187
  verify_identifier_string("G2");
188
  int sno=restore_int_value();
189
  void * ptr=restore_pointer_value();
190
  verify_identifier_string("D");
191
  prevariable_position dvpos=restore_prevariable_position();
192
  double dv=restore_prevariable_derivative(dvpos);
193
  cout << "sending " << dv << " to master " << endl;
194
  send_double_to_slave(dv,ptr,sno);
195
  //pvm_pack(dv);
196
  verify_identifier_string("C");
197
}
198

  
199
/*
147 200
double get_double_from_master(void * transfer_buffer, int sno)
148 201
{
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff