Zoltan 2 Version 0.5
StridedData.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 // This is another test where you need to look at the output to
00047 // know if it's right.  This should be fixed.
00048 
00057 #include <Zoltan2_StridedData.hpp>   
00058 #include <Zoltan2_TestHelpers.hpp>   
00059 
00060 using Zoltan2::StridedData;
00061 using Teuchos::RCP;
00062 using Teuchos::rcp;
00063 using Teuchos::ArrayRCP;
00064 using Teuchos::Array;
00065 using namespace std;
00066 
00067 void StridedDataTest(Teuchos::RCP<const Teuchos::Comm<int> > &comm)
00068 {
00069   // StridedData template arguments
00070 
00071   typedef lno_t     index_t;
00072   typedef scalar_t  value_t;
00073 
00074   typedef StridedData<index_t, value_t> stridedInput_t;
00075 
00079   ArrayRCP<value_t> input1(new value_t [12], 0, 12, true);
00080   for (int i=0; i < 12; i++)
00081     input1[i] = (i+1) * 5; 
00082 
00083   RCP<stridedInput_t> s1;
00084 
00085   try{
00086     s1 = rcp<stridedInput_t>(new stridedInput_t(input1, 1));
00087   }
00088   catch (std::exception &e){
00089     TEST_FAIL_AND_EXIT(*comm, 0, "Error in constructor 1", 1);
00090   }
00091 
00092   std::cout << std::endl;
00093   std::cout << "Test 1, input: " << input1 << std::endl;
00094   std::cout << "[] test: ";
00095   for (int i=0; i < 12; i++)
00096     std::cout << (*s1)[i] << " ";
00097   std::cout << std::endl;
00098 
00099   ArrayRCP<const value_t> fromS1;
00100   s1->getInputArray(fromS1);
00101   std::cout << "getInputArray test: ";
00102   for (int i=0; i < 12; i++)
00103     std::cout << fromS1[i] << " ";
00104   std::cout << std::endl;
00105 
00106   stridedInput_t s1Copy;
00107   s1Copy = *s1;
00108 
00109   std::cout << "assignment operator test: ";
00110   for (int i=0; i < 12; i++)
00111     std::cout << s1Copy[i] << " ";
00112   std::cout << std::endl;
00113 
00117   ArrayRCP<value_t> input2(new value_t [12], 0, 12, true);
00118   for (int i=0; i < 12; i+=3)
00119     input2[i] = (i+1) * -5.0; 
00120 
00121   RCP<stridedInput_t> s2;
00122 
00123   try{
00124     s2 = rcp<stridedInput_t>(new stridedInput_t(input2, 3));
00125   }
00126   catch (std::exception &e){
00127     TEST_FAIL_AND_EXIT(*comm, 0, "Error in constructor 2", 2);
00128   }
00129 
00130   std::cout << std::endl;
00131   std::cout << "Test 2, input: " << input2 << std::endl;
00132   std::cout << "[] test: ";
00133   for (int i=0; i < 4; i++)
00134     std::cout << (*s2)[i] << " ";
00135   std::cout << std::endl;
00136 
00137   ArrayRCP<const value_t> fromS2;
00138   s2->getInputArray(fromS2);
00139   std::cout << "getInputArray test: ";
00140   for (int i=0; i < 4; i++)
00141     std::cout << fromS2[i] << " ";
00142   std::cout << std::endl;
00143 
00144   stridedInput_t s2Copy;
00145   s2Copy = *s2;
00146 
00147   std::cout << "assignment operator test: ";
00148   for (int i=0; i < 4; i++)
00149     std::cout << s2Copy[i] << " ";
00150   std::cout << std::endl;
00151 }
00152 
00153 int main(int argc, char *argv[])
00154 {
00155   Teuchos::GlobalMPISession session(&argc, &argv);
00156   Teuchos::RCP<const Teuchos::Comm<int> > comm = 
00157     Teuchos::DefaultComm<int>::getComm();
00158 
00159   if (comm->getRank() > 0)
00160     return 0;
00161 
00162   StridedDataTest(comm);
00163 
00164   std::cout << "PASS" << std::endl;
00165 }