00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #include <exception>
00076
00077
00078 #include "chomp/system/config.h"
00079 #include "chomp/system/textfile.h"
00080 #include "chomp/system/timeused.h"
00081 #include "chomp/system/arg.h"
00082 #include "chomp/multiwork/mw.h"
00083
00084
00085 #include "config.h"
00086 #include "typedefs.h"
00087 #include "worker.h"
00088 #include "coord.h"
00089
00090
00091
00092
00093
00094
00095
00096
00097 const char *title = "\
00098 This is a Conley-Morse graphs computation program.\n\
00099 Ver. 0.01, April 19, 2008. Copyright (C) 2005-2008 by Pawel Pilarczyk.\n\
00100 This is free software. No warranty. Consult 'license.txt' for details.";
00101
00102
00103
00104
00105 const char *helpinfo = "\
00106 This is the front-end program for the computation of Conley-Morse graphs\n\
00107 for a selected range of parameters for a given discrete dynamical system,\n\
00108 as configured in the file 'config.h' of the source code. Please, see the\n\
00109 documentation of the program and the source code for more information.\n\
00110 Command line arguments (at least '-w', '-c' or '-f' must be specified):\n\
00111 -w computer:port - run as a worker and connect to the given coordinator,\n\
00112 -c [port] - run as a coordinator and listen to workers at the given port;\n\
00113 \tif port=0 (default) then runs the computations locally only,\n\
00114 -f prefix - file name prefix for saving the final continuation data & png,\n\
00115 -i filename - intermediate results file (new results will be appended),\n\
00116 -g filename - file name to save the text code for Conley-Morse graphs,\n\
00117 -s prefix - file name prefix for saving shared Morse decompositions,\n\
00118 -p prefix - file name prefix for PNG pictures of Morse decompositions,\n\
00119 -n num - the expected number of workers (affects data chunk sizes),\n\
00120 --full - use the full range of the phase space to plot Morse sets,\n\
00121 --log filename - file name to save all the text output of the program to,\n\
00122 --quiet - suppress any output written to the terminal,\n\
00123 --debug - display additional information useful for debugging,\n\
00124 --help - make the program show this brief help information and exit.\n\
00125 For more information ask the author at http://www.pawelpilarczyk.com/.";
00126
00127
00128
00129
00130
00131
00132
00133
00134 int main (int argc, char *argv [])
00135 {
00136 using namespace chomp::homology;
00137
00138
00139 char *workAddress = 0;
00140 char *interFileName = 0;
00141 char *graphsFileName = 0;
00142 char *finalPrefix = 0;
00143 char *sharePrefix = 0;
00144 char *phaseSpacePrefix = 0;
00145 int coordPort = -1;
00146 int skipIndices = 0;
00147 bool fullPhaseSpace = false;
00148 int nWorkers = 1000000;
00149
00150
00151 arguments a;
00152 arg (a, "c", coordPort, 0);
00153 arg (a, "w", workAddress);
00154 arg (a, "i", interFileName);
00155 arg (a, "g", graphsFileName);
00156 arg (a, "f", finalPrefix);
00157 arg (a, "s", sharePrefix);
00158 arg (a, "p", phaseSpacePrefix);
00159 arg (a, "n", nWorkers);
00160 arg (a, "-skip-indices", skipIndices, 1);
00161 argswitch (a, "-full", fullPhaseSpace, true);
00162 arghelp (a);
00163
00164 argstreamprepare (a);
00165 int argresult = a. analyze (argc, argv);
00166 argstreamset ();
00167
00168
00169
00170 if (finalPrefix && (coordPort < 0))
00171 coordPort = 0;
00172
00173
00174 if (!finalPrefix && !workAddress)
00175 argresult = 1;
00176
00177
00178 if (argresult >= 0)
00179 sout << title << '\n';
00180
00181
00182 if (argresult < 0)
00183 {
00184 sout << "Call with '--help' for help.\n";
00185 return 2;
00186 }
00187
00188
00189 if (argresult > 0)
00190 {
00191 sout << helpinfo << '\n';
00192 return 1;
00193 }
00194
00195
00196 try
00197 {
00198
00199 program_time = "Aborted after:";
00200 program_time = 1;
00201
00202
00203 if (workAddress)
00204 {
00205 Worker w (false);
00206 w. Port (0);
00207 w. Add (workAddress);
00208 w. TimeOut (30);
00209 sout << "Running as a worker...\n";
00210 int result = w. Work ();
00211 if (result == chomp::multiwork::mwOk)
00212 sout << "Work completed successfully.\n";
00213 else
00214 sout << "Could not work - probably "
00215 "an error occurred.\n";
00216 }
00217
00218
00219 else
00220 {
00221 Worker w (true);
00222 Coordinator c (interFileName, graphsFileName,
00223 finalPrefix, sharePrefix,
00224 phaseSpacePrefix, fullPhaseSpace,
00225 skipIndices, nWorkers);
00226 c. Port (coordPort);
00227 sout << "Running as a coordinator...\n";
00228 int result = c. Coordinate (coordPort ? 0 : &w);
00229 if (result == chomp::multiwork::mwOk)
00230 sout << "The task completed successfully.\n";
00231 else
00232 sout << "Could not coordinate - probably "
00233 "an error occurred.\n";
00234 }
00235
00236
00237 program_time = "Total time used:";
00238
00239
00240 return 0;
00241 }
00242 catch (const char *msg)
00243 {
00244 sout << "ERROR: " << msg << '\n';
00245 return -1;
00246 }
00247 catch (const std::exception &e)
00248 {
00249 sout << "ERROR: " << e. what () << '\n';
00250 return -1;
00251 }
00252 catch (...)
00253 {
00254 sout << "ABORT: An unknown error occurred.\n";
00255 return -1;
00256 }
00257 }
00258