Revision 766
branches/pthreads737/tests/multisimple/simple_thread.cpp (revision 766)  

1 
//$Id: simple_thread.cpp 3054 20130110 22:54:36Z jsibert $ 

2 
#include "pt_trace.h" 

3 
#include <admodel.h> 

4 
#include "adpthread_manager.h" 

5 
#include "msimple.htp" 

6 
extern adpthread_manager * thread_manager; 

7 
extern void * mp_ptr; 

8 
extern pthread_mutex_t trace_mutex; 

9 
static int nentries = 0; 

10 


11 
void* simple_thread(void * ptr) 

12 
{ 

13 
nentries ++; 

14 
thread_data * tptr = (thread_data *) ptr; 

15 
thread_data::id=tptr>thread_no; 

16 
const int sno=tptr>thread_no; 

17 
model_parameters * mp = (model_parameters*)mp_ptr; 

18 
TTTRACE(nentries,sno, ((void*)mp)) 

19  
20 
gradient_structure::set_MAX_NVAR_OFFSET(200); 

21 
gradient_structure::set_GRADSTACK_BUFFER_SIZE(2200); 

22 
gradient_structure::set_CMPDIF_BUFFER_SIZE (32000L); 

23 
gradient_structure gs;//(2000000); 

24  
25 
//PROCEDURE_SECTION 

26 
//pred_Y=a*x+b; 

27 
//f=(norm2(pred_YY)); 

28 
//f=nobs/2.*log(f); // make it a likelihood function so that 

29 
// covariance matrix is correct 

30 
TTTRACE(sno,mp>a, mp>b) 

31 
TTTRACE(sno,mp>x(sno).indexmin(),mp>x(sno).indexmax()); 

32 
TTRACE(sno,mp>x(sno)) 

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

35 
TTTRACE(sno,pred_Y.indexmin(),pred_Y.indexmax()) 

36 
pred_Y = mp>a * mp>x(sno) + mp> b; 

37 
TTTRACE(sno,pred_Y.indexmin(),pred_Y.indexmax()); 

38 
TTRACE(sno,pred_Y); 

39  
40 
dvariable f=norm2(pred_Ymp>Y(sno)); 

41 
f=mp>nobs/2.*log(f); // make it a likelihood function so that 

42 
// covariance matrix is correct 

43 
TTRACE(sno,f) 

44  
45 
thread_manager>send_dvariable_to_master(f, sno); 

46 
slave_gradcalc(); 

47 
return; 

48 
} 

49 

branches/pthreads737/tests/multisimple/msimple.tpl (revision 766)  

1 
//$Id: msimple.tpl 3054M 20130111 20:23:43Z (local) $ 

2  
3 
GLOBALS_SECTION 

4 
#include <pthread.h> 

5 
#include "adpthread_manager.h" 

6 
#include "pt_trace.h" 

7 
pthread_mutex_t trace_mutex= PTHREAD_MUTEX_INITIALIZER; 

8 
ofstream clogf; 

9 
int NSLAVES=0; 

10  
11  
12 
void * mp_ptr = NULL; 

13 
adpthread_manager * thread_manager= NULL; 

14 
void* simple_thread(void * ptr); 

15 
int __thread thread_data::id=1; 

16  
17  
18  
19 
DATA_SECTION 

20 
init_int nobs 

21 
init_int nslaves 

22  
23 
matrix Y(1,nslaves,1,nobs) 

24 
matrix x(1,nslaves,1,nobs) 

25  
26 
LOCAL_CALCS 

27 
double A = 2.0; 

28 
double B = 4.0; 

29 
random_number_generator rng(101); 

30 
dvector err(1,nobs); 

31 
for (int i = 1; i <= nslaves; i++) 

32 
{ 

33 
x(i).fill_randu(rng); 

34 
x(i) *= 100.0; 

35 
Y(i) = A*x(i) + B; 

36 
err.fill_randn(rng); 

37 
Y(i) += 5.0*err; 

38 
} 

39 
NSLAVES = nslaves; 

40 
/* 

41 
if (1) 

42 
{ 
Also available in: Unified diff