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

admb_thread.cpp (revision 757)
3 3
#include "pt_trace.h"
4 4

  
5 5
#include <admodel.h>
6
#include "adpthread_manager.h"
6
//#include "adpthread_manager.h"
7
#include "adthread.h"
7 8
#include "nst.htp"
8 9

  
9
extern adpthread_manager * nst_thread_manager;
10
extern adpthread_manager * test_thread_manager;
10 11
extern void * mp_ptr; 
11
 
12
//extern pthread_mutex_t * smutex;
13
//extern pthread_cond_t * scondition; 
12 14

  
13 15
void admb_thread(void * ptr)
14 16
{
15 17
  thread_data * tptr = (thread_data *) ptr;
16 18
  thread_data::id=tptr->thread_no;
17 19
  int sno=tptr->thread_no;
20
  pthread_mutex_lock(&test_thread_manager->smutex[sno]);
21
  while (mp_ptr == NULL) pthread_cond_wait(&test_thread_manager->scondition[sno],
22
                                           &test_thread_manager->smutex[sno]);
23
  pthread_mutex_unlock(&test_thread_manager->smutex[sno]);
24
  model_parameters * mp = (model_parameters*)mp_ptr;
25
  const int m = mp->m;
18 26
  {
27
    //arrmblsize = 35000000;
28
 
19 29
    gradient_structure::set_MAX_NVAR_OFFSET(10000);
20
    gradient_structure::set_GRADSTACK_BUFFER_SIZE(100000000);
21
    gradient_structure::set_CMPDIF_BUFFER_SIZE   (100000000);
22
    //gradient_structure::set_MAX_NVAR_OFFSET(10000);
23
    gradient_structure gs(2000000);
24
 
25
    dvar_vector v= nst_thread_manager->get_dvar_vector_from_master(sno);
26
    int mmin=v.indexmin();
27
    int mmax=v.indexmax();
28
    model_parameters * mp = (model_parameters*)mp_ptr;
29
    const int m = mp->m;
30
    dvar_matrix M(1,m,1,m);
31
    int ii=0;
32
    for (int i=1;i<=m;i++)
30
    gradient_structure::set_GRADSTACK_BUFFER_SIZE(20000000);
31
    gradient_structure::set_CMPDIF_BUFFER_SIZE(20000000);
32
    gradient_structure::set_MAX_NVAR_OFFSET(30000);
33
    gradient_structure gs(1000000);
34
    do
33 35
    {
34
      for (int j=1;j<=m;j++)
35
      {
36
        M(i,j)=v(++ii);
37
      }
38
    }
39
    dvector u(1,m);
40
    u.fill_seqadd(sno,1.0/sno);
36
       double lflag = test_thread_manager->get_double_from_master(sno); 
37
       if (lflag == 0.0) break;
38
       dvar_vector v= test_thread_manager->get_dvar_vector_from_master(sno);
39
       int mmin=v.indexmin();
40
       int mmax=v.indexmax();
41
       dvar_matrix M(1,m,1,m);
42
       int ii=0;
43
       for (int i=1;i<=m;i++)
44
       {
45
         for (int j=1;j<=m;j++)
46
         {
47
           M(i,j)=v(++ii);
48
         }
49
       }
50
       dvector u(1,m);
51
       u.fill_seqadd(sno,1.0/sno);
41 52
    
42
    dvariable z=0.0;
43
    for (int i=1;i<=20;i++)
44
    {
45
      z+=norm2(solve(M,u+double(i)));
53
       dvariable z=0.0;
54
       for (int i=1;i<=20;i++)
55
       {
56
         z+=norm2(solve(M,u+double(i)));
57
       }
58
  
59
       test_thread_manager->send_dvariable_to_master(z,sno);
60
       slave_gradcalc();
46 61
    }
47
  
48
    nst_thread_manager->send_dvariable_to_master(z,sno);
49
    slave_gradcalc();
62
    while(1);
50 63
  }
51 64
}
52 65

  

Also available in: Unified diff