-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
put timer into qnetsimengine and print the results to csv #1990
Closed
Closed
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
10285ce
put timer into qnetsimengine and print the results to csv
Janekdererste 656c7f1
Replace generic boxed lists with fastutil DoubleList and LongList.
Janekdererste 20dbe83
Add a runnable class to test things on the cluster
Janekdererste 135b427
Ignore expensive unit test
Janekdererste f1a7815
Measure absolute timing instead of per node
Janekdererste 838f295
Merge remote-tracking branch 'origin/measure_qsim_time' into measure_…
Janekdererste 8aec2a6
Print timings for super simple benchmark
Janekdererste File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,16 +20,24 @@ | |
|
||
package org.matsim.core.mobsim.qsim.qnetsimengine; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import javax.inject.Inject; | ||
|
||
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; | ||
import it.unimi.dsi.fastutil.doubles.DoubleList; | ||
import org.apache.commons.csv.CSVFormat; | ||
import org.matsim.core.mobsim.qsim.QSim; | ||
|
||
/** | ||
|
@@ -46,6 +54,12 @@ | |
final class QNetsimEngineWithThreadpool extends AbstractQNetsimEngine<QNetsimEngineRunnerForThreadpool> { | ||
|
||
private final int numOfRunners; | ||
private final Timing overallTiming = new Timing( "NetsimeEngine_overall"); | ||
private final Timing nodesTiming = new Timing("NetsimeEngine_nodes"); | ||
private final Timing linksTiming = new Timing("NetsimeEngine_links"); | ||
private final DoubleList times = new DoubleArrayList(); | ||
private final String timingOutuputPath; | ||
private final String runId; | ||
private ExecutorService pool; | ||
|
||
public QNetsimEngineWithThreadpool(final QSim sim) { | ||
|
@@ -55,9 +69,51 @@ public QNetsimEngineWithThreadpool(final QSim sim) { | |
@Inject | ||
public QNetsimEngineWithThreadpool(final QSim sim, QNetworkFactory netsimNetworkFactory) { | ||
super(sim, netsimNetworkFactory); | ||
timingOutuputPath = sim.getScenario().getConfig().controler().getOutputDirectory(); | ||
runId = sim.getScenario().getConfig().controler().getRunId(); | ||
this.numOfRunners = this.numOfThreads; | ||
} | ||
|
||
@Override | ||
public void afterSim() { | ||
|
||
var timings = this.getQnetsimEngineRunner().stream() | ||
.flatMap(runner -> Stream.of(runner.getLinksTiming(), runner.getNodesTiming())) | ||
.collect(Collectors.toList()); | ||
|
||
var ownTimings = List.of(overallTiming, nodesTiming, linksTiming); | ||
timings.addAll(ownTimings); | ||
var outputPath = Paths.get(timingOutuputPath).resolve(runId + "_timings.csv"); | ||
|
||
try (var writer = Files.newBufferedWriter(outputPath); var printer = CSVFormat.Builder.create().build().print(writer)) { | ||
|
||
// print the header | ||
printer.print("time"); | ||
for(var timing : timings) { | ||
printer.print(timing.getName()); | ||
} | ||
printer.println(); | ||
|
||
// now all the values | ||
// assuming that all the timings have the same number of values | ||
var firstTimingSize = timings.get(0).getDurations().size(); | ||
for(int i = 0; i < firstTimingSize; i++) { | ||
// first the time step | ||
printer.print(times.getDouble(i)); | ||
for (var timing : timings) { | ||
var duration = timing.getDurations().getLong(i); | ||
printer.print(duration); | ||
} | ||
printer.println(); | ||
} | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
super.afterSim(); | ||
} | ||
|
||
@Override | ||
public void finishMultiThreading() { | ||
this.pool.shutdown(); | ||
|
@@ -89,23 +145,45 @@ protected void run(double time) { | |
// as input for the domain decomposition under (b). | ||
|
||
// set current Time | ||
times.add(time); | ||
for (AbstractQNetsimEngineRunner engine : this.getQnetsimEngineRunner()) { | ||
engine.setTime(time); | ||
} | ||
|
||
try { | ||
var overallStartTime = System.nanoTime(); | ||
for (AbstractQNetsimEngineRunner engine : this.getQnetsimEngineRunner()) { | ||
((QNetsimEngineRunnerForThreadpool) engine).setMovingNodes(true); | ||
} | ||
|
||
var nodesStartTime = System.nanoTime(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hier beginnt das Node measurement für das oberste Diagram. |
||
for (Future<Boolean> future : pool.invokeAll(this.getQnetsimEngineRunner())) { | ||
future.get(); | ||
|
||
} | ||
var nodesDuration = System.nanoTime() - nodesStartTime; | ||
int nodeCount = this.getQnetsimEngineRunner().stream() | ||
.mapToInt(AbstractQNetsimEngineRunner::getNodeCounter) | ||
.sum(); | ||
nodesTiming.addDuration(nodesDuration / Math.max(1, nodeCount)); | ||
|
||
for (AbstractQNetsimEngineRunner engine : this.getQnetsimEngineRunner()) { | ||
((QNetsimEngineRunnerForThreadpool) engine).setMovingNodes(false); | ||
} | ||
|
||
var linksStartTime = System.nanoTime(); | ||
for (Future<Boolean> future : pool.invokeAll(this.getQnetsimEngineRunner())) { | ||
future.get(); | ||
} | ||
var afterLinksTime = System.nanoTime(); | ||
var linksDuration = afterLinksTime - linksStartTime; | ||
var linkCount = this.getQnetsimEngineRunner().stream() | ||
.mapToInt(AbstractQNetsimEngineRunner::getLinkCounter) | ||
.sum(); | ||
linksTiming.addDuration(linksDuration / Math.max(1, linkCount)); | ||
|
||
var overallDuration = afterLinksTime - overallStartTime; | ||
overallTiming.addDuration(overallDuration); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e) ; | ||
} catch (ExecutionException e) { | ||
|
@@ -126,7 +204,7 @@ public Thread newThread(Runnable r) { | |
protected List<QNetsimEngineRunnerForThreadpool> initQSimEngineRunners() { | ||
List<QNetsimEngineRunnerForThreadpool> engines = new ArrayList<>(); | ||
for (int i = 0; i < numOfRunners; i++) { | ||
QNetsimEngineRunnerForThreadpool engine = new QNetsimEngineRunnerForThreadpool(); | ||
QNetsimEngineRunnerForThreadpool engine = new QNetsimEngineRunnerForThreadpool("Runner_" + i); | ||
engines.add(engine); | ||
} | ||
return engines; | ||
|
30 changes: 30 additions & 0 deletions
30
matsim/src/main/java/org/matsim/core/mobsim/qsim/qnetsimengine/Timing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.matsim.core.mobsim.qsim.qnetsimengine; | ||
|
||
import it.unimi.dsi.fastutil.doubles.DoubleList; | ||
import it.unimi.dsi.fastutil.longs.LongArrayList; | ||
import it.unimi.dsi.fastutil.longs.LongList; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Timing { | ||
|
||
private final String name; | ||
private final LongList durations = new LongArrayList(); | ||
|
||
public Timing(String name) { | ||
this.name = name; | ||
} | ||
|
||
void addDuration(long duration) { | ||
durations.add(duration); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public LongList getDurations() { | ||
return this.durations; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hier beginnt das Time measurement der Worker