Revision 757

branches/threaded2/tests/nst/nst.tpl (revision 757)
1 1
//$Id: $
2 2

  
3 3
GLOBALS_SECTION
4
  #include <pthread.h>
5
  #include "adpthread_manager.h"
4
  #include <admodel.h>
5
  #include "adthread.h"
6

  
7
  int __thread thread_data::id;
8
  void admb_thread(void * ptr);
9

  
6 10
  #include "pt_trace.h"
7 11
  pthread_mutex_t trace_mutex= PTHREAD_MUTEX_INITIALIZER;
8 12
  ofstream clogf;
9
  const int NSLAVES=16;
13
  //const int NSLAVES=10;
14
  //extern int NSLAVES;
10 15

  
11

  
12 16
  void * mp_ptr = NULL;
13
  adpthread_manager * nst_thread_manager= NULL;
14
  void* admb_thread(void * ptr);
15
  int __thread thread_data::id=-1;
16 17

  
17 18

  
18 19
DATA_SECTION
19
  init_int m
20
  int m
20 21
  int m2
21 22
  int n
23
  vector x
24
  int NSLAVES
22 25
 LOCAL_CALCS
26
   m=150;
23 27
   m2 = m*m;
28
   NSLAVES=24;
24 29
   n = NSLAVES;
25 30
   TTTRACE(m,m2,NSLAVES)
31
   x.allocate(1,m2);
32
   TTRACE(x.indexmin(),x.indexmax())
33
   random_number_generator rng(101);
34
   x.fill_randn(rng);
35
   TRACE(x)
26 36

  
27 37

  
28 38
PARAMETER_SECTION
29
  init_vector x(1,m2)
30
  vector vx(1,m2)
39
  init_vector vx(1,m2)
31 40
  objective_function_value f
32 41
  vector yy(1,NSLAVES)
33 42

  
......
36 45
  TTRACE(mp_ptr,((void*)this));
37 46
  mp_ptr = (void*)this;
38 47
  TTRACE(mp_ptr,((void*)this));
39
  TRACE(NSLAVES)
40
  nst_thread_manager = new adpthread_manager(NSLAVES,50000);
41
  thread_data* data1 = new thread_data[NSLAVES+1];
42
  data1 --;
43
  // initialize data to pass to thread 1
44
  for (int i=1;i<=NSLAVES;i++)
48
  for (int i = 1; i <= NSLAVES; i++)
45 49
  {
46
    data1[i].thread_no = i;
47
    TTRACE(i,data1[i].thread_no)
50
    pthread_mutex_unlock(&test_thread_manager->smutex[i]);
51
    pthread_cond_signal(&test_thread_manager->scondition[i]);
48 52
  }
49
  //const int n=NSLAVES;
50
  nst_thread_manager->create_all(&admb_thread,data1);
51 53
 
52
  TTRACE(x.indexmin(),x.indexmax())
54
  TRACE(NSLAVES)
55
  vx = dvar_vector(x); 
53 56

  
54
  dvector tx(1,m2);
55
  random_number_generator rng(101);
56
  tx.fill_randn(rng);
57
  x = tx;
58
  TRACE(x)
59

  
60 57
PROCEDURE_SECTION
61
  vx = x;
58
  double cf=0.0;
59
  int nloop=3;
60
  adtimer adt;
62 61
  for (int kk=1;kk<=n;kk++)
63 62
  {
64
    TTRACE(kk,vx)
65
    nst_thread_manager->send_dvar_vector_to_slave(vx,kk);
63
     TTRACE(kk,vx)
64
     test_thread_manager->send_double_to_slave(1.0,kk);
65
     test_thread_manager->send_dvar_vector_to_slave(vx,kk);
66 66
  }
67
     
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff