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 d9f0a1a

Browse files
multishot
1 parent 8e4ab25 commit d9f0a1a

File tree

3 files changed

+54
-41
lines changed

3 files changed

+54
-41
lines changed

‎example/output/1.output‎

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

‎example/output/2.output‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
61 451 457 501 569 864

‎template_cpp/src/include/LatticeAggrement.hpp‎

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class LatteAggrement{
2525
vector<Message> Tobroadcast; // first index stands for iter;
2626
vector<vector<Message>> Tosend; // first index stands for to-Pi;
2727
set<long unsigned> proposed_value;
28-
set<long unsigned> accepted_value;
28+
vector<set<long unsigned>> accepted_value_vec;
2929

3030

3131

@@ -39,7 +39,6 @@ class LatteAggrement{
3939
this->myid=myid;
4040
this->socket_fd=socket_fd;
4141
this->host_dicts=host_dicts;
42-
this->active=true;
4342
struct sockaddr_in myaddr=host_dicts[(myid-1)];
4443

4544
this->host_num=host_dicts.size();
@@ -55,6 +54,7 @@ class LatteAggrement{
5554
// Trigger the beb of the first proposed_value;
5655

5756
Tosend=vector<vector<Message>>(128);
57+
accepted_value_vec.push_back(set<long unsigned>());
5858

5959

6060
// Add the forst Proposal
@@ -70,14 +70,9 @@ class LatteAggrement{
7070
while(1){
7171
// BroadCast
7272
// cout<<"Broadcast"<<endl;
73-
unsigned int k=0;
7473
mut_broadcast.lock();
7574
for(long unsigned i=0;i<Tobroadcast.size();i++){
7675
sendrange(Tobroadcast[i]);
77-
// if(Tobroadcast[i].proposal_num==1){
78-
// k=k+1;
79-
// cout<<k<<endl;
80-
// }
8176
}
8277
mut_broadcast.unlock();
8378
// Send
@@ -99,16 +94,13 @@ class LatteAggrement{
9994
//cout<<m.m_type<< " "<<m.value_set[0]<<endl;
10095
for(long unsigned i=0;i<this->host_num;i++){
10196
this->pl_link.send(m,host_dicts[i]);
102-
if(m.proposal_num==1&&i==2){
103-
// cout<<"To 3"<<endl;
104-
}
10597
}
10698

10799
}
108100

109101
void upon_change_ack_nack(Message & m){
110102
if(nack_count>0 && (ack_count+nack_count>=host_num/2+host_num%2) &&
111-
active){
103+
m.iter==current_iter){ // Modify the active bool
112104
active_proposal_num++;
113105
ack_count=0;
114106
nack_count=0;
@@ -119,12 +111,28 @@ class LatteAggrement{
119111
current_iter,myid,active_proposal_num,proposed_value));// WARN: Modify Here
120112
mut_broadcast.unlock();
121113
}
122-
else if(ack_count>=(host_num/2+host_num%2) && active) {
114+
else if(ack_count>=(host_num/2+host_num%2) && m.iter==current_iter) {
123115
//decide
124116
Todecide.push_back(proposed_value);
125117
cout<<"Decide"<<endl;
126-
active=false;
127-
//this->current_iter++; // Enter the next proposal stage(iter);
118+
// Clean the previous things;
119+
// Enter the next proposal stage(iter);
120+
this->ack_count=0;
121+
this->nack_count=0;
122+
this->active_proposal_num=0;
123+
this->accepted_value_vec.push_back(set<long unsigned>());
124+
this->proposed_value.clear();
125+
126+
// Start next round
127+
mut_broadcast.lock();
128+
this->current_iter++;
129+
for(auto it=vec_proposals[current_iter-1].begin();
130+
it!=vec_proposals[current_iter-1].end();it++){
131+
proposed_value.insert(*it);
132+
}
133+
this->Tobroadcast.push_back(Message(0,
134+
this->current_iter,myid,active_proposal_num,proposed_value));
135+
mut_broadcast.unlock();
128136
}
129137

130138
}
@@ -164,6 +172,7 @@ class LatteAggrement{
164172
void deliver(){
165173
Message m;
166174
while(1){
175+
167176
// Pay Attention: I would force perfect link only
168177
// deliver message belonging to the same 'iter'
169178
// and same 'propose_num'
@@ -172,15 +181,15 @@ class LatteAggrement{
172181
if(m.original_id!=0){
173182
// ACK
174183

175-
if((m.m_type)==1&&m.proposal_num==active_proposal_num){
184+
if((m.m_type)==1&&m.proposal_num==active_proposal_num &&m.iter==current_iter){
176185
ack_count++;
177186
cout<<"Receive ACK Oid:"<<m.original_id<<" Iter:"<<m.iter<<" Type:"<<m.m_type<<" Value:";
178187
cout<<" activeround:"<<m.proposal_num<<"myround:"<<active_proposal_num <<endl;
179188
upon_change_ack_nack(m);
180189
// cout<<"hello man"<<endl;
181190
}
182191
// NACK
183-
if(m.m_type==2&&m.proposal_num==active_proposal_num){
192+
if(m.m_type==2&&m.proposal_num==active_proposal_num&&m.iter==current_iter){
184193
nack_count++;
185194
for(long unsigned k=0;k<m.value_set_num;k++){
186195
proposed_value.insert(m.value_set[k]);
@@ -189,37 +198,41 @@ class LatteAggrement{
189198
for(long unsigned i=0;i<m.value_set_num;i++){
190199
cout<<m.value_set[i]<<" ";
191200
}
192-
cout<<" activeround:"<<m.proposal_num<<"myround:"<<active_proposal_num <<endl;
201+
cout<<" activeround:"<<m.proposal_num<<"myround:"<<active_proposal_num <<endl;
193202
upon_change_ack_nack(m);
194203

195204
}
196205
// PROPOSAL
197-
bool tag=mergeset(accepted_value,m);
198-
if(m.m_type==0 && tag){
199-
// ACK
200-
mut_send.lock();
201-
Tosend[m.original_id-1].push_back(Message(1,
202-
current_iter,myid,m.proposal_num));
203-
mut_send.unlock();
204-
205-
cout<<"Send Ack Oid:"<<myid<<"To "<<m.original_id<<" Type:"<<m.m_type;
206-
cout<<" activeround:"<<m.proposal_num<<"myround:"<<active_proposal_num <<endl;
207206

208-
}
209-
else if(m.m_type==0 && !tag){
210-
// NACK
211-
mut_send.lock();
212-
Tosend[m.original_id-1].push_back(Message(2,
213-
current_iter,myid,m.proposal_num,accepted_value));
214-
mut_send.unlock();
215-
216-
cout<<"Send NACK Oid:"<<myid<<"To "<<m.original_id <<" Type:"<<m.m_type<<" Value:";
217-
for(auto it= accepted_value.begin();it!=accepted_value.end();it++){
218-
cout<<*it<<" ";
219-
}
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;
220218
cout<<" activeround:"<<m.proposal_num<<"myround:"<<active_proposal_num <<endl;
221-
}
222219

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+
}
235+
}
223236

224237
}
225238

0 commit comments

Comments
(0)

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