Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Tsqr_NodeTsqrFactory.hpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //          Kokkos: Node API and Parallel Node Kernels
00005 //              Copyright (2008) Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00038 // 
00039 // ************************************************************************
00040 //@HEADER
00041 
00042 #ifndef __TSQR_NodeTsqrFactory_hpp
00043 #define __TSQR_NodeTsqrFactory_hpp
00044 
00045 #include <Kokkos_ConfigDefs.hpp> // HAVE_KOKKOS_TBB
00046 
00047 #ifdef HAVE_KOKKOS_TBB
00048 #  include <Kokkos_TBBNode.hpp>
00049 #  include <TbbTsqr.hpp>
00050 #endif // HAVE_KOKKOS_TBB
00051 
00052 #ifdef HAVE_KOKKOS_THREADPOOL
00053 #  include <Tsqr_KokkosNodeTsqr.hpp>
00054 #endif // HAVE_KOKKOS_THREADPOOL
00055 
00056 #include <Kokkos_SerialNode.hpp>
00057 #include <Tsqr_SequentialTsqr.hpp>
00058 
00059 #include <Teuchos_ParameterList.hpp>
00060 #include <Teuchos_ParameterListExceptions.hpp>
00061 #include <Teuchos_RCP.hpp>
00062 #include <Teuchos_ScalarTraits.hpp>
00063 #include <Teuchos_TypeNameTraits.hpp>
00064 
00065 #include <stdexcept>
00066 
00067 
00068 namespace TSQR {
00069 
00079   template<class Node, class Scalar, class LocalOrdinal>
00080   class NodeTsqrFactory {
00081   public:
00084     typedef Node node_type;
00085     typedef Teuchos::RCP<node_type> node_ptr;
00086 
00089     typedef SequentialTsqr<LocalOrdinal, Scalar> node_tsqr_type;
00090 
00097     static Teuchos::RCP<const Teuchos::ParameterList>
00098     getDefaultParameters ()
00099     {
00100       return Teuchos::parameterList ("NodeTsqr");
00101     }
00102 
00109     static Teuchos::RCP<node_tsqr_type>
00110     makeNodeTsqr (const Teuchos::RCP<node_type>& node,
00111       const Teuchos::RCP<Teuchos::ParameterList>& plist)
00112     {
00113       // This method is implemented with correct behavior for those
00114       // Kokkos Node types for which we have implemented an intranode
00115       // TSQR implementation.
00116       TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
00117          "TSQR is not supported on your Kokkos Node type "
00118          << Teuchos::TypeNameTraits<node_type>::name()
00119          << ".");
00120     }
00121 
00132     static void 
00133     prepareNodeTsqr (const Teuchos::RCP<node_tsqr_type>& nodeTsqr,
00134          const Teuchos::RCP<node_type>& node) 
00135     {
00136       // This method is implemented with correct behavior for those
00137       // Kokkos Node types for which we have implemented an intranode
00138       // TSQR implementation.
00139       TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
00140          "TSQR is not supported on your Kokkos Node type "
00141          << Teuchos::TypeNameTraits<node_type>::name()
00142          << ".");
00143     }
00144   };
00145 
00146 #ifdef HAVE_KOKKOS_TBB
00147   //
00148   // Specialization of NodeTsqrFactory for Kokkos::TBBNode.
00149   //
00150   template<class Scalar, class LocalOrdinal>
00151   class NodeTsqrFactory<Kokkos::TBBNode, Scalar, LocalOrdinal> {
00152   public:
00153     typedef Kokkos::TBBNode node_type;
00154     typedef Teuchos::RCP<node_type> node_ptr;
00155     typedef TBB::TbbTsqr<LocalOrdinal, Scalar> node_tsqr_type;
00156 
00157     static Teuchos::RCP<const Teuchos::ParameterList>
00158     getDefaultParameters ()
00159     {
00160       using Teuchos::ParameterList;
00161       using Teuchos::parameterList;
00162       using Teuchos::RCP;
00163 
00164       RCP<ParameterList> params = parameterList ("NodeTsqr");
00165       // Create a temporary node_tsqr_type instance in order to get
00166       // default parameters.  The empty input parameter list will get
00167       // filled in with default values of missing parameters.
00168       node_tsqr_type nodeTsqr (params);
00169 
00170       return params;
00171     }
00172 
00173     static Teuchos::RCP<node_tsqr_type>
00174     makeNodeTsqr (const Teuchos::RCP<node_type>& node,
00175       const Teuchos::RCP<Teuchos::ParameterList>& params)
00176     {
00177       (void) node;
00178       return Teuchos::rcp (new node_tsqr_type (params));
00179     }
00180 
00181     static void 
00182     prepareNodeTsqr (const Teuchos::RCP<node_tsqr_type>& nodeTsqr,
00183          const Teuchos::RCP<node_type>& node) 
00184     {
00185       // TbbTsqr interacts directly with TBB and doesn't use the
00186       // Kokkos Node.  Thus, the TbbTsqr instance doesn't need to have
00187       // its Kokkos Node instance set.
00188       (void) nodeTsqr;
00189       (void) node;
00190     }
00191   };
00192 #endif // HAVE_KOKKOS_TBB
00193 
00194 #if defined(HAVE_KOKKOS_THREADPOOL)
00195   //
00196   // Specialization of NodeTsqrFactory for Kokkos::TPINode.
00197   //
00198   template<class Scalar, class LocalOrdinal>
00199   class NodeTsqrFactory<Kokkos::TPINode, Scalar, LocalOrdinal> {
00200   public:
00201     typedef Kokkos::TPINode node_type;
00202     typedef Teuchos::RCP<node_type> node_ptr;
00203     typedef KokkosNodeTsqr<LocalOrdinal, Scalar, node_type> node_tsqr_type;
00204 
00205     static Teuchos::RCP<const Teuchos::ParameterList>
00206     getDefaultParameters ()
00207     {
00208       using Teuchos::ParameterList;
00209       using Teuchos::parameterList;
00210       using Teuchos::RCP;
00211 
00212       RCP<ParameterList> params = parameterList ("NodeTsqr");
00213       // Create a temporary node_tsqr_type instance in order to get
00214       // default parameters.  The empty input parameter list will get
00215       // filled in with default values of missing parameters.
00216       node_tsqr_type nodeTsqr (params);
00217 
00218       return params;
00219     }
00220 
00221     static Teuchos::RCP<node_tsqr_type>
00222     makeNodeTsqr (const Teuchos::RCP<node_type>& node,
00223       const Teuchos::RCP<Teuchos::ParameterList>& params)
00224     {
00225       return Teuchos::rcp (new node_tsqr_type (node, params));
00226     }
00227 
00228     static void 
00229     prepareNodeTsqr (const Teuchos::RCP<node_tsqr_type>& nodeTsqr,
00230          const Teuchos::RCP<node_type>& node) 
00231     {
00232       // KokkosNodeTsqr needs a pointer to the Kokkos Node instance.
00233       nodeTsqr->setNode (node);
00234     }
00235   };
00236 #endif // defined(HAVE_KOKKOS_THREADPOOL)
00237 
00238   //
00239   // Specialization of NodeTsqrFactory for Kokkos::SerialNode.
00240   //
00241   template<class Scalar, class LocalOrdinal>
00242   class NodeTsqrFactory<Kokkos::SerialNode, Scalar, LocalOrdinal> {
00243   public:
00244     typedef Kokkos::SerialNode node_type;
00245     typedef Teuchos::RCP<node_type> node_ptr;
00246     typedef SequentialTsqr<LocalOrdinal, Scalar> node_tsqr_type;
00247 
00248     static Teuchos::RCP<const Teuchos::ParameterList>
00249     getDefaultParameters ()
00250     {
00251       using Teuchos::ParameterList;
00252       using Teuchos::parameterList;
00253       using Teuchos::RCP;
00254 
00255       RCP<ParameterList> params = parameterList ("NodeTsqr");
00256       // Create a temporary node_tsqr_type instance in order to get
00257       // default parameters.  The empty input parameter list will get
00258       // filled in with default values of missing parameters.
00259       node_tsqr_type nodeTsqr (params);
00260 
00261       return params;
00262     }
00263 
00264     static Teuchos::RCP<node_tsqr_type>
00265     makeNodeTsqr (const Teuchos::RCP<node_type>& node,
00266       const Teuchos::RCP<Teuchos::ParameterList>& params)
00267     {
00268       (void) node;
00269       return rcp (new node_tsqr_type (params));
00270     }
00271 
00272     static void 
00273     prepareNodeTsqr (const Teuchos::RCP<node_tsqr_type>& nodeTsqr,
00274          const Teuchos::RCP<node_type>& node) 
00275     {
00276       // SequentialTsqr doesn't need the Kokkos Node instance.
00277       (void) nodeTsqr;
00278       (void) node;
00279     }
00280   };
00281 
00282 } // namespace TSQR
00283 
00284 #endif // __TSQR_NodeTsqrFactory_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends