Skip to content

Commit

Permalink
Refactor parameter structs
Browse files Browse the repository at this point in the history
- struct now only hold native types
  • Loading branch information
heat1q committed Nov 5, 2020
1 parent 59657b3 commit aa46ed6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
21 changes: 10 additions & 11 deletions src/core/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,26 @@ namespace ldpc

std::ostream &operator<<(std::ostream &os, const decoder_param &p)
{
os << "Type: " << p.type << "\n";
os << "Iterations: " << p.iterations << "\n";
os << "Early Termination: " << p.earlyTerm;
os << " Type: " << p.type << "\n";
os << " Iterations: " << p.iterations << "\n";
os << " Early Termination: " << p.earlyTerm;
return os;
}

std::ostream &operator<<(std::ostream &os, const channel_param &p)
{
os << "Type: " << p.type << "\n";
os << "Seed: " << p.seed << "\n";
os << "Range: " << p.xRange << "\n";
os << "Values: " << p.xVals;
os << " Type: " << p.type << "\n";
os << " Seed: " << p.seed << "\n";
os << " Range: Min: " << p.xRange[0] << ", Max: " << p.xRange[1] << ", Step: " << p.xRange[2];
return os;
}

std::ostream &operator<<(std::ostream &os, const simulation_param &p)
{
os << "Threads: " << p.threads << "\n";
os << "FEC: " << p.fec << "\n";
os << "Max Frames: " << p.maxFrames << "\n";
os << "Output File: " << p.resultFile;
os << " Threads: " << p.threads << "\n";
os << " FEC: " << p.fec << "\n";
os << " Max Frames: " << p.maxFrames << "\n";
os << " Output File: " << p.resultFile;
return os;
}
} // namespace ldpc
9 changes: 4 additions & 5 deletions src/core/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,22 @@ namespace ldpc
{
bool earlyTerm;
u32 iterations;
std::string type;
const char *type;
} typedef decoder_param;

struct
{
u64 seed;
vec_double_t xRange;
vec_double_t xVals;
std::string type;
double xRange[3];
const char *type;
} typedef channel_param;

struct
{
u32 threads;
u64 maxFrames;
u64 fec;
std::string resultFile;
const char *resultFile;
} typedef simulation_param;

std::ostream &operator<<(std::ostream &os, const decoder_param &p);
Expand Down
10 changes: 8 additions & 2 deletions src/sim/ldpcsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ namespace ldpc
catch (std::exception &e)
{
std::cout << "Error: ldpc_sim::ldpc_sim() " << e.what() << "\n";
exit(EXIT_FAILURE);
}
}

Expand All @@ -99,7 +98,14 @@ namespace ldpc
u64 iters;
u64 bec_tmp;

auto xVals = mChannelParams.xVals;
ldpc::vec_double_t xVals;
double val = mChannelParams.xRange[0];
while (val < mChannelParams.xRange[1])
{
xVals.push_back(val);
val += mChannelParams.xRange[2];
}

auto minFec = mSimulationParams.fec;
auto maxFrames = mSimulationParams.maxFrames;
std::string xValType = "SNR";
Expand Down
21 changes: 10 additions & 11 deletions src/sim_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,32 @@ int main(int argc, char *argv[])
std::cout << *code << std::endl;
std::cout << "========================================================================================" << std::endl;

std::string decType, chType, resFile;
decType = parser.get<std::string>("--decoding");
chType = parser.get<std::string>("--channel");
resFile = parser.get<std::string>("output-file");

// decoder parameters
ldpc::decoder_param decoderParams;
decoderParams.iterations = parser.get<ldpc::u32>("--num-iterations");
decoderParams.type = parser.get<std::string>("--decoding");
decoderParams.earlyTerm = !parser.get<bool>("--no-early-term");
decoderParams.type = decType.c_str();

// channel parameters
ldpc::channel_param channelParams;
channelParams.type = parser.get<std::string>("--channel");
channelParams.seed = parser.get<ldpc::u64>("--seed");
channelParams.xRange = snr;

ldpc::vec_double_t x;
double val = snr[0];
while (val < snr[1])
channelParams.type = chType.c_str();
for (int i = 0; i < 3; ++i)
{
x.push_back(val);
val += snr[2];
channelParams.xRange[i] = snr[i];
}
channelParams.xVals = x;

// simulation parameters
ldpc::simulation_param simulationParams;
simulationParams.resultFile = parser.get<std::string>("output-file");
simulationParams.threads = parser.get<ldpc::u32>("--num-threads");
simulationParams.fec = parser.get<ldpc::u64>("--frame-error-count");
simulationParams.maxFrames = parser.get<ldpc::u64>("--max-frames");
simulationParams.resultFile = resFile.c_str();

ldpc::ldpc_sim sim(
code,
Expand Down

0 comments on commit aa46ed6

Please sign in to comment.