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
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 #include "rounding.h"
00111
00112
00113 #include "coord.h"
00114 #include "worker.h"
00115 #include "maptypes.h"
00116 #include "parttypes.h"
00117
00118
00119 #include <string>
00120 #include <vector>
00121 #include <exception>
00122
00123
00124 #include "chomp/system/config.h"
00125 #include "chomp/system/textfile.h"
00126 #include "chomp/system/timeused.h"
00127 #include "chomp/multiwork/mw.h"
00128 #include "chomp/system/arg.h"
00129
00130
00131
00132
00133
00134
00135
00136 const char *title = "\
00137 UniformExpansion, ver. 0.01, 11/14/2007. (C) 2007 by Pawel Pilarczyk.\n\
00138 This is free software. No warranty. Consult 'license.txt' for details.";
00139
00140
00141 const char *helpinfo = "\
00142 This is a computer program for the rigorous analysis of the uniform\n\
00143 expansion condition as described in the paper by S. Day, H. Kokubu,\n\
00144 S. Luzzatto, K. Mischaikow, H. Oka, and P. Pilarczyk. See the paper\n\
00145 for details, and the attached documentation for directions.\n\
00146 Command line arguments:\n\
00147 -a N - set the value of the map's parameter (an obligatory argument!),\n\
00148 -m name - use the map with the given name (default: quadratic),\n\
00149 -p name - use partition with the given name (default: uniform),\n\
00150 -k N - set the number of intervals, including crit. nbhd (default: 1001),\n\
00151 -d N - fix delta (the radius of the critical neighborhood; default: 0.01),\n\
00152 -f name - save results of computations to this file,\n\
00153 -s N - use algorithms for sparse graphs: 0=no, 1=yes, -1=auto (default),\n\
00154 --rigorous - run rigorous computations (with controlled rounding),\n\
00155 --flush - flush the data written to the results file (slow),\n\
00156 --help - show this brief help information and exit.\n\
00157 Arguments that define what to compute (default: lambda, C, and lambda0):\n\
00158 --lambda - compute lambda for (1) in the paper,\n\
00159 --C - compute C for (1) in the paper (implies the computation of lambda),\n\
00160 --lambda0 - compute lambda for (2) in the paper (implies --lambda),\n\
00161 --delta - compute min delta s.t. lambda > 0 (does not imply --lambda),\n\
00162 --delta0 - compute min delta s.t. lambda0 > 0 (does not imply --lambda),\n\
00163 -l N - fix a lambda or lambda0 for --delta or --delta0 (default: 0),\n\
00164 -r N - relative resolution for computing log delta (default: 0.01).\n\
00165 If one of the arguments '-a', '-d', '-k', '-l' is repeated, then the\n\
00166 computations are run for all the parameters from the given interval.\n\
00167 -i - use full intervals of parameters (applies only for '-a'),\n\
00168 -L N - level of initial subdivisions (default: 4); 2^n are made at start,\n\
00169 -L N - level of final subdivisions (def: 10); 2^n subdivisions are made.\n\
00170 Arguments for running distributed computing:\n\
00171 -w computer:port - run a worker and connect to the given coordinator,\n\
00172 -c [port] - run the coordinator and listen at the given port (def: 4721).";
00173
00174
00175 const char *helpmore = "\
00176 For more information ask the author at http://www.pawelpilarczyk.com/.";
00177
00178
00179
00180 const int controlNumber = 42342;
00181
00182
00183
00184
00185
00186
00187
00188
00189 int main (int argc, char *argv [])
00190 {
00191 using namespace chomp::homology;
00192 using namespace chomp::multiwork;
00193 using namespace unifexp;
00194
00195
00196 const double infinity = 1.7e308;
00197 double paramMin = -infinity;
00198 double paramMax = -infinity;
00199 double deltaMin = 0;
00200 double deltaMax = -infinity;
00201 double resolution = 0.01;
00202 double lambdaMin = 0;
00203 double lambdaMax = -infinity;
00204 int partCountMin = 1001;
00205 int partCountMax = -1;
00206 char *mapName = 0;
00207 char *defMapName = const_cast<char *> ("quadratic");
00208 char *defMapNameRigorous = const_cast<char *> ("quadratic-intv");
00209 char *partName = const_cast<char *> ("uniform");
00210 int port = 0;
00211 char *work = 0;
00212 bool test = false;
00213 bool flushfile = false;
00214 char *filename = 0;
00215 bool intervals = false;
00216 int startLevel = 4;
00217 int finalLevel = 6;
00218 int computeDelta = 0;
00219 int computeDelta0 = 0;
00220 int computeLambda = 0;
00221 int computeC = 0;
00222 int computeLambda0 = 0;
00223 int rigorous = 0;
00224 int sparseGraph = -1;
00225
00226
00227 arguments a;
00228 arg (a, "a", paramMin);
00229 arg (a, "a", paramMax);
00230 arg (a, "d", deltaMin);
00231 arg (a, "d", deltaMax);
00232 arg (a, "r", resolution);
00233 arg (a, "k", partCountMin);
00234 arg (a, "k", partCountMax);
00235 arg (a, "m", mapName);
00236 arg (a, "p", partName);
00237 arg (a, "f", filename);
00238 arg (a, "c", port, 4721);
00239 arg (a, "w", work);
00240 arg (a, "L", startLevel);
00241 arg (a, "L", finalLevel);
00242 arg (a, "l", lambdaMin);
00243 arg (a, "l", lambdaMax);
00244 arg (a, "s", sparseGraph);
00245 argswitch (a, "i", intervals, true);
00246 argswitch (a, "t", test, true);
00247 argswitch (a, "-test", test, true);
00248 argswitch (a, "-flush", flushfile, true);
00249 argswitch (a, "-delta0", computeDelta0, 1);
00250 argswitch (a, "-delta", computeDelta, 1);
00251 argswitch (a, "-lambda0", computeLambda0, 1);
00252 argswitch (a, "-lambda", computeLambda, 1);
00253 argswitch (a, "-C", computeC, 1);
00254 argswitch (a, "-rigorous", rigorous, 1);
00255 arghelp (a);
00256
00257 argstreamprepare (a);
00258 int argresult = a. analyze (argc, argv);
00259 argstreamset ();
00260
00261
00262 if (argresult >= 0)
00263 sout << title << '\n';
00264
00265
00266 if (argresult < 0)
00267 {
00268 sout << "Call with '--help' for help.\n";
00269 return 2;
00270 }
00271
00272
00273 if (((paramMin == -infinity) && !work && !test) || (argresult > 0))
00274 {
00275 sout << helpinfo << '\n';
00276 typedef std::vector<std::string> strings;
00277
00278
00279 strings partNames;
00280 partTypes<double> partitions;
00281 partitions. getNames (partNames);
00282 sout << "Available partitions:";
00283 int pos = 14;
00284 for (strings::iterator it = partNames. begin ();
00285 it != partNames. end (); ++ it)
00286 {
00287 if (pos + (*it). length () > 70)
00288 {
00289 sout << "\n\t";
00290 pos = 0;
00291 }
00292 else if (pos > 0)
00293 sout << " ";
00294 sout << (*it);
00295 pos += (*it). length () + 1;
00296 }
00297 sout << ".\n";
00298
00299
00300 strings mapNames;
00301 mapTypes<double> maps;
00302 maps. getNames (mapNames);
00303 sout << "Available maps:";
00304 pos = 8;
00305 for (strings::iterator it = mapNames. begin ();
00306 it != mapNames. end (); ++ it)
00307 {
00308 if (pos + (*it). length () > 70)
00309 {
00310 sout << "\n\t";
00311 pos = 0;
00312 }
00313 else if (pos > 0)
00314 sout << " ";
00315 sout << (*it);
00316 pos += (*it). length () + 1;
00317 }
00318 sout << ".\n";
00319
00320 sout << helpmore << '\n';
00321 return 1;
00322 }
00323
00324
00325 if (!computeDelta && !computeDelta0 && (deltaMin <= 0))
00326 deltaMin = deltaMax = 0.01;
00327
00328
00329 if (paramMax < paramMin)
00330 paramMax = paramMin;
00331 if (deltaMax < deltaMin)
00332 deltaMax = deltaMin;
00333 if (lambdaMax < lambdaMin)
00334 lambdaMax = lambdaMin;
00335 if (partCountMax < partCountMin)
00336 partCountMax = partCountMin;
00337
00338
00339 if (!mapName)
00340 mapName = rigorous ? defMapNameRigorous : defMapName;
00341
00342
00343 if (!computeDelta && !computeDelta0 && !computeLambda &&
00344 !computeC && !computeLambda0)
00345 {
00346 computeLambda = 1;
00347 computeC = 1;
00348 computeLambda0 = 1;
00349 }
00350
00351
00352 if (finalLevel < startLevel)
00353 finalLevel = startLevel;
00354
00355
00356 try
00357 {
00358
00359 program_time = "Aborted after:";
00360 program_time = 1;
00361
00362
00363 if (test)
00364 {
00365 }
00366
00367
00368 else if (work)
00369 {
00370 Worker w (controlNumber, false);
00371 w. Add (work);
00372 sout << "Running as a worker...\n";
00373 int result = w. Work ();
00374 if (result == mwOk)
00375 sout << "Work completed successfully.\n";
00376 else
00377 sout << "Could not work - probably "
00378 "an error occurred.\n";
00379 }
00380
00381
00382 else
00383 {
00384
00385 Coordinator c (controlNumber, filename, flushfile,
00386 paramMin, paramMax, intervals,
00387 deltaMin, deltaMax, resolution,
00388 lambdaMin, lambdaMax, mapName,
00389 partName, partCountMin, partCountMax,
00390 startLevel, finalLevel,
00391 computeDelta, computeDelta0,
00392 computeLambda, computeC, computeLambda0,
00393 rigorous, sparseGraph);
00394 c. Port (port);
00395
00396
00397 if (port)
00398 {
00399 sout << "Running as a coordinator...\n";
00400 int result = c. Coordinate ();
00401 if (result == mwOk)
00402 sout << "Completed successfully.\n";
00403 else
00404 sout << "Could not coordinate - "
00405 "an error occurred.\n";
00406 }
00407
00408
00409 else
00410 {
00411 Worker w (controlNumber, true);
00412 sout << "Running the computations...\n";
00413 int result = c. Coordinate (&w);
00414 if (result == mwOk)
00415 sout << "Completed successfully.\n";
00416 else
00417 sout << "Could not work - probably "
00418 "an error occurred.\n";
00419 }
00420 }
00421
00422
00423 program_time = "Total time used:";
00424
00425
00426 return 0;
00427 }
00428 catch (const char *msg)
00429 {
00430 sout << "ERROR: " << msg << '\n';
00431 return -1;
00432 }
00433 catch (const std::exception &e)
00434 {
00435 sout << "ERROR: " << e. what () << '\n';
00436 return -1;
00437 }
00438 catch (...)
00439 {
00440 sout << "ABORT: An unknown error occurred.\n";
00441 return -1;
00442 }
00443 }
00444
00445
00446