Revision 1048 branches/threaded2/tests/multisimple/msimple.tpl

msimple.tpl (revision 1048)
4 4
  #include <pthread.h>
5 5
  #include <fvar.hpp>
6 6
  #include <adthread.h>
7
  //#include "pt_trace.h"
8
  pthread_mutex_t trace_mutex= PTHREAD_MUTEX_INITIALIZER;
9
  ofstream clogf;
7
 
8
  void simple_thread(void * ptr)
9
  {
10
      new_thread_data * tptr = (new_thread_data *) ptr;
10 11

  
12
      gradient_structure::set_MAX_NVAR_OFFSET(10000);
13
      gradient_structure::set_GRADSTACK_BUFFER_SIZE(20000000);
14
      gradient_structure::set_CMPDIF_BUFFER_SIZE   (20000000);
15
      gradient_structure gs(10000000);
16
   
17
      ad_comm::pthread_manager->set_slave_number(tptr->thread_no);
11 18

  
12
  void * mp_ptr = NULL;
13
  void* simple_thread(void * ptr);
19
      ad_comm::pthread_manager->cread_lock_buffer(0);
20
      dvector x = ad_comm::pthread_manager->get_dvector(0);
21
      dvector Y = ad_comm::pthread_manager->get_dvector(0);
22
      ad_comm::pthread_manager->cread_unlock_buffer(0);
14 23

  
24
      do
25
      {
26
         ad_comm::pthread_manager->read_lock_buffer(0);
27
         int lflag=ad_comm::pthread_manager->get_int(0);
28
         if (lflag == 0) break;
29
         dvariable a =ad_comm::pthread_manager->get_dvariable(0);
30
         dvariable b =ad_comm::pthread_manager->get_dvariable(0);
31
         ad_comm::pthread_manager->read_unlock_buffer(0);
32

  
33
         dvar_vector pred_Y(x.indexmin(),x.indexmax());
34

  
35
         pred_Y = a * x +  b;
36
         dvariable f=norm2(pred_Y-Y); 
37
   
38
         ad_comm::pthread_manager->write_lock_buffer(0);
39
         ad_comm::pthread_manager->send_dvariable_to_master(f, 0);
40
         ad_comm::pthread_manager->write_unlock_buffer(0);
41
   
42
         slave_gradcalc();
43
      }
44
      while (1);
45
      pthread_exit(ptr);
46
   }
47

  
48

  
15 49
DATA_SECTION
16 50
  init_int nobs
17 51
  init_int nrow
......
21 55
  number B
22 56

  
23 57
 LOCAL_CALCS
24
    //TTRACE(nobs,nrow)
58
    cout << nobs << "  " << nrow << endl;
25 59
    A = 2.0;
26 60
    B = 4.0;
27 61
    random_number_generator rng(101);
......
35 69
       Y(i) += 5.0*err;
36 70
    }
37 71

  
38
    /*
39
    if (1)
40
    {
41
       TTRACE(nobs,nrow)
42
       TTRACE(A,B)
43
       TRACE(x)
44
       TRACE(Y)
45
       ad_exit(1);
46
    }
47
    */
48

  
49 72
PARAMETER_SECTION
50 73
  init_number a   
51 74
  init_number b   
......
54 77
  objective_function_value f
55 78

  
56 79
PRELIMINARY_CALCS_SECTION
80
    cout << nobs << "  " << nrow << endl;
57 81
  //TRACE(x)
58 82
  //TRACE(Y)
59 83
  a = 1.0;
60 84
  b = 2.0;
61
  mp_ptr = (void*)this;
62
  //TTRACE(mp_ptr,((void*)this));
63 85

  
64 86
  int ngroups=1;
65 87
  ivector ng(1,ngroups);
......
75 97
  }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff