|
Zoltan2
|
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 the MetricOutputManager object. 00047 // 00048 // Verbosity levels are 00049 // NO_STATUS, 00050 // BASIC_STATUS, 00051 // DETAILED_STATUS, 00052 // VERBOSE_DETAILED_STATUS 00053 // NUM_STATUS_OUTPUT_LEVELS 00054 // 00055 // This test can only really be verified by reading the output. 00056 // So we are testing that MetricOutputManager doesn't crash. 00057 00058 00059 #include <Zoltan2_MetricOutputManager.hpp> 00060 #include <Zoltan2_Parameters.hpp> 00061 #include <Zoltan2_TestHelpers.hpp> 00062 00063 #include <Teuchos_DefaultComm.hpp> 00064 00065 #include <set> 00066 #include <iostream> 00067 #include <string> 00068 #include <ostream> 00069 00070 using namespace std; 00071 using std::string; 00072 using Zoltan2::MetricOutputManager; 00073 00074 int main(int argc, char *argv[]) 00075 { 00076 Teuchos::GlobalMPISession session(&argc, &argv); 00077 Teuchos::RCP<const Teuchos::Comm<int> > comm = 00078 Teuchos::DefaultComm<int>::getComm(); 00079 00080 int rank = comm->getRank(); 00081 int nprocs = comm->getSize(); 00082 bool fail = false; 00083 00084 MetricOutputManager<int> *intmom = NULL; 00085 MetricOutputManager<float> *floatmom = NULL; 00086 MetricOutputManager<double> *doublemom = NULL; 00087 00088 // Even ranks print to cout 00089 00090 bool iPrint = (rank%2 == 0); 00091 bool someOnePrints = true; 00092 00093 comm->barrier(); 00094 00095 try { 00096 intmom = new MetricOutputManager<int>( 00097 rank, iPrint, std::cout, someOnePrints, string("units"), 10); 00098 } 00099 catch(std::exception &e){ 00100 fail=true; 00101 } 00102 00103 TEST_FAIL_AND_EXIT(*comm, !fail, "constructor", 1); 00104 00105 if (intmom->getMetricsOn() != true) 00106 fail = true; 00107 00108 TEST_FAIL_AND_EXIT(*comm, !fail, "getMetricsOn", 1); 00109 00110 if (rank==0){ 00111 std::cout << "\nThere are " << nprocs << " processes. "; 00112 std::cout << "Even ranks only participate." << std::endl; 00113 } 00114 00115 try{ 00116 intmom->print(string("number of things"), 10); 00117 intmom->print(string("number of other things"), 5); 00118 } 00119 catch(std::exception &e){ 00120 fail=true; 00121 } 00122 00123 TEST_FAIL_AND_EXIT(*comm, !fail, "print to standard output", 1); 00124 00125 delete intmom; 00126 00127 // All print to cout 00128 00129 iPrint = true; 00130 someOnePrints = true; 00131 comm->barrier(); 00132 00133 try { 00134 floatmom = new MetricOutputManager<float>( 00135 00136 rank, iPrint, std::cout, someOnePrints, string("dollars"), 10); 00137 } 00138 catch(std::exception &e){ 00139 fail=true; 00140 } 00141 00142 TEST_FAIL_AND_EXIT(*comm, !fail, "constructor", 1); 00143 00144 if (floatmom->getMetricsOn() != true) 00145 fail = true; 00146 00147 TEST_FAIL_AND_EXIT(*comm, !fail, "getMetricsOn", 1); 00148 00149 if (rank==0){ 00150 std::cout << "\nThere are " << nprocs << " processes. "; 00151 std::cout << "All ranks participate." << std::endl; 00152 } 00153 00154 try{ 00155 floatmom->print(string("Price of things"), 10.10); 00156 floatmom->print(string("Price of other things"), 25.25); 00157 } 00158 catch(std::exception &e){ 00159 fail=true; 00160 } 00161 00162 TEST_FAIL_AND_EXIT(*comm, !fail, "all print to standard output", 1); 00163 00164 delete floatmom; 00165 00166 // Node zero prints to a file. 00167 00168 iPrint = (rank == 0); 00169 someOnePrints = true; 00170 comm->barrier(); 00171 00172 ios_base::openmode flags = ios_base::out & ios_base::trunc; 00173 00174 ofstream outF("testMetricFile.txt", flags); 00175 00176 try { 00177 doublemom = new MetricOutputManager<double>( rank, iPrint, outF, someOnePrints, string("microseconds"), 10); 00178 } 00179 catch(std::exception &e){ 00180 fail=true; 00181 } 00182 00183 TEST_FAIL_AND_EXIT(*comm, !fail, "constructor", 1); 00184 00185 if (rank==0){ 00186 std::cout << "\nThere are " << nprocs << " processes. "; 00187 std::cout << "Rank zero only participates" << std::endl; 00188 } 00189 00190 try{ 00191 doublemom->print(string("Time to do something"), 00192 10.101012345); 00193 doublemom->print(string("Time to do something else"), 00194 25.2500024); 00195 } 00196 catch(std::exception &e){ 00197 fail=true; 00198 } 00199 00200 TEST_FAIL_AND_EXIT(*comm, !fail, "printing to a file", 1); 00201 00202 outF.close(); 00203 00204 comm->barrier(); 00205 00206 if (rank == 0){ 00207 ifstream inF("testMetricFile.txt"); 00208 string s; 00209 while (getline(inF, s)){ 00210 std::cout << s << std::endl; 00211 } 00212 inF.close(); 00213 system("rm testMetricFile.txt"); // \todo fix for windows 00214 } 00215 00216 comm->barrier(); 00217 00218 delete doublemom; 00219 00220 if (rank==0) 00221 std::cout << "PASS" << std::endl; 00222 }
1.7.6.1