cmgraphs.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// @file cmgraphs.cpp
00004 ///
00005 /// Conley-Morse graphs - the main program.
00006 /// This program computes a set of Conley-Morse graphs
00007 /// for a given discrete dynamical system
00008 /// for a prescribed rectangular range of parameters,
00009 /// and establishes the continuation relation
00010 /// between adjacent computed graphs.
00011 ///
00012 /// @author Pawel Pilarczyk
00013 ///
00014 ///
00015 /// @mainpage The Conley-Morse Graphs Software
00016 ///
00017 /// \section intro Introduction
00018 ///
00019 /// This website contains the documentation of software designed and
00020 /// programmed by Pawel Pilarczyk which accompanies the paper
00021 /// <em>Databases for the Global Dynamics of Multiparameter Systems</em>
00022 /// by Z. Arai, W. Kalies, H. Kokubu, K. Mischaikow, H. Oka,
00023 /// and P. Pilarczyk. Please, see the
00024 /// <a href="http://chomp.rutgers.edu/database/">website of the project</a>
00025 /// and refer to the <a href="http://www.pawelpilarczyk.com/cmgraphs/">page
00026 /// devoted to the software</a> for more information.
00027 ///
00028 /// \section license License
00029 ///
00030 /// In order to make this software freely available for wide audience,
00031 /// it is provided here under the terms of the
00032 /// <a href="http://www.gnu.org/copyleft/gpl.html">GNU General
00033 /// Public License</a>, and this documentation is provided under the terms
00034 /// of the <a href="http://www.gnu.org/copyleft/fdl.html">GNU Free
00035 /// Documentation License</a>.
00036 ///
00037 /// \section browsing Browsing
00038 ///
00039 /// Although a lot of effort has been put into making this software
00040 /// as transparent and clear as possible,
00041 /// and to make this documentation complete,
00042 /// I am sure that there is a lot of important information
00043 /// which should have been included here but was omitted.
00044 /// Therefore, this documentation was generated in such
00045 /// a way that it contains the entire source code
00046 /// which can be browsed and verified in case of any doubt.
00047 ///
00048 /// So, what are you waiting for? Have a nice browsing!
00049 ///
00050 /// Pawel Pilarczyk
00051 ///
00052 /////////////////////////////////////////////////////////////////////////////
00053 
00054 // Copyright (C) 1997-2008 by Pawel Pilarczyk.
00055 //
00056 // This file is part of my research software package.  This is free software;
00057 // you can redistribute it and/or modify it under the terms of the GNU
00058 // General Public License as published by the Free Software Foundation;
00059 // either version 2 of the License, or (at your option) any later version.
00060 //
00061 // This software is distributed in the hope that it will be useful,
00062 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00063 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00064 // GNU General Public License for more details.
00065 //
00066 // You should have received a copy of the GNU General Public License along
00067 // with this software; see the file "license.txt".  If not, write to the
00068 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00069 // MA 02111-1307, USA.
00070 
00071 // Started in November 2005. Last revision: February 24, 2008.
00072 
00073 
00074 // include some standard C++ header files
00075 #include <exception>
00076 
00077 // include selected header files from the CHomP library
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 // include local header files
00085 #include "config.h"
00086 #include "typedefs.h"
00087 #include "worker.h"
00088 #include "coord.h"
00089 
00090 
00091 // --------------------------------------------------
00092 // -------------------- OVERTURE --------------------
00093 // --------------------------------------------------
00094 
00095 /// The title of the program which is displayed every time
00096 /// the program is launcued.
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 /// The help information about the program which is displayed
00103 /// if the program is launched without command-line arguments
00104 /// or with incorrect arguments.
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 // ---------------------- MAIN ----------------------
00130 // --------------------------------------------------
00131 
00132 /// The main procedure of the program.
00133 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
00134 int main (int argc, char *argv [])
00135 {
00136         using namespace chomp::homology;
00137 
00138         // prepare user-configurable data
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         // interprete the command-line arguments
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         // if the final results prefix is specified but no port for the
00169         // coordinator was specified then set it to 0 (local work)
00170         if (finalPrefix && (coordPort < 0))
00171                 coordPort = 0;
00172 
00173         // if no worker/coordinator selected then show help information
00174         if (!finalPrefix && !workAddress)
00175                 argresult = 1;
00176 
00177         // show the program's main title
00178         if (argresult >= 0)
00179                 sout << title << '\n';
00180 
00181         // if something was incorrect, show an additional message and exit
00182         if (argresult < 0)
00183         {
00184                 sout << "Call with '--help' for help.\n";
00185                 return 2;
00186         }
00187 
00188         // if help requested, show help information
00189         if (argresult > 0)
00190         {
00191                 sout << helpinfo << '\n';
00192                 return 1;
00193         }
00194 
00195         // try running the main function and catch an error message if thrown
00196         try
00197         {
00198                 // set an appropriate program time message
00199                 program_time = "Aborted after:";
00200                 program_time = 1;
00201 
00202                 // run as a worker if requested to
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                 // run as a coordinator otherwise
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                 // set an appropriate program time message
00237                 program_time = "Total time used:";
00238 
00239                 // finalize
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 } /* main */
00258 

Generated on Sun Mar 28 17:47:57 2010 for The Conley-Morse Graphs Software by  doxygen 1.5.3