From 3445fe8efbd0007e0c06a099f5d6066e66992868 Mon Sep 17 00:00:00 2001 From: Ulysse Beaugnon Date: Wed, 11 Jul 2012 14:18:03 +0900 Subject: [PATCH] The simulator now use the library of the C++ 11 It allow the simulator to run multiple simulation at once (but not yet multiple runs) and to let the system decide how it should scale on each computer --- simulation/main.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/simulation/main.cpp b/simulation/main.cpp index 48e8758..9724581 100644 --- a/simulation/main.cpp +++ b/simulation/main.cpp @@ -1,9 +1,9 @@ -// To compile with -std=c++0x +// To compile : g++ -std=c++0x results.cpp graph.cpp main.cpp -lpthread #include "main.h" #include +#include +#include -int n = 1000; // the number of peer -int k = 10; // each peer try to make k connections with the others const char* outName = "out.csv"; @@ -13,9 +13,6 @@ Results Simulate(mt19937 rng, int n, int k, int maxPeer, int maxDistanceFrom, i for(int r=0; r> outputStrings; for(int n=200; n<=20000; n*=2) for(int k=5; k<=50; k+=5) { - Results results = Simulate(rng, n, k, 3*k, 10000, 50); - output << n << "," << k << "," << 3*k << "," << results.avgDistance << "," - << results.disconnected << "," << results.maxDistance << "," - << results.arityDistrib[3*k] << endl; + outputStrings.push_back(async(launch::async, [rng, n, k]() + { + Results results = Simulate(rng, n, k, 3*k, 10000, 50); + ostringstream out; + out << n << "," << k << "," << 3*k << "," << results.avgDistance << "," + << results.disconnected << "," << results.maxDistance << "," + << results.arityDistrib[3*k]; + + return out.str(); + })); } + cout << "Launching finished" << endl; + + int nTask = outputStrings.size(); + for(int i=0; i