Revision 1087

branches/threaded2/examples/threaded/multisimple/simple_thread.cpp (revision 1087)
1
//$Id: simple_thread.cpp 3054 2013-01-10 22:54:36Z jsibert $
2
//#include "pt_trace.h"
3
#include <admodel.h>
4
#include <adthread.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
   pthread_mutex_lock(&ad_comm::pthread_manager->start_mutex);
14
   pthread_mutex_unlock(&ad_comm::pthread_manager->start_mutex);
15
   new_thread_data * tptr = (new_thread_data *) ptr;
16

  
17
   model_parameters * mp = (model_parameters*)mp_ptr; 
18
   //TRACE((void*)mp)
19
   //TTTRACE(mp->a,mp->b,mp->nobs)
20

  
21
   //int m=tptr->m;
22
   int sno=tptr->thread_no;
23
   //TRACE(sno)
24
   { 
25
      gradient_structure::set_MAX_NVAR_OFFSET(10000);
26
      gradient_structure::set_GRADSTACK_BUFFER_SIZE(20000000);
27
      gradient_structure::set_CMPDIF_BUFFER_SIZE   (20000000);
28
      gradient_structure gs(10000000);
29
   
30
      ad_comm::pthread_manager->set_slave_number(tptr->thread_no);
31
      do
32
      {
33
         ad_comm::pthread_manager->cread_lock_buffer(0);
34
         int lflag=ad_comm::pthread_manager->get_int(0);
35
         ad_comm::pthread_manager->cread_unlock_buffer(0);
36
         //TRACE(lflag)
37
         if (lflag == 0) break;
38
         ad_comm::pthread_manager->read_lock_buffer(0);
39
         dvariable a =ad_comm::pthread_manager->get_dvariable(0);
40
         dvariable b =ad_comm::pthread_manager->get_dvariable(0);
41
         ad_comm::pthread_manager->read_unlock_buffer(0);
42

  
43
         dvar_vector pred_Y(mp->x(sno).indexmin(),mp->x(sno).indexmax());
44
   //PROCEDURE_SECTION
45
     //pred_Y=a*x+b;
46
     //f=(norm2(pred_Y-Y)); 
47
     //f=nobs/2.*log(f);    // make it a likelihood function so that
48
                            // covariance matrix is correct
49
         //TTRACE(sno,sum(mp->x(sno)))
50
         //pred_Y = mp->a * mp->x(sno) + mp-> b; // does not work
51
         pred_Y = a * mp->x(sno) +  b;
52
   
53
         dvariable f=norm2(pred_Y-mp->Y(sno)); 
54
         //TTRACE(sno,f)
55
         f=mp->nobs/2.*log(f);    // make it a likelihood function so that
56
                                  // covariance matrix is correct
57
   
58
         ad_comm::pthread_manager->write_lock_buffer(0);
59
         //TTRACE(sno,f)
60
         ad_comm::pthread_manager->send_dvariable_to_master(f, 0);
61
         ad_comm::pthread_manager->write_unlock_buffer(0);
62
   
63
         slave_gradcalc();
64
      }
65
      while (1);
66
   }
67
   pthread_exit(ptr);
68
}
69
  
branches/threaded2/examples/threaded/multisimple/Makefile (revision 1087)
20 20
LFLAGS = -L$(ADMB_HOME)/lib -ldf1b2s -ladmod -ladt -lads -ldf1b2s -ladmod -ladt -lads -ldf1b2s -ladmod -ladt -lads -lpthread
21 21
#LFLAGS = -L$(ADMB_HOME)/lib -ldf1b2s -ladmod -ladt -lado -ldf1b2o -ladmod -ladt -lado -ldf1b2o -ladmod -ladt -lado -lpthread
22 22

  
23
#OBJECTS=adpthread_manager.o msimple.o simple_thread.o
24
OBJECTS=msimple.o
25 23

  
26
# link the object file into the executable 
27
msimple: $(OBJECTS) 
28
	@echo
29
	@echo ------- Link $@
30
	$(LL) -o $@ $^ $(LFLAGS)
31
	@echo ------- Done
24
all: msimple
32 25

  
33
msimple1: msimple1.o
26
%:%.o
34 27
	@echo
35 28
	@echo ------- Link $@
36 29
	$(LL) -o $@ $^ $(LFLAGS)
37 30
	@echo ------- Done
38 31

  
39
simple_thread.o: simple_thread.cpp msimple.tpl msimple.htp
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff