Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Tsqr_generateStack.hpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //          Kokkos: Node API and Parallel Node Kernels
00005 //              Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ************************************************************************
00027 //@HEADER
00028 
00029 #ifndef __TSQR_Test_generateStack_hpp
00030 #define __TSQR_Test_generateStack_hpp
00031 
00032 #include <Tsqr_Blas.hpp>
00033 #include <Tsqr_Lapack.hpp>
00034 #include <Tsqr_Matrix.hpp>
00035 #include <Tsqr_Util.hpp>
00036 #include <Tsqr_Random_MatrixGenerator.hpp>
00037 #include <Tsqr_RMessenger.hpp>
00038 
00039 #include <algorithm>
00040 #include <functional>
00041 #include <sstream>
00042 #include <stdexcept>
00043 
00044 
00045 namespace TSQR {
00046   namespace Test {
00047 
00067     template<class Ordinal, class Scalar, class Generator>
00068     static void
00069     generateStack (Generator& generator,
00070        Matrix<Ordinal, Scalar>& A_global,
00071        const typename Teuchos::ScalarTraits<Scalar>::magnitudeType singularValues[],
00072        const int numProcs,
00073        const Ordinal numCols)
00074     {
00075       TSQR::Random::MatrixGenerator<Ordinal, Scalar, Generator> matGen (generator);
00076       const Ordinal numRows = numProcs * numCols;
00077       A_global.reshape (numRows, numCols);
00078       A_global.fill (Scalar(0));
00079 
00080       for (int p = 0; p < numProcs; ++p)
00081   {
00082     Scalar* const curptr = A_global.get() + p*numCols;
00083     MatView<Ordinal, Scalar> R_cur (numCols, numCols, curptr, numRows);
00084     matGen.fill_random_R (numCols, R_cur.get(), numRows, singularValues);
00085   }
00086     }
00087 
00114     template<class Ordinal, class Scalar, class Generator>
00115     void
00116     par_tsqr_test_problem (Generator& generator,
00117          Matrix<Ordinal, Scalar>& A_local,
00118          Matrix<Ordinal, Scalar>& A_global, 
00119          const Ordinal ncols,
00120          const Teuchos::RCP<MessengerBase<Scalar> >& messenger)
00121     {
00122       const int nprocs = messenger->size();
00123       const int my_rank = messenger->rank();
00124       A_local.reshape (ncols, ncols);
00125 
00126       if (my_rank == 0)
00127   {
00128     typedef typename Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type;
00129 
00130     std::vector< magnitude_type > singular_values (ncols);
00131     singular_values[0] = magnitude_type(1);
00132     for (Ordinal k = 1; k < ncols; ++k)
00133       singular_values[k] = singular_values[k-1] / magnitude_type(2);
00134 
00135     generateStack (generator, A_global, &singular_values[0], nprocs, ncols);
00136     scatterStack (A_global, A_local, messenger);
00137   }
00138       else
00139   scatterStack (A_global, A_local, messenger);
00140     }
00141 
00142 
00143   } // namespace Test
00144 } // namespace TSQR
00145 
00146 #endif // __TSQR_Test_generateStack_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends