Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
java examples: make it easier to run them from the cmdline or from eclipse
[simgrid.git] / examples / java / cloud / masterworker / Main.java
1 /* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 package cloud.masterworker;
7
8 import java.io.File;
9
10 import org.simgrid.msg.Msg;
11 import org.simgrid.msg.Host;
12 import org.simgrid.msg.MsgException;
13
14 class Main {
15   public static final double TASK_COMP_SIZE = 10;
16   public static final double TASK_COMM_SIZE = 10;
17   public static final int NHOSTS = 6;
18   public static final int NSTEPS = 50;
19
20   private Main() {
21     throw new IllegalAccessError("Utility class");
22   }
23
24   public static void main(String[] args) throws MsgException {
25     Msg.init(args); 
26
27     String platfFile = "../../examples/platforms/small_platform.xml";
28     if (args.length >= 1)
29         platfFile = args[0];
30     
31     File f = new File(platfFile); 
32     if (!f.exists()) {
33         System.err.println("File "+platfFile+" does not exist in "+System.getProperty("user.dir"));
34         System.err.println("Usage  : Main ../platforms/platform.xml");
35     }
36     
37     Msg.createEnvironment(platfFile);
38     Host[] hosts = Host.all();
39     if (hosts.length < NHOSTS+1) {
40       Msg.info("I need at least "+ (NHOSTS+1) +"  hosts in the platform file, but " + args[0] + " contains only "
41                + hosts.length + " hosts");
42       System.exit(42);
43     }
44     new Master(hosts[0],"Master",hosts).start();
45     
46     /* Execute the simulation */
47     Msg.run();
48   }
49 }