Revision 1235 branches/threaded2merge/src/linad99/xthread_stuff.cpp

xthread_stuff.cpp (revision 1235)
29 29
    int s2 = sno;
30 30
    pthread_mutex_lock(ssmutex[s1]+s2);
31 31
    // only write if buffer empty
32
    while (smflag(s1,s2) == 1 || ssflag(s1,s2) ==1 ) 
32
    while (smflag(s1,s2) == 1 || ssflag(s1,s2) ==1 )
33 33
      pthread_cond_wait(smcondition[s1]+s2,ssmutex[s1]+s2);
34 34
    save_identifier_string("YX");
35 35
    save_int_value(sno);
......
46 46
    int s1 = sno;
47 47
    pthread_mutex_lock(ssmutex[s1]+s2);
48 48
    // only write if buffer empty
49
    while (smflag(s1,s2) == 1 || ssflag(s1,s2) ==1 ) 
49
    while (smflag(s1,s2) == 1 || ssflag(s1,s2) == 1)
50 50
      pthread_cond_wait(sscondition[s1]+s2,ssmutex[s1]+s2);
51 51
    save_identifier_string("TYD");
52 52
    save_int_value(sno);
......
57 57
    gradient_structure::GRAD_STACK1->
58 58
        set_gradient_stack(::adjoint_adwrite_lock_buffer_2);
59 59
  }
60
}   
60
}
61 61
void adpthread_manager::cwrite_lock_buffer(int sno)
62 62
{
63
  if (logflag)
63
  int tn2 = ad_comm::pthread_manager->get_slave_number();
64
  if (tn2 < sno)  // old master write to slave
64 65
  {
65
    //*(logfiles[0]) << " write_lock_buffer_master"   << endl;
66
    //adt[0].get_elapsed_time_and_reset();
67
  }
68
  int tn2=ad_comm::pthread_manager->get_slave_number();
69
  if (tn2==sno)
70
  {
71
    //cerr << "Error -- process can not write to itself" << endl;
72
    ad_exit(1);
73
  }
74
  else if (tn2<sno)  // old master write to slave
75
  {
76 66
    int s1 = tn2;
77 67
    int s2 = sno;
78 68
    pthread_mutex_lock(ssmutex[s1]+s2);
79 69
    // only write if buffer empty
80
    while (smflag(s1,s2) == 1 || ssflag(s1,s2) ==1 ) 
70
    while (smflag(s1,s2) == 1 || ssflag(s1,s2) == 1)
81 71
      pthread_cond_wait(smcondition[s1]+s2,ssmutex[s1]+s2);
82 72
  }
83
  else if (sno<tn2)  // old slave write to master
73
  else if (sno < tn2)  // old slave write to master
84 74
  {
85 75
    int s2 = tn2;
86 76
    int s1 = sno;
87 77
    pthread_mutex_lock(ssmutex[s1]+s2);
88 78
    // only write if buffer empty
89
    while (smflag(s1,s2) == 1 || ssflag(s1,s2) ==1 ) 
79
    while (smflag(s1,s2) == 1 || ssflag(s1,s2) == 1)
90 80
      pthread_cond_wait(sscondition[s1]+s2,ssmutex[s1]+s2);
91 81
  }
92
}   
82
  else
83
  {
84
    cerr << "Error -- process can not write to itself" << endl;
85
    ad_exit(1);
86
  }
87
}
88
void adpthread_manager::cwrite_unlock_buffer(int sno)
89
{
90
  int tn2 = ad_comm::pthread_manager->get_slave_number();
91
  if (tn2 < sno)  // old master write to slave
92
  {
93
    int s1 = tn2;
94
    int s2 = sno;
95
    scurrent_bptr[s1][s2]=stransfer_buffer[s1][s2];
96
    smflag(s1,s2) = 1;
97
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
98
    pthread_cond_signal(sscondition[s1]+s2);
99
    pthread_mutex_unlock(ssmutex[s1]+s2);
100
  }
101
  else if (sno < tn2)  // old slave write to master
102
  {
103
    int s2 = tn2;
104
    int s1 = sno;
105
    scurrent_bptr[s1][s2]=stransfer_buffer[s1][s2];
106
    ssflag(s1,s2) = 1;
107
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
108
    pthread_cond_signal(smcondition[s1]+s2);
109
    pthread_mutex_unlock(ssmutex[s1]+s2);
110
  }
111
  else
112
  {
113
    cerr << "Error -- process can not write to itself" << endl;
114
    ad_exit(1);
115
  }
116
}
93 117
void adjoint_adwrite_lock_buffer_1(void)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff