Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Tpetra_RowGraph_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_ROWGRAPH_DEF_HPP
00043 #define TPETRA_ROWGRAPH_DEF_HPP
00044 
00045 #include <Tpetra_RowGraph_decl.hpp>
00046 #include <Tpetra_Distributor.hpp> // avoid error C2027: use of undefined type 'Tpetra::Distributor' at (void) distor below
00047 
00048 namespace Tpetra {
00049   template<class LocalOrdinal, class GlobalOrdinal, class Node>
00050   void
00051   RowGraph<LocalOrdinal,GlobalOrdinal,Node>::
00052   pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
00053   Teuchos::Array<GlobalOrdinal>& exports,
00054   const Teuchos::ArrayView<size_t>& numPacketsPerLID,
00055   size_t& constantNumPackets,
00056   Distributor& distor) const
00057   {
00058     using Teuchos::Array;
00059     typedef LocalOrdinal LO;
00060     typedef GlobalOrdinal GO;
00061     typedef Map<LO, GO, Node> map_type;
00062     const char tfecfFuncName[] = "packAndPrepare";
00063     (void) distor; // forestall "unused argument" compiler warning
00064 
00065     TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
00066       exportLIDs.size() != numPacketsPerLID.size(), std::runtime_error,
00067       ": exportLIDs and numPacketsPerLID must have the same size.");
00068 
00069     const map_type& srcMap = * (this->getRowMap ());
00070     constantNumPackets = 0;
00071 
00072     // Set numPacketsPerLID[i] to the number of entries owned by the
00073     // calling process in (local) row exportLIDs[i] of the graph, that
00074     // the caller wants us to send out.  Compute the total number of
00075     // packets (that is, entries) owned by this process in all the
00076     // rows that the caller wants us to send out.
00077     size_t totalNumPackets = 0;
00078     Array<GO> row;
00079     for (LO i = 0; i < exportLIDs.size (); ++i) {
00080       const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
00081       size_t row_length = this->getNumEntriesInGlobalRow (GID);
00082       numPacketsPerLID[i] = row_length;
00083       totalNumPackets += row_length;
00084     }
00085 
00086     exports.resize (totalNumPackets);
00087 
00088     // Loop again over the rows to export, and pack rows of indices
00089     // into the output buffer.
00090     size_t exportsOffset = 0;
00091     for (LO i = 0; i < exportLIDs.size (); ++i) {
00092       const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
00093       size_t row_length = this->getNumEntriesInGlobalRow (GID);
00094       row.resize (row_length);
00095       size_t check_row_length = 0;
00096       this->getGlobalRowCopy (GID, row (), check_row_length);
00097       typename Array<GO>::const_iterator row_iter = row.begin();
00098       typename Array<GO>::const_iterator row_end = row.end();
00099       size_t j = 0;
00100       for (; row_iter != row_end; ++row_iter, ++j) {
00101         exports[exportsOffset+j] = *row_iter;
00102       }
00103       exportsOffset += row.size ();
00104     }
00105   }
00106 } // namespace Tpetra
00107 
00108 //
00109 // Explicit instantiation macro
00110 //
00111 // Must be expanded from within the Tpetra namespace!
00112 //
00113 
00114 #define TPETRA_ROWGRAPH_INSTANT(LO,GO,NODE) \
00115   \
00116   template class RowGraph< LO , GO , NODE >; \
00117 
00118 #endif // TPETRA_ROWGRAPH_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines