Anasazi Version of the Day
Tsqr_generateStack.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                 Anasazi: Block Eigensolvers Package
00005 //                 Copyright (2010) 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 
00046 
00047 namespace TSQR {
00048   namespace Test {
00049 
00058     template< class Ordinal, class Scalar, class Generator >
00059     static void
00060     generateStack (Generator& generator,
00061        Matrix< Ordinal, Scalar >& A_global,
00062        const typename ScalarTraits< Scalar >::magnitude_type singular_values[],
00063        const int nprocs,
00064        const Ordinal ncols)
00065     {
00066       TSQR::Random::MatrixGenerator< Ordinal, Scalar, Generator > matGen (generator);
00067       const Ordinal nrows = nprocs * ncols;
00068       A_global.reshape (nrows, ncols);
00069       A_global.fill (Scalar(0));
00070 
00071       for (int p = 0; p < nprocs; ++p)
00072   {
00073     Scalar* const curptr = A_global.get() + p*ncols;
00074     MatView< Ordinal, Scalar > R_cur (ncols, ncols, curptr, nrows);
00075     matGen.fill_random_R (ncols, R_cur.get(), nrows, singular_values);
00076   }
00077     }
00078 
00096     template< class Ordinal, class Scalar, class Generator >
00097     void
00098     par_tsqr_test_problem (Generator& generator,
00099          Matrix< Ordinal, Scalar >& A_local,
00100          Matrix< Ordinal, Scalar >& A_global, 
00101          const Ordinal ncols,
00102          const Teuchos::RCP< MessengerBase< Scalar > >& messenger)
00103     {
00104       const int nprocs = messenger->size();
00105       const int my_rank = messenger->rank();
00106       A_local.reshape (ncols, ncols);
00107 
00108       if (my_rank == 0)
00109   {
00110     typedef typename ScalarTraits< Scalar >::magnitude_type magnitude_type;
00111 
00112     std::vector< magnitude_type > singular_values (ncols);
00113     singular_values[0] = magnitude_type(1);
00114     for (Ordinal k = 1; k < ncols; ++k)
00115       singular_values[k] = singular_values[k-1] / magnitude_type(2);
00116 
00117     generateStack (generator, A_global, &singular_values[0], nprocs, ncols);
00118     scatterStack (A_global, A_local, messenger);
00119   }
00120       else
00121   scatterStack (A_global, A_local, messenger);
00122     }
00123 
00124 
00125   } // namespace Test
00126 } // namespace TSQR
00127 
00128 #endif // __TSQR_Test_generateStack_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends