Zoltan2 Version of the Day
AllParameters.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 parameters.  Serial test.
00047 
00048 #include <Zoltan2_config.h>
00049 #include <Zoltan2_Environment.hpp>
00050 #include <Teuchos_ParameterList.hpp>
00051 #include <Teuchos_DefaultComm.hpp>
00052 #include <string>
00053 
00054 using namespace std;
00055 using std::cout;
00056 using std::cerr;
00057 using std::endl;
00058 using std::string;
00059 
00060 //
00061 // For all parameters:
00062 //   parameter name, a valid value, an invalid value
00063 
00064 // FileNameValidator - a number is invalid
00065 
00066 #define NUMFN 3
00067 static string fnParams[NUMFN][3]={
00068   {"debug_output_file", "temp.txt", "5"},
00069   {"timer_output_file", "timerInfo.txt", "10.3"},
00070   {"memory_output_file", "memory.txt", "3.33"}
00071 };
00072 
00073 // Value value is any integer - a string is invalid
00074 
00075 #define NUMANYINT 2 
00076 static string anyIntParams[NUMANYINT][3]={
00077   {"bisection_num_test_cuts", "3", "dont_know"},
00078   {"parallel_part_calculation_count", "2", "dont_know"}
00079 };
00080 
00081 // Value value is a particular string
00082 
00083 #define NUMSTR 31
00084 static string strParams[NUMSTR][3]={
00085   {"error_check_level", "basic_assertions", "invalid_assertion_request"},
00086   {"debug_level", "basic_status", "bogus_status"},
00087   {"timer_type", "no_timers", "invalid_timers"},
00088   {"debug_output_stream", "cout", "invalid_stream"},
00089   {"timer_output_stream", "/dev/null", "invalid_stream"},
00090   {"memory_output_stream", "cerr", "invalid_stream"},
00091   {"debug_procs", "all", "not_a_valid_list_of_any_type"},
00092   {"pqParts", "2,3,4", "not_a_valid_list_of_any_type"},
00093   {"memory_procs", "2-10", "not_a_valid_list_of_any_type"},
00094   {"speed_versus_quality", "balance", "amazing_performance"},
00095   {"memory_versus_speed", "memory", "impossible_performance"},
00096   {"random_seed", "9.999", "xxx"},
00097   {"order_method", "rcm", "rcmNew"},
00098   {"order_package", "amd", "amdNew"},
00099   {"compute_metrics", "yes", "maybe"},
00100   {"topology", "2,3,6", "I_don't_know"},
00101   {"randomize_input", "1", "22"},
00102   {"partitioning_objective", "balance_object_weight", "get_curry"},
00103   {"imbalance_tolerance", "1.1", "intolerant"},
00104   {"num_global_parts", "12", "xxx"},
00105   {"num_local_parts", "1", "no_idea"},
00106   {"partitioning_approach", "repartition", "cut_it_up"},
00107   {"objects_to_partition", "graph_vertices", "nothing"},
00108   {"model", "graph", "manifold"},
00109   {"algorithm", "rcb", "xyz"},
00110   {"rectilinear_blocks", "yes", "dont_know"},
00111   {"average_cuts", "false", "dont_know"},
00112   {"symmetrize_input", "transpose", "dont_know"},
00113   {"subset_graph", "1", "dont_know"},
00114   {"force_binary_search", "true", "dont_know"},
00115   {"force_linear_search", "yes", "dont_know"} 
00116 };
00117 
00118 
00119 template <typename T>
00120 int testInvalidValue( Teuchos::ParameterList &pl, 
00121   string paramName, T badValue)
00122 {
00123   Teuchos::ParameterList validParameters;
00124   pl.set(paramName, badValue);
00125   cout << endl;
00126   cout << paramName << " = " << badValue << endl;
00127 
00128   bool failed = false;
00129   try{
00130     Zoltan2::createValidatorList(pl, validParameters);
00131     pl.validateParametersAndSetDefaults(validParameters);
00132   }
00133   catch(std::exception &e){
00134     cout << "Correctly generated an error:" << endl;
00135     cout << e.what() << endl;
00136     failed = true;
00137   }
00138 
00139   if (!failed){
00140     cerr << "Bad parameter was not detected in parameter list." << endl;
00141     return 1;
00142   }
00143   return 0;
00144 }
00145 
00146   // Print out all the documentation
00147 
00148 int main(int argc, char *argv[])
00149 {
00150   Teuchos::GlobalMPISession session(&argc, &argv);
00151   Teuchos::RCP<const Teuchos::Comm<int> > comm =
00152     Teuchos::DefaultComm<int>::getComm();
00153 
00154   int rank = comm->getRank();
00155 
00156   if (rank > 0)
00157     return 0;
00158 
00159   // Create a valid parameter list.
00160 
00161   Teuchos::ParameterList validParameters;
00162   Teuchos::ParameterList myParams("testParameterList");
00163 
00164   for (int i=0; i < NUMSTR; i++){
00165     myParams.set(strParams[i][0], strParams[i][1]);
00166   }
00167 
00168   for (int i=0; i < NUMANYINT; i++){
00169     istringstream iss(anyIntParams[i][1]);
00170     int paramValue;
00171     iss >> paramValue;
00172     myParams.set(anyIntParams[i][0], paramValue);
00173   }
00174 
00175   for (int i=0; i < NUMFN; i++){
00176     myParams.set(fnParams[i][0], fnParams[i][1]);
00177   }
00178 
00179   Teuchos::ParameterList origParams(myParams);
00180 
00181   // Normally an application would not call this.  The
00182   // Environment object will validate the entered parameters.
00183 
00184   try{
00185     Zoltan2::createValidatorList(myParams, validParameters);
00186     myParams.validateParametersAndSetDefaults(validParameters);
00187     Zoltan2::Environment::convertStringToInt(myParams);
00188   }
00189   catch(std::exception &e){
00190     std::cerr << "Validate parameters generated an error:" << endl;
00191     std::cerr << e.what() << endl;
00192     std::cerr << "FAIL" << endl;
00193     return 1;
00194   }
00195 
00196   cout << endl;
00197   cout << "Parameters after validation: " << endl;
00198   cout << myParams << endl;
00199 
00200   // Try invalid parameter values
00201 
00202   for (int i=0; i < NUMSTR; i++){
00203     Teuchos::ParameterList badParams(origParams);
00204     int fail = 
00205       testInvalidValue<string>(badParams, strParams[i][0], strParams[i][2]);
00206     if (fail){
00207       cout << "FAIL" << endl;
00208       return 1;
00209     }
00210   }
00211 
00212   for (int i=0; i < NUMANYINT; i++){
00213     Teuchos::ParameterList badParams(origParams);
00214     int fail = 
00215        testInvalidValue<string>(badParams, anyIntParams[i][0], anyIntParams[i][2]);
00216     if (fail){
00217       cout << "FAIL" << endl;
00218       return 1;
00219     }
00220   }
00221 
00222   for (int i=0; i < NUMFN; i++){
00223     Teuchos::ParameterList badParams(origParams);
00224     istringstream iss(fnParams[i][2]);
00225     double badVal;
00226     iss >> badVal;
00227     int fail = 
00228        testInvalidValue<double>(badParams, fnParams[i][0], badVal);
00229     if (fail){
00230       cout << "FAIL" << endl;
00231       return 1;
00232     }
00233   }
00234 
00235 
00236   // Print out all the documentation
00237 
00238   cout << endl;
00239   cout << "Parameter documentation:" << endl;
00240   Zoltan2::printListDocumentation(validParameters, cout, std::string()); 
00241 
00242   cout << "PASS"  << endl;
00243   return 0;
00244 }