1 | package de.ugoe.cs.cpdp;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.util.concurrent.ExecutorService;
|
---|
5 | import java.util.concurrent.Executors;
|
---|
6 | import java.util.concurrent.TimeUnit;
|
---|
7 | import java.util.logging.Level;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.util.console.Console;
|
---|
10 | import de.ugoe.cs.util.console.TextConsole;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Executable that can be used to run experiments.
|
---|
14 | * @author Steffen Herbold
|
---|
15 | *
|
---|
16 | */
|
---|
17 | public class Runner {
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Main class. The arguments are {@link ExperimentConfiguration} files. Each experiment is started in a separate thread. The number of concurrently running threads is the number of logical processors of the host system.
|
---|
21 | * @param args experiment configuration files
|
---|
22 | */
|
---|
23 | public static void main(String[] args) {
|
---|
24 | new TextConsole(Level.FINE);
|
---|
25 |
|
---|
26 | final int concurrentThreads = Runtime.getRuntime().availableProcessors();
|
---|
27 | final ExecutorService threadPool = Executors.newFixedThreadPool(concurrentThreads);
|
---|
28 | for( String arg : args ) {
|
---|
29 | File file = new File(arg);
|
---|
30 | if( file.isFile() ) {
|
---|
31 | createConfig(threadPool, file.getAbsolutePath());
|
---|
32 | }
|
---|
33 | else if( file.isDirectory() ) {
|
---|
34 | for( File subfile : file.listFiles() ) {
|
---|
35 | if( subfile.isFile() ) {
|
---|
36 | createConfig(threadPool, subfile.getAbsolutePath());
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
41 | threadPool.shutdown();
|
---|
42 | try {
|
---|
43 | threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
|
---|
44 | } catch (InterruptedException e) {
|
---|
45 | e.printStackTrace();
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | public static void createConfig(ExecutorService threadPool, String configFile) {
|
---|
50 | ExperimentConfiguration config = null;
|
---|
51 | try {
|
---|
52 | config = new ExperimentConfiguration(configFile);
|
---|
53 | } catch (Exception e) {
|
---|
54 | Console.printerrln("Failure initializing the experiment configuration for configuration file " + configFile);
|
---|
55 | e.printStackTrace();
|
---|
56 | }
|
---|
57 | if( config!=null ) {
|
---|
58 | Console.trace(Level.FINE, config.toString());
|
---|
59 | Experiment experiment = new Experiment(config);
|
---|
60 | threadPool.execute(experiment);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|