Revision 1031

branches/threaded2/examples/threaded/multisimple/simple.dat (revision 1031)
1
# number of observations
2
     10
3
# observed Y values
4
    1.4  4.7  5.1  8.3  9.0  14.5  14.0  13.4  19.2  18 
5
# observed x values
6
    -1  0 1  2  3  4  5  6  7  8        
7

  
branches/threaded2/examples/threaded/multisimple/simple_thread.cpp (revision 1031)
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/msimple.tpl (revision 1031)
1
//$Id: msimple.tpl 3054M 2013-01-11 20:23:43Z (local) $
2

  
3
GLOBALS_SECTION
4
  #include <pthread.h>
5
  #include <fvar.hpp>
6
  #include <adthread.h>
7
  //#include "pt_trace.h"
8
  pthread_mutex_t trace_mutex= PTHREAD_MUTEX_INITIALIZER;
9
  ofstream clogf;
10

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff