MATSIM
RunParallelisationExample.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2014 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 
20 /* *********************************************************************** *
21  * project: org.matsim.*
22  * *
23  * *********************************************************************** *
24  * *
25  * copyright : (C) 2014 by the members listed in the COPYING, *
26  * LICENSE and WARRANTY file. *
27  * email : info at matsim dot org *
28  * *
29  * *********************************************************************** *
30  * *
31  * This program is free software; you can redistribute it and/or modify *
32  * it under the terms of the GNU General Public License as published by *
33  * the Free Software Foundation; either version 2 of the License, or *
34  * (at your option) any later version. *
35  * See also COPYING, LICENSE and WARRANTY file *
36  * *
37  * *********************************************************************** */
38 
39 package tutorial.programming.example17Parallelisation;
40 
41 import java.io.File;
42 
43 import org.apache.log4j.Logger;
44 import org.matsim.api.core.v01.Scenario;
45 import org.matsim.core.config.Config;
48 import org.matsim.core.gbl.Gbl;
50 import org.matsim.core.utils.io.IOUtils;
51 
60  final private static Logger LOG = Logger.getLogger(Math.class);
61 
73  public static void main(String[] args) {
74  /* Running in single thread. */
76  Config config = ConfigUtils.createConfig();
77  String configFilename = "examples/siouxfalls-2014/config_default.xml";
78  ConfigUtils.loadConfig(config, configFilename);
79  config.controler().setLastIteration(10);
80  /*====================================================================*/
81  /* Setting parallelisation: */
82  config.qsim().setNumberOfThreads(1); /* Mobility simulation */
83  config.global().setNumberOfThreads(1); /* Replanning */
84  config.parallelEventHandling().setNumberOfThreads(1); /* Events handling. */
85  /*====================================================================*/
86  Scenario sc = ScenarioUtils.loadScenario(config);
87  Controler controler = new Controler(sc);
88  controler.run();
89  LOG.info("Single thread time:");
91 
92  /* Running multi-threaded. First delete the output directory. */
93  IOUtils.deleteDirectory(new File(config.controler().getOutputDirectory()));
95  config = ConfigUtils.createConfig();
96  ConfigUtils.loadConfig(config, configFilename);
97  config.controler().setLastIteration(10);
98  /*====================================================================*/
99  /* Setting parallelisation: */
100  config.qsim().setNumberOfThreads(2); /* Mobility simulation */
101  config.global().setNumberOfThreads(2); /* Replanning */
102  config.parallelEventHandling().setNumberOfThreads(2); /* Events handling. */
103  /*====================================================================*/
104  sc = ScenarioUtils.loadScenario(config);
105  controler = new Controler(sc);
106  controler.run();
107  LOG.info("Multi-threaded time:");
109  }
110 
111 }
static final void startMeasurement()
Definition: Gbl.java:134
ControlerConfigGroup controler
Definition: Config.java:87
static Config createConfig(final String filename)
QSimConfigGroup qsim()
Definition: Config.java:484
static void deleteDirectory(final File dir)
Definition: IOUtils.java:426
static final void printElapsedTime()
Definition: Gbl.java:138
ParallelEventHandlingConfigGroup parallelEventHandling
Definition: Config.java:93
static Config loadConfig(final String filename, ConfigGroup...customModules)
static Scenario loadScenario(final Config config)
GlobalConfigGroup global
Definition: Config.java:90