Revision 779 branches/pthreads-737/tests/nst/thread_stuff.cpp

thread_stuff.cpp (revision 779)
1 1
#include <admodel.h>
2
#include <cstddef>
2 3
#include "adthread.h"
3
#include "pt_trace.h"
4
#if !defined(OPT_LIB)
5
#  if !defined(CHK_ID_STRING)
6
#    define CHK_ID_STRING
7
#  endif
8
#endif
4 9

  
5 10
/* prototype for thread routine */
6 11
void admb_thread(void * ptr);
7 12

  
8
/* struct to hold data to be passed to a thread
9
   this shows how multiple data items can be passed to a thread */
10
 // union a_union {
11
 //     char * p;
12
 //     double d;
13
 // };
14
 // 
15
  a_union au;
16
 // 
17
 // 
18
 // class thread_data
19
 // {
20
 // public:
21
 //   static int __thread id;
22
 //   int thread_no;
23
 //   int bufsize;
24
 //   pthread_mutex_t *inlock;
25
 //   pthread_mutex_t *outlock;
26
 //   void * transfer_buffer;
27
 //   char message[100];
28
 // };
29 13
pthread_mutex_t mutex_print;
30 14

  
31
const int NSLAVES=24;
15
//const int NSLAVES=1;
32 16

  
33
int mflag[NSLAVES+1];
34
int sflag[NSLAVES+1];
35
pthread_mutex_t smutex[NSLAVES+1];
36
pthread_cond_t scondition[NSLAVES+1];
37
pthread_cond_t mcondition[NSLAVES+1];
38

  
39 17
typedef char * pchar;
18
void pthread_master_unpack_vector_derivatives(void);
40 19

  
41
void send_double_to_slave(const double &x,void * transfer_buffer,int sno)
20
void send_double_to_master(double &x,void * current_bptr,int sno)
42 21
{
22
  memcpy(current_bptr,&x,sizeof(double));
23
}
24

  
25
void adpthreads_slave_pack_vector_derivative(void);
26

  
27
double get_double_from_master(void * current_bptr, int sno)
28
{
29
  double x;
30
  memcpy(&x,current_bptr,sizeof(double));
31
  return x;
32
}
33

  
34
void adpthreads_slave_pack_number_derivative(void)
35
{
36
  verify_identifier_string("G1");
37
  int sno=restore_int_value();
38
  void * ptr=restore_pointer_value();
39
  verify_identifier_string("D");
40
  prevariable_position dvpos=restore_prevariable_position();
41
  double dv=restore_prevariable_derivative(dvpos);
42
  //cout << "sending " << dv << " to master " << endl;
43
  send_double_to_master(dv,ptr,sno);
44
  //pvm_pack(dv);
45
  verify_identifier_string("C");
46
}
47

  
48

  
49
dvariable get_dvariable_from_master(void * current_bptr, int sno)
50
{
51
  dvariable x;
52
  value(x)=get_double_from_master(current_bptr,sno);
53
  save_identifier_string("C");
54
  x.save_prevariable_position();
55
  save_identifier_string("D");
56
  save_pointer_value(current_bptr);
57
  save_int_value(sno);
58
  save_identifier_string("G1");
59
  gradient_structure::GRAD_STACK1->
60
            set_gradient_stack(adpthreads_slave_pack_number_derivative);
61
  return x;
62
}
63

  
64

  
65
void adpthreads_slave_pack_vector_derivative(void)
66
{
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff