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