Tpetra Matrix/Vector Services Version of the Day
Tpetra_Directory_def.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //          Tpetra: Templated Linear Algebra Services Package
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 TPETRA_DIRECTORY_HPP
00043 #define TPETRA_DIRECTORY_HPP
00044 
00045 #include <Teuchos_as.hpp>
00046 #include <Tpetra_ConfigDefs.hpp>
00047 #include <Tpetra_Distributor.hpp>
00048 #include <Tpetra_Map.hpp>
00049 #include <Tpetra_DirectoryImpl.hpp>
00050 #include <Tpetra_DirectoryImpl_def.hpp>
00051 
00052 #ifdef DOXYGEN_USE_ONLY
00053 #  include "Tpetra_Directory_decl.hpp"
00054 #endif
00055 
00056 namespace Tpetra {
00057 
00058   template<class LO, class GO, class NT>
00059   Directory<LO, GO, NT>::
00060   Directory (const Teuchos::RCP<const Map<LO, GO, NT> >& map)
00061   {
00062     using Teuchos::Comm;
00063     using Teuchos::gatherAll;
00064     using Teuchos::RCP;
00065     using Teuchos::rcp;
00066 
00067     // Create an implementation object of the appropriate type,
00068     // depending on whether the Map is distributed or replicated, and
00069     // contiguous or noncontiguous.
00070     RCP<const Details::Directory<LO, GO, NT> > dir;
00071     if (map->isDistributed ()) {
00072       if (map->isContiguous ()) {
00073   dir = rcp (new Details::DistributedContiguousDirectory<LO, GO, NT> (map));
00074       }
00075       else {
00076   dir = rcp (new Details::DistributedNoncontiguousDirectory<LO, GO, NT> (map));
00077       }
00078     }
00079     else {
00080       dir = rcp (new Details::ReplicatedDirectory<LO, GO, NT> (map));
00081     }
00082     TEUCHOS_TEST_FOR_EXCEPTION(dir.is_null (), std::logic_error, "Tpetra::"
00083       "Directory constructor failed to create Directory implementation.  "
00084       "Please report this bug to the Tpetra developers.");
00085     impl_ = dir;
00086   }
00087 
00088   template<class LO, class GO, class NT>
00089   Directory<LO, GO, NT>::~Directory() {}
00090 
00091   template<class LO, class GO, class NT>
00092   LookupStatus 
00093   Directory<LO, GO, NT>::
00094   getDirectoryEntries (const Teuchos::ArrayView<const GO>& globalIDs, 
00095            const Teuchos::ArrayView<int>& nodeIDs) const 
00096   {
00097     const bool computeLIDs = false;
00098     return impl_->getEntries (globalIDs, nodeIDs, Teuchos::null, computeLIDs);
00099   }
00100 
00101   template<class LO, class GO, class NT>
00102   LookupStatus 
00103   Directory<LO, GO, NT>::
00104   getDirectoryEntries (const Teuchos::ArrayView<const GO>& globalIDs, 
00105                        const Teuchos::ArrayView<int>& nodeIDs, 
00106                        const Teuchos::ArrayView<LO>& localIDs) const 
00107   {
00108     const bool computeLIDs = true;
00109     return impl_->getEntries (globalIDs, nodeIDs, localIDs, computeLIDs);
00110   }
00111 
00112   template<class LO, class GO, class NT>
00113   std::string 
00114   Directory<LO, GO, NT>::description () const
00115   {
00116     using Teuchos::TypeNameTraits;
00117     
00118     std::ostringstream os;
00119     os << "Directory" 
00120        << "<" << TypeNameTraits<LO>::name ()
00121        << ", " << TypeNameTraits<GO>::name ()
00122        << ", " << TypeNameTraits<NT>::name () << ">";
00123     return os.str ();
00124   }
00125 
00126 } // namespace Tpetra
00127 
00128 //
00129 // Explicit instantiation macro
00130 //
00131 // Must be expanded from within the Tpetra namespace!
00132 //
00133 
00134 #define TPETRA_DIRECTORY_INSTANT(LO,GO,NODE) \
00135   \
00136   template class Directory< LO , GO , NODE >; \
00137 
00138 #endif // TPETRA_DIRECTORY_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines