Anasazi Version of the Day
Tsqr_TestSetup.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_TestSetup_hpp
00030 #define __TSQR_TestSetup_hpp
00031 
00032 #include <Tsqr_MessengerBase.hpp>
00033 #include <Tsqr_Random_GlobalMatrix.hpp>
00034 #include <Tsqr_Matrix.hpp>
00035 #include <Tsqr_ScalarTraits.hpp>
00036 
00037 #include <vector>
00038 
00041 
00042 namespace TSQR { 
00043   namespace Test {
00044 
00045     template< class Ordinal, class CommOrdinal >
00046     Ordinal 
00047     numLocalRows (const Ordinal nrowsGlobal, 
00048       const CommOrdinal myRank,
00049       const CommOrdinal nprocs)
00050     {
00051       const Ordinal nrowsLocal = nrowsGlobal / Ordinal(nprocs);
00052       const Ordinal remainder = nrowsGlobal - nrowsLocal * Ordinal(nprocs);
00053       if (myRank != nprocs - 1)
00054   return nrowsLocal;
00055       else
00056   return nrowsLocal + remainder;
00057     }
00058 
00065     template< class MatrixViewType, class Generator >
00066     void
00067     distributedTestProblem (Generator& generator,
00068           MatrixViewType& A_local,
00069           MessengerBase< typename MatrixViewType::ordinal_type >* const ordinalComm,
00070           MessengerBase< typename MatrixViewType::scalar_type >* const scalarComm)
00071     {
00072       typedef typename MatrixViewType::ordinal_type ordinal_type;
00073       typedef typename MatrixViewType::scalar_type scalar_type;
00074       typedef typename ScalarTraits< scalar_type >::magnitude_type magnitude_type;
00075 
00076       const int myRank = scalarComm->rank();
00077       const ordinal_type ncols = A_local.ncols();
00078 
00079       if (myRank == 0)
00080   {
00081     // Generate some singular values for the test problem.
00082     std::vector< magnitude_type > singular_values (ncols);
00083     singular_values[0] = 1.0;
00084     for (ordinal_type k = 1; k < ncols; ++k)
00085       singular_values[k] = singular_values[k-1] / double(2);
00086 
00087     // Generate the test problem.  All MPI processes
00088     // participate, but only Proc 0 generates the (pseudo)random
00089     // numbers.
00090     TSQR::Random::randomGlobalMatrix (&generator, A_local, 
00091               &singular_values[0], ordinalComm,
00092               scalarComm);
00093   }
00094       else
00095   {
00096     // This helps C++ deduce the type; the values aren't read on
00097     // this proc.
00098     magnitude_type singular_values[1];
00099 
00100     // All MPI processes participate in the distribution of the
00101     // test matrix.
00102     TSQR::Random::randomGlobalMatrix (&generator, A_local, 
00103               &singular_values[0], ordinalComm,
00104               scalarComm);
00105   }
00106     }
00107   } // namespace Test
00108 } // namespace TSQR
00109 
00110 #endif // __TSQR_TestSetup_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends