Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae63a3e

Browse files
single success
1 parent d9f0a1a commit ae63a3e

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

‎example/output/1.output

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
61 178 228 285 476 501 563 864
2+
61 209 285 447 451 476 501 563 919

‎example/output/3.output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
61 178 228 285 476 501 563 864
1+
178

‎template_cpp/src/include/LatticeAggrement.hpp

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
class LatteAggrement{
1313
public:
14-
bool active;
1514
long unsigned current_iter;
1615
long unsigned ack_count;
1716
long unsigned nack_count;
@@ -52,11 +51,8 @@ class LatteAggrement{
5251
}
5352

5453
// Trigger the beb of the first proposed_value;
55-
5654
Tosend=vector<vector<Message>>(128);
57-
accepted_value_vec.push_back(set<long unsigned>());
58-
59-
55+
this->accepted_value_vec.push_back(set<long unsigned>());
6056
// Add the forst Proposal
6157
Tobroadcast.push_back(Message(0,\
6258
current_iter,myid,active_proposal_num,proposed_value));
@@ -70,9 +66,11 @@ class LatteAggrement{
7066
while(1){
7167
// BroadCast
7268
// cout<<"Broadcast"<<endl;
69+
unsigned int k=0;
7370
mut_broadcast.lock();
7471
for(long unsigned i=0;i<Tobroadcast.size();i++){
7572
sendrange(Tobroadcast[i]);
73+
7674
}
7775
mut_broadcast.unlock();
7876
// Send
@@ -94,13 +92,16 @@ class LatteAggrement{
9492
//cout<<m.m_type<< " "<<m.value_set[0]<<endl;
9593
for(long unsigned i=0;i<this->host_num;i++){
9694
this->pl_link.send(m,host_dicts[i]);
95+
if(m.proposal_num==1&&i==2){
96+
// cout<<"To 3"<<endl;
97+
}
9798
}
9899

99100
}
100101

101102
void upon_change_ack_nack(Message & m){
102103
if(nack_count>0 && (ack_count+nack_count>=host_num/2+host_num%2) &&
103-
m.iter==current_iter){ // Modify the active bool
104+
this->current_iter==m.iter){
104105
active_proposal_num++;
105106
ack_count=0;
106107
nack_count=0;
@@ -111,12 +112,15 @@ class LatteAggrement{
111112
current_iter,myid,active_proposal_num,proposed_value));// WARN: Modify Here
112113
mut_broadcast.unlock();
113114
}
114-
else if(ack_count>=(host_num/2+host_num%2) && m.iter==current_iter) {
115+
else if(ack_count>=(host_num/2+host_num%2) && this->current_iter==m.iter) {
115116
//decide
116117
Todecide.push_back(proposed_value);
117118
cout<<"Decide"<<endl;
118-
// Clean the previous things;
119-
// Enter the next proposal stage(iter);
119+
// this->current_iter++; // Enter the next proposal stage(iter);
120+
/****************************************
121+
* From last version code
122+
*
123+
*/
120124
this->ack_count=0;
121125
this->nack_count=0;
122126
this->active_proposal_num=0;
@@ -172,11 +176,10 @@ class LatteAggrement{
172176
void deliver(){
173177
Message m;
174178
while(1){
175-
176179
// Pay Attention: I would force perfect link only
177180
// deliver message belonging to the same 'iter'
178181
// and same 'propose_num'
179-
m=this->pl_link.deliver();
182+
m=this->pl_link.deliver(current_iter);
180183

181184
if(m.original_id!=0){
182185
// ACK
@@ -190,6 +193,7 @@ class LatteAggrement{
190193
}
191194
// NACK
192195
if(m.m_type==2&&m.proposal_num==active_proposal_num&&m.iter==current_iter){
196+
// Add the modification above m.iter==current_iter
193197
nack_count++;
194198
for(long unsigned k=0;k<m.value_set_num;k++){
195199
proposed_value.insert(m.value_set[k]);
@@ -198,41 +202,41 @@ class LatteAggrement{
198202
for(long unsigned i=0;i<m.value_set_num;i++){
199203
cout<<m.value_set[i]<<" ";
200204
}
201-
cout<<" activeround:"<<m.proposal_num<<"myround:"<<active_proposal_num <<endl;
205+
cout<<" activeround:"<<m.proposal_num<<"myround:"<<active_proposal_num <<endl;
202206
upon_change_ack_nack(m);
203207

204208
}
205209
// PROPOSAL
210+
// if(m.iter>=accepted_value_vec.size()){
211+
// accepted_value_vec.push
212+
// }
213+
bool tag=mergeset(accepted_value_vec[m.iter-1],m);
214+
if(m.m_type==0 && tag){
215+
// ACK
216+
mut_send.lock();
217+
Tosend[m.original_id-1].push_back(Message(1,
218+
m.iter,myid,m.proposal_num));
219+
mut_send.unlock();
220+
221+
cout<<"Send Ack Oid:"<<myid<<"To "<<m.original_id<<" Iter:"<<m.iter<<" Type:"<<m.m_type;
222+
cout<<" activeround:"<<m.proposal_num<<"myround:"<<active_proposal_num <<endl;
206223

207-
// Modify
208-
if(m.m_type==0 && m.iter<=current_iter){
209-
bool tag=mergeset(accepted_value_vec[m.iter-1],m);
210-
if(m.m_type==0 && tag){
211-
// ACK
212-
mut_send.lock();
213-
Tosend[m.original_id-1].push_back(Message(1,
214-
m.iter,myid,m.proposal_num)); // Modify the current_iter to m.tier
215-
mut_send.unlock();
216-
217-
cout<<"Send Ack Oid:"<<myid<<" Iter " <<m.iter<<"To "<<m.original_id<<" Type:"<<m.m_type;
224+
}
225+
else if(m.m_type==0 && !tag){
226+
// NACK
227+
mut_send.lock();
228+
//m.iter not current iter
229+
Tosend[m.original_id-1].push_back(Message(2,
230+
m.iter,myid,m.proposal_num,accepted_value_vec[m.iter-1]));
231+
mut_send.unlock();
232+
233+
cout<<"Send NACK Oid:"<<myid<<"To "<<m.original_id <<" Type:"<<m.m_type<<" Value:";
234+
for(auto it= accepted_value_vec[m.iter-1].begin();it!=accepted_value_vec[m.iter-1].end();it++){
235+
cout<<*it<<" ";
236+
}
218237
cout<<" activeround:"<<m.proposal_num<<"myround:"<<active_proposal_num <<endl;
219-
220-
}
221-
else if(m.m_type==0 && !tag){
222-
// NACK
223-
mut_send.lock();
224-
Tosend[m.original_id-1].push_back(Message(2,
225-
m.iter,myid,m.proposal_num,accepted_value_vec[m.iter-1]));
226-
mut_send.unlock();
227-
228-
cout<<"Send NACK Oid:"<<myid<<"To "<<m.original_id <<" Type:"<<m.m_type<<" Value:";
229-
for(auto it= accepted_value_vec[m.iter-1].begin();
230-
it!=accepted_value_vec[m.iter-1].end();it++){
231-
cout<<*it<<" ";
232-
}
233-
cout<<" activeround:"<<m.proposal_num<<" myround:"<<active_proposal_num <<endl;
234-
}
235238
}
239+
236240

237241
}
238242

‎template_cpp/src/include/PerfectLink.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ class PerfectLink
3535
this->st_link.send(pl_m, dest_addr);
3636
}
3737

38-
Message deliver()
38+
Message deliver(longunsigned current_iter)
3939
{
4040
pair<set<Message>::iterator, bool> ret;
4141
Message pl_m = this->st_link.deliver();
4242

4343
ret = delivered[pl_m.original_id-1].insert(pl_m);
44+
if(pl_m.iter>current_iter){
45+
return Message();
46+
}
4447

4548
if (ret.second == true)
4649
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /