Debian Codegraph @

src/dr/app/beast/BeastRemote.java

raw symbols SCIP
1 /*
2 * BeastRemote.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.beast;
27
28 import dr.app.util.Arguments;
29 import dr.inference.parallel.MPIServices;
30 import dr.math.MathUtils;
31 import mpi.MPI;
32
33 import java.io.File;
34
35 /**
36 * @author Marc Suchard
37 */
38 public class BeastRemote extends BeastMain {
39
40 public BeastRemote(File inputFile, BeastConsoleApp consoleApp, boolean verbose, boolean parserWarning) {
41 super(inputFile, consoleApp, 0, verbose, parserWarning, true, null, false, null, 0);
42 }
43
44 public static void terminateSlaves() {
45 int size = MPI.COMM_WORLD.Size();
46 for (int i = 1; i < size; i++) {
47 System.err.println("Sending kill to process " + i);
48 MPIServices.requestTermination(i);
49 }
50
51 }
52
53 public static void main(String[] oldArgs) throws java.io.IOException {
54
55 // First populate args from MPI.WORLD
56
57 // String[] args = null;
58 MPI.Init(oldArgs);
59 System.err.println(oldArgs[0]);
60 System.err.println(oldArgs[1]);
61 System.err.println(oldArgs[2]);
62
63 int rank = MPI.COMM_WORLD.Rank();
64 int argLength = oldArgs.length - 3;
65 String[] args = new String[argLength];
66 for (int i = 0; i < argLength; i++) {
67
68 args[i] = oldArgs[i + 3];
69 System.err.println(i + " : " + args[i]);
70 if (args[i].contains(".xml")) { // append rank
71 args[i] = args[i].replace(".xml", Integer.toString(rank) + ".xml");
72 System.err.println("Attempting to load: " + args[i]);
73 }
74 }
75
76 /* for (String str : args)
77 System.err.println(str);*/
78 //System.exit(1);
79
80
81 Arguments arguments = new Arguments(
82 new Arguments.Option[]{
83 new Arguments.Option("verbose", "verbose XML parsing messages"),
84 new Arguments.Option("warnings", "Show warning messages about BEAST XML file"),
85 new Arguments.Option("window", "provide a console window"),
86 new Arguments.Option("working", "change working directory to input file's directory"),
87 new Arguments.LongOption("seed", "specify a random number generator seed"),
88 new Arguments.Option("help", "option to print this message")
89 });
90
91 try {
92 arguments.parseArguments(args);
93 } catch (Arguments.ArgumentException ae) {
94 System.out.println();
95 System.out.println(ae.getMessage());
96 System.out.println();
97 printTitle();
98 printUsage(arguments);
99 MPI.Finalize();
100 System.exit(1);
101 }
102
103 if (arguments.hasOption("help")) {
104 printTitle();
105 printUsage(arguments);
106 MPI.Finalize();
107 System.exit(0);
108 }
109
110 boolean verbose = arguments.hasOption("verbose");
111 boolean parserWarning = arguments.hasOption("pwarning"); // if dev, then auto turn on, otherwise default to turn off
112 // boolean window = arguments.hasOption("window");
113 boolean working = arguments.hasOption("working");
114
115 long seed = MathUtils.getSeed();
116 if (arguments.hasOption("seed")) {
117 seed = arguments.getLongOption("seed");
118 MathUtils.setSeed(seed);
119 }
120
121 // if (System.getProperty("dr.app.beast.main.window", "false").toLowerCase().equals("true")) {
122 // window = true;
123 // }
124
125 BeastConsoleApp consoleApp = null;
126
127 /* if (window) {
128 System.setProperty("com.apple.macos.useScreenMenuBar", "true");
129 System.setProperty("apple.laf.useScreenMenuBar", "true");
130 System.setProperty("apple.awt.showGrowBox", "true");
131
132 javax.swing.Icon icon = IconUtils.getIcon(BeastMain.class, "images/beast.png");
133
134 String nameString = "BEAST " + version.getVersionString();
135 String aboutString = "<html><center><p>Bayesian Evolutionary Analysis Sampling Trees<br>" +
136 "Version " + version.getVersionString() + ", 2002-2006</p>" +
137 "<p>by<br>" +
138 "Alexei J. Drummond and Andrew Rambaut</p>" +
139 "<p>Department of Computer Science, University of Auckland<br>" +
140 "<a href=\"mailto:[email protected]\">[email protected]</a></p>" +
141 "<p>Institute of Evolutionary Biology, University of Edinburgh<br>" +
142 "<a href=\"mailto:[email protected]\">[email protected]</a></p>" +
143 "<p><a href=\"http://evolve.zoo.ox.ac.uk/beast/\">http://evolve.zoo.ox.ac.uk/beast/</a></p>" +
144 "<p>Source code distributed under the GNU LGPL:<br>" +
145 "<a href=\"http://github.com/beast-dev/beast-mcmc/\">http://github.com/beast-dev/beast-mcmc/</a></p>" +
146 "<p>Additional programming by:<br>" +
147 "Roald Forsberg, Gerton Lunter, Sidney Markowitz, Oliver Pybus</p>" +
148 "<p>Thanks to Korbinian Strimmer for use of his code</p>" +
149 "</center></html>";
150
151 consoleApp = new BeastConsoleApp(nameString, aboutString, icon);
152 }*/ // Remote can never be interactive
153
154 String inputFileName;
155
156 String[] args2 = arguments.getLeftoverArguments();
157
158 if (args2.length > 1) {
159 System.err.println("Unknown option: " + args2[1]);
160 System.err.println();
161 printTitle();
162 printUsage(arguments);
163 MPI.Finalize();
164 System.exit(1);
165 }
166
167 File inputFile = null;
168
169 if (args2.length > 0) {
170 inputFileName = args2[0];
171 inputFile = new File(inputFileName);
172 }
173
174 /* if (inputFileName == null) {
175 // No input file name was given so throw up a dialog box...
176 inputFile = Utils.getLoadFile("BEAST " + version.getVersionString() + " - Select XML input file");
177 }*/
178
179 if (inputFile != null && working) {
180 System.setProperty("user.dir", inputFile.getParent());
181 }
182
183 printTitle();
184
185 System.out.println();
186 System.out.println("Random number seed: " + seed);
187 System.out.println();
188
189 new BeastRemote(inputFile, consoleApp, verbose, parserWarning);
190 //System.err.println("Did I get here");
191 if (rank == 0)
192 terminateSlaves();
193 MPI.Finalize();
194 }
195
196
197 }