Skip to content

Commit

Permalink
Initial state before using Github.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwoalk committed Dec 3, 2018
0 parents commit 61c6253
Show file tree
Hide file tree
Showing 54 changed files with 3,083 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Sample1/Sample1/Sample1.vcxproj.user
22 changes: 22 additions & 0 deletions Sample1/Sample1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Sample1", "Sample1\Sample1.vcxproj", "{2741273E-EC1D-4B3A-A693-3482ED543699}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2741273E-EC1D-4B3A-A693-3482ED543699}.Debug|x64.ActiveCfg = Debug|x64
{2741273E-EC1D-4B3A-A693-3482ED543699}.Debug|x64.Build.0 = Debug|x64
{2741273E-EC1D-4B3A-A693-3482ED543699}.Release|x64.ActiveCfg = Release|x64
{2741273E-EC1D-4B3A-A693-3482ED543699}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
73 changes: 73 additions & 0 deletions Sample1/Sample1/Anode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "stdafx.h"

//void Anode::main()
//{
//while (true)
//{
// CheckIncoming();
//}
//}

void Anode::CheckIncoming()
{
k_block k;
if (k_rec.nb_read(k))
{
cout << "Receive," << sc_time_stamp() << "," << name() << "," << k << endl;
//cout << sc_time_stamp() << ": A " << name() << " received " << k << "." << endl;
++kblk_rec;
// TODO: it kind of sends everything instantly and then waits
int leader = rand() % 2;
send_shadow_rq srq = create_send_shadow_rq(leader, k.info1, k.info2, number, NodeType::A);
int delay = randomTime(this, k);
delay += SendToConnectedNode(srq);
next_trigger(delay, SC_NS);
return; // !!!
}
else
{
recv_shadow_rq rr;
if (recv_rec.nb_read(rr))
{
cout << "Receive," << sc_time_stamp() << "," << name() << "," << rr << endl;
//cout << sc_time_stamp() << ": A " << name() << " received " << rr << "." << endl;
++rblk_rec;
m_block m = create_m_block(rr.info1, rr.info2, NodeType::A);
int delay = randomTime(this, rr);
delay += SendToConnectedNode(m);
next_trigger(delay, SC_NS);
return; // !!!
}
}
next_trigger();
}

int Anode::SendToConnectedNode(send_shadow_rq& srq)
{
int delay = 0;
if (NULL != Sconn)
{
Sconn->send_rec.nb_write(srq);
++sblk_snt;
delay += randomTime(this, srq);
}
return delay;
}

int Anode::SendToConnectedNode(m_block& m)
{
int delay = 0;
if (NULL != Wconn)
{
Wconn->m_rec.nb_write(m);
++mblk_snt;
delay += randomTime(this, m);
}
if (NULL != Sconn)
{
Sconn->m_rec.nb_write(m);
++mblk_snt;
delay += randomTime(this, m);
}
return delay;
}
44 changes: 44 additions & 0 deletions Sample1/Sample1/Anode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

SC_MODULE(Anode) {
int number;
// currently N/A
std::unordered_map<int, int> a_memory;

WSAP cc;
WnodeP Wconn;
SnodeP Sconn;

int kblk_rec;
int rblk_rec;
int sblk_snt;
int mblk_snt;

// S forwards k_blocks to A
log_fifo<k_block> k_rec;
// S replies to A on send_shadow_rq with recv_shadow_rq
log_fifo<recv_shadow_rq> recv_rec;

SC_HAS_PROCESS(Anode);
Anode(sc_module_name name, int num_, WSAP cc_, WnodeP Wconn_, SnodeP Sconn_) : sc_module(name),
k_rec("A_k_rec_fifo", 10), recv_rec("A_recv_rec_fifo", 10),
kblk_rec(0), rblk_rec(0), sblk_snt(0), mblk_snt(0),
cc(cc_), Wconn(Wconn_), Sconn(Sconn_), number(num_)
{
SC_METHOD(CheckIncoming);
sensitive << k_rec.data_written_event() << recv_rec.data_written_event();
}

~Anode()
{
cout << "Destructor,Anode," << name() << "," << kblk_rec << "," << rblk_rec << "," << sblk_snt << "," << mblk_snt << endl;
//cout << "Destructing " << name() << ": krec=" << kblk_rec << " rrec=" << rblk_rec << " ssnt=" << sblk_snt << " msnt=" << mblk_snt << "." << endl;
//cout << "Destructed " << name() << "." << endl;
}

//void main();
void CheckIncoming();
int SendToConnectedNode(send_shadow_rq& srq);
int SendToConnectedNode(m_block& k);
};
typedef Anode* AnodeP;
86 changes: 86 additions & 0 deletions Sample1/Sample1/Base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "stdafx.h"

double baseMu = 10000;
double baseSigma = 10000;
int baseWnum = 2;
int baseSnum = 2;
int baseAnum = 10;
int t_proc = 100;
int t_send = 100;
int t_broadcast = 100;

// positive only
// probably it was supposed to be exponential distribution? easy to change anyway...
int randomTime()
{
return randomTime(baseMu, baseSigma);
}

int randomTime(double mu, double sigma)
{
static std::default_random_engine generator;
std::normal_distribution<double> distribution(mu, sigma);
int number = (int)abs(distribution(generator));
//std::cout << "randomTime() = " << number << " (mu,sigma) = (" << baseMu << "," << baseSigma << ") " << endl;
return number;
}

int randomTime(WnodeP w)
{
return randomTime(baseMu, baseSigma);
}

int randomTime(WnodeP w, m_block& m)
{
return t_proc;
}

int randomTime(WnodeP w, k_block& k)
{
return t_proc;
}

int randomTime(WSAP p, k_block& k)
{
return t_broadcast;
}

int randomTime(SnodeP s, k_block& k)
{
return t_proc;
}

int randomTime(SnodeP s, send_shadow_rq& k)
{
return t_proc;
}

int randomTime(SnodeP s, m_block& m)
{
return t_proc;
}

int randomTime(SnodeP s, recv_shadow_rq& rr)
{
return t_proc;
}

int randomTime(AnodeP a, k_block& k)
{
return t_proc;
}

int randomTime(AnodeP a, m_block& k)
{
return t_proc;
}

int randomTime(AnodeP a, recv_shadow_rq& k)
{
return t_proc;
}

int randomTime(AnodeP a, send_shadow_rq& k)
{
return t_proc;
}
Loading

0 comments on commit 61c6253

Please sign in to comment.