Zoltan2 Version of the Day
Parameters.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 //
00003 // ***********************************************************************
00004 //
00005 //   Zoltan2: A package of combinatorial algorithms for scientific computing
00006 //                  Copyright 2012 Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Karen Devine      (kddevin@sandia.gov)
00039 //                    Erik Boman        (egboman@sandia.gov)
00040 //                    Siva Rajamanickam (srajama@sandia.gov)
00041 //
00042 // ***********************************************************************
00043 //
00044 // @HEADER
00045 //
00046 // Testing integer range list parameters.  Serial test.
00047 
00048 #include <Zoltan2_config.h>
00049 #include <Zoltan2_Environment.hpp>
00050 #include <Zoltan2_IntegerRangeList.hpp>
00051 #include <Teuchos_ParameterList.hpp>
00052 #include <Teuchos_DefaultComm.hpp>
00053 #include <Teuchos_Array.hpp>
00054 #include <Teuchos_ParameterEntryValidator.hpp>
00055 
00056 typedef Teuchos::Array<int> rangeList_t;
00057 
00058 int main(int argc, char *argv[])
00059 {
00060   Teuchos::GlobalMPISession session(&argc, &argv);
00061   Teuchos::RCP<const Teuchos::Comm<int> > comm =
00062     Teuchos::DefaultComm<int>::getComm();
00063 
00064   int rank = comm->getRank();
00065 
00066   if (rank > 0)
00067     return 0;
00068 
00069   // Set a few parameters, and then validate them.
00070 
00071   Teuchos::ParameterList validParameters;
00072 
00073   Teuchos::ParameterList myParams("testParameterList");
00074 
00075   myParams.set("debug_level", "detailed_status");        
00076   myParams.set("debug_procs", "all");   
00077   myParams.set("debug_output_stream", "std::cout");
00078 
00079   myParams.set("timer_output_file", "appPerformance.txt");
00080 
00081   // Normally an application would not call this.  The
00082   // Environment object will validate the entered parameters.
00083   // Since debug_procs is an IntegerRangeList,
00084   // this call will convert it to a Teuchos::Array that uses
00085   // a special flag to indicate "all" or "none".
00086 
00087   try{
00088     Zoltan2::createValidatorList(myParams, validParameters);
00089     myParams.validateParametersAndSetDefaults(validParameters);
00090     Zoltan2::Environment::convertStringToInt(myParams);
00091   }
00092   catch(std::exception &e){
00093     std::cerr << "Validate parameters generated an error:" << std::endl;
00094     std::cerr << e.what() << std::endl;
00095     std::cerr << "FAIL" << std::endl;
00096     return 1;
00097   }
00098 
00099   validParameters = Teuchos::ParameterList();
00100 
00101   std::cout << std::endl;
00102   std::cout << "A few parameters after validation: " << std::endl;
00103   std::cout << myParams << std::endl;
00104 
00105   rangeList_t &a1 = myParams.get<rangeList_t>("debug_procs");
00106   std::cout << "debug_procs translation: ";
00107   Zoltan2::printIntegralRangeList(std::cout, a1);
00108   std::cout << std::endl;
00109 
00110   // Now let's enter a bad value for a parameter and make sure
00111   // we get an error.
00112 
00113   Teuchos::ParameterList faultyParams("badParameterList");
00114   faultyParams.set("debug_procs", "not-even-remotely-an-integer-range");
00115   bool failed = false;
00116   try{
00117     Zoltan2::createValidatorList(faultyParams, validParameters);
00118     faultyParams.validateParametersAndSetDefaults(validParameters);
00119   }
00120   catch(std::exception &e){
00121     std::cout << std::endl;
00122     std::cout << "Invalid parameter correctly generated an error:" << std::endl;
00123     std::cout << e.what() << std::endl;
00124     failed = true;
00125   }
00126 
00127   validParameters = Teuchos::ParameterList();
00128 
00129   if (!failed){
00130     std::cerr << "Bad parameter was not detected in parameter list." << std::endl;
00131     return 1;
00132   }
00133 
00134   // Now set every parameter to a reasonable value
00135 
00136   Teuchos::ParameterList all("setAllParametersList");
00137   all.set("debug_level", "basic_status");
00138 
00139   all.set("debug_procs", "1,2,5-10,2");
00140   all.set("memory_procs", "1,2,3,4,all");
00141 
00142   all.set("debug_output_stream", "std::cerr");
00143   all.set("timer_output_stream", "std::cout");
00144   all.set("memory_output_stream", "/dev/null");
00145 
00146 
00147   all.set("debug_output_file", "/home/me/debug.txt");
00148   all.set("timer_output_file", "/home/me/performance.txt");
00149   all.set("memory_output_file", "/home/me/memoryUsed.txt");
00150 
00151   all.set("speed_versus_quality", "speed");
00152   all.set("memory_versus_speed", "memory");
00153 
00154   all.set("error_check_level", "basic_assertions");
00155 
00156   all.set("random_seed", .12121212);
00157 
00158   all.set("topology", "2,6,6");
00159 
00160   all.set("randomize_input", "true");
00161 
00162   all.set("partitioning_objective", "minimize_cut_edge_weight");
00163 
00164   all.set("imbalance_tolerance", 1.2);
00165 
00166   all.set("num_global_parts", 12);
00167   all.set("num_local_parts", 2);
00168 
00169   all.set("partitioning_approach", "partition");
00170 
00171   all.set("objects_to_partition", "graph_vertices");
00172 
00173   all.set("model", "hypergraph");
00174 
00175   all.set("algorithm", "phg");
00176 
00177   all.set("symmetrize_input", "no");
00178   all.set("subset_graph", "false");
00179 
00180   try{
00181     Zoltan2::createValidatorList(all, validParameters);
00182     all.validateParametersAndSetDefaults(validParameters);
00183     Zoltan2::Environment::convertStringToInt(all);
00184   }
00185   catch(std::exception &e){
00186     std::cerr << "Validate parameters generated an error:" << std::endl;
00187     std::cerr << e.what() << std::endl;
00188     std::cerr << "FAIL" << std::endl;
00189     return 1;
00190   }
00191 
00192   std::cout << std::endl;
00193   std::cout << "All parameters validated and modified: ";
00194   std::cout << all << std::endl;
00195 
00196   a1 = all.get<rangeList_t>("debug_procs");
00197   std::cout << "debug_procs translation: ";
00198   Zoltan2::printIntegralRangeList(std::cout, a1);
00199   std::cout << std::endl;
00200 
00201   a1 = all.get<rangeList_t>("memory_procs");
00202   std::cout << "memory_procs translation: ";
00203   Zoltan2::printIntegralRangeList(std::cout, a1);
00204   std::cout << std::endl;
00205 
00206   // Print out all the documentation
00207 
00208   std::cout << std::endl;
00209   std::cout << "Parameter documentation:" << std::endl;
00210   Zoltan2::printListDocumentation(validParameters, std::cout, std::string()); 
00211 
00212   std::cout << "PASS"  << std::endl;
00213   return 0;
00214 }