Skip to content

Commit

Permalink
Being parallel.
Browse files Browse the repository at this point in the history
  • Loading branch information
suehtamacv committed Jan 9, 2016
1 parent 7c22066 commit 4c6a068
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 36 deletions.
3 changes: 2 additions & 1 deletion adamant-broccoli.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle qt

QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -std=c++11 -fopenmp
QMAKE_LFLAGS += -std=c++11 -fopenmp
QMAKE_CXXFLAGS_RELEASE -= -O
QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE -= -O2
Expand Down
19 changes: 11 additions & 8 deletions include/GeneralPurposeAlgorithms/PSO/ParticleSwarmOptimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,22 @@ template<class PositionType, class Fit, class Comp>
void ParticleSwarmOptimization<PositionType, Fit, Comp>::run_generation() {
p = 1;

for (auto &particle : Particles) {
particle->currentFit = Fit()(particle);
#pragma omp parallel for ordered schedule(dynamic)

for (unsigned i = 0; i < Particles.size(); i++) {
Particles[i]->currentFit = Fit()(Particles[i]);

if (Comp()(particle->currentFit, particle->bestFit) || g == 1) {
particle->bestFit = particle->currentFit;
particle->P = particle->X;
if (Comp()(Particles[i]->currentFit, Particles[i]->bestFit) || g == 1) {
Particles[i]->bestFit = Particles[i]->currentFit;
Particles[i]->P = Particles[i]->X;
}

if (Comp()(particle->bestFit, BestParticle->bestFit)) {
std::clog << "New fitter particle found. Fit: " << particle->currentFit
#pragma omp critical
if (Comp()(Particles[i]->bestFit, BestParticle->bestFit)) {
std::clog << "New fitter particle found. Fit: " << Particles[i]->currentFit
<< std::endl;

BestParticle = particle;
BestParticle = Particles[i];
}

p++;
Expand Down
7 changes: 5 additions & 2 deletions src/GeneralPurposeAlgorithms/NSGA-II/NSGA2_Generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ NSGA2_Generation::NSGA2_Generation() : isEvaluated(false) {
}

void NSGA2_Generation::eval() {
for (auto individual : people) {
individual->eval();
extern bool parallelism_enabled;
#pragma omp parallel for ordered schedule(dynamic) if(parallelism_enabled)

for (unsigned i = 0; i < people.size(); i++) {
people[i]->eval();
}

evalParetoFront();
Expand Down
19 changes: 13 additions & 6 deletions src/SimulationTypes/Simulation_NetworkLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ void Simulation_NetworkLoad::run() {
load();
}

for (auto &simulation : simulations) {
simulation->run();
extern bool parallelism_enabled;
#pragma omp parallel for ordered schedule(dynamic) if(parallelism_enabled)

for (unsigned i = 0; i < simulations.size(); i++) {
simulations[i]->run();
}
}

Expand All @@ -43,12 +46,16 @@ void Simulation_NetworkLoad::print() {
std::cout << std::endl << "* * RESULTS * *" << std::endl;
std::cout << "LOAD\tCALL BLOCKING PROBABILITY" << std::endl;

for (auto &simulation : simulations) {
if (!simulation->hasSimulated) {
simulation->run();
extern bool parallelism_enabled;
#pragma omp parallel for ordered schedule(dynamic) if(parallelism_enabled)

for (unsigned i = 0; i < simulations.size(); i++) {
if (!simulations[i]->hasSimulated) {
simulations[i]->run();
}

simulation->print();
#pragma omp ordered
simulations[i]->print();
}

}
Expand Down
13 changes: 8 additions & 5 deletions src/SimulationTypes/Simulation_PSROptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,18 @@ void Simulation_PSROptimization::print() {
std::shared_ptr<PSO::ParticleSwarmOptimization<double, Fitness, Compare>>
(new PSO::ParticleSwarmOptimization<double, Fitness, Compare>
(P, G, N, XMin, XMax, VMin, VMax));
}

std::cout << std::endl << "* * RESULTS * *" << std::endl;
std::cout << std::endl << "* * RESULTS * *" << std::endl;

for (unsigned i = 1; i <= G; i++) {
for (unsigned i = 1; i <= G; i++) {
if (!hasRun) {
PSO_Optim->run_generation();
std::cout << "GENERATION\tCALL BLOCKING PROBABILITY" << std::endl;
std::cout << i << "\t\t" << PSO_Optim->BestParticle->bestFit << std::endl;
printCoefficients(FileName);
}

std::cout << "GENERATION\tCALL BLOCKING PROBABILITY" << std::endl;
std::cout << i << "\t\t" << PSO_Optim->BestParticle->bestFit << std::endl;
printCoefficients(FileName);
}
}

Expand Down
23 changes: 15 additions & 8 deletions src/SimulationTypes/Simulation_RegeneratorNumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ void Simulation_RegeneratorNumber::run() {
load();
}

for (auto &sim : simulations) {
if (!sim->hasSimulated) {
sim->run();
extern bool parallelism_enabled;
#pragma omp parallel for ordered schedule(dynamic) if(parallelism_enabled)

for (unsigned i = 0; i < simulations.size(); i++) {
if (!simulations[i]->hasSimulated) {
simulations[i]->run();
}
}
}
Expand Down Expand Up @@ -183,13 +186,17 @@ void Simulation_RegeneratorNumber::print() {
std::cout << std::endl << "* * RESULTS * *" << std::endl;
std::cout << "NUM REGENERATORS\tCALL BLOCKING PROBABILITY" << std::endl;

for (auto &sim : simulations) {
if (!sim->hasSimulated) {
sim->run();
extern bool parallelism_enabled;
#pragma omp parallel for ordered schedule(dynamic) if(parallelism_enabled)

for (unsigned i = 0; i < simulations.size(); i++) {
if (!simulations[i]->hasSimulated) {
simulations[i]->run();
}

std::cout << sim->Generator->T->get_NumRegenerators() << "\t\t\t"
<< sim->get_CallBlockingProbability() << std::endl;
#pragma omp ordered
std::cout << simulations[i]->Generator->T->get_NumRegenerators() << "\t\t\t"
<< simulations[i]->get_CallBlockingProbability() << std::endl;

}
}
Expand Down
22 changes: 16 additions & 6 deletions src/SimulationTypes/Simulation_StatisticalTrend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,19 @@ void Simulation_StatisticalTrend::print() {
std::cout << std::endl << "* * RESULTS * *" << std::endl;
std::cout << "SIMULATION\tCALL BLOCKING PROBABILITY" << std::endl;

for (auto &simulation : simulations) {
if (!simulation->hasSimulated) {
simulation->run();
extern bool parallelism_enabled;
#pragma omp parallel for ordered schedule(dynamic) if(parallelism_enabled)

for (unsigned i = 0; i < simulations.size(); i++) {
simulations[i]->run();

if (!simulations[i]->hasSimulated) {
simulations[i]->run();
}

std::cout << Sim++ << "\t\t" << simulation->get_CallBlockingProbability() << std::endl;
#pragma omp ordered
std::cout << Sim++ << "\t\t" << simulations[i]->get_CallBlockingProbability()
<< std::endl;
}
}

Expand All @@ -211,7 +218,10 @@ void Simulation_StatisticalTrend::run() {
load();
}

for (auto &simulation : simulations) {
simulation->run();
extern bool parallelism_enabled;
#pragma omp parallel for ordered schedule(dynamic) if(parallelism_enabled)

for (unsigned i = 0; i < simulations.size(); i++) {
simulations[i]->run();
}
}
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "RWA.h"
#include "SimulationTypes.h"

bool parallelism_enabled = true;

int main(void) {
std::cout << "\t* * * SIMULATOR OF SLICE OPTICAL NETWORKS * * *"
<< std::endl;
Expand Down

0 comments on commit 4c6a068

Please sign in to comment.