|
Tpetra Matrix/Vector Services
Version of the Day
|
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_DirectoryImpl_decl_hpp 00043 #define __Tpetra_DirectoryImpl_decl_hpp 00044 00045 #include <Tpetra_ConfigDefs.hpp> 00046 #include "Tpetra_TieBreak.hpp" 00047 00048 // 00049 // mfh 13-15 May 2013: HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX governs 00050 // the fix for Bug 5822. The fix is enabled by default. To disable 00051 // the fix, uncomment out the three lines below that undefine 00052 // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX, and comment out the three 00053 // lines below them that define that macro. 00054 // 00055 // mfh 23 Mar 2014: I want Bug 5822 to stay fixed, so I am removing 00056 // all references to HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX. I hope no 00057 // downstream code is using that macro, but just in case, I will leave 00058 // it defined. 00059 00060 #ifndef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX 00061 # define HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX 1 00062 #endif // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX 00063 00064 #include <Tpetra_Details_FixedHashTable_decl.hpp> 00065 00066 00067 namespace Tpetra { 00068 // Forward declaration. 00069 template <class LocalOrdinal, class GlobalOrdinal, class Node> class Map; 00070 00071 namespace Details { 00072 // Forward declaration. 00073 template <class LocalOrdinal, class GlobalOrdinal> class TieBreak; 00074 00082 template<class LocalOrdinal, class GlobalOrdinal, class NodeType> 00083 class Directory : public Teuchos::Describable { 00084 public: 00085 typedef LocalOrdinal local_ordinal_type; 00086 typedef GlobalOrdinal global_ordinal_type; 00087 typedef NodeType node_type; 00088 typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, NodeType> map_type; 00089 00097 Directory (); 00098 00131 LookupStatus 00132 getEntries (const map_type& map, 00133 const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs, 00134 const Teuchos::ArrayView<int> &nodeIDs, 00135 const Teuchos::ArrayView<LocalOrdinal> &localIDs, 00136 const bool computeLIDs) const; 00137 00144 virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const = 0; 00145 00146 protected: 00148 virtual LookupStatus 00149 getEntriesImpl (const map_type& map, 00150 const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs, 00151 const Teuchos::ArrayView<int> &nodeIDs, 00152 const Teuchos::ArrayView<LocalOrdinal> &localIDs, 00153 const bool computeLIDs) const = 0; 00154 }; 00155 00158 template<class LocalOrdinal, class GlobalOrdinal, class NodeType> 00159 class ReplicatedDirectory : 00160 public Directory<LocalOrdinal, GlobalOrdinal, NodeType> { 00161 public: 00162 typedef Directory<LocalOrdinal, GlobalOrdinal, NodeType> base_type; 00163 typedef typename base_type::map_type map_type; 00164 00166 ReplicatedDirectory (const map_type& map); 00167 00169 ReplicatedDirectory (); 00170 00171 virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const; 00172 00173 template <class Node2> 00174 Directory<LocalOrdinal,GlobalOrdinal,Node2>* 00175 clone (const Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const 00176 { 00177 typedef ReplicatedDirectory<LocalOrdinal,GlobalOrdinal,Node2> Dir2; 00178 return new Dir2 (cloneMap); 00179 } 00180 00182 00183 00185 std::string description () const; 00187 protected: 00189 LookupStatus 00190 getEntriesImpl (const map_type& map, 00191 const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs, 00192 const Teuchos::ArrayView<int> &nodeIDs, 00193 const Teuchos::ArrayView<LocalOrdinal> &localIDs, 00194 const bool computeLIDs) const; 00195 00196 private: 00198 const int numProcs_; 00199 }; 00200 00201 00210 template<class LocalOrdinal, class GlobalOrdinal, class NodeType> 00211 class ContiguousUniformDirectory : 00212 public Directory<LocalOrdinal, GlobalOrdinal, NodeType> { 00213 private: 00214 // This friend declaration lets us implement clone(). 00215 template <class LO, class GO, class N> friend class ContiguousUniformDirectory; 00216 00218 ContiguousUniformDirectory () {} 00219 00220 public: 00221 typedef Directory<LocalOrdinal, GlobalOrdinal, NodeType> base_type; 00222 typedef typename base_type::map_type map_type; 00223 00225 ContiguousUniformDirectory (const map_type& map); 00226 00227 virtual bool isOneToOne (const Teuchos::Comm<int>&) const { 00228 return true; 00229 } 00230 00231 template <class Node2> 00232 Directory<LocalOrdinal,GlobalOrdinal,Node2>* 00233 clone (const Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const 00234 { 00235 typedef ContiguousUniformDirectory<LocalOrdinal,GlobalOrdinal,Node2> Dir2; 00236 return new Dir2 (cloneMap); 00237 } 00238 00240 00241 00243 std::string description () const; 00245 00246 protected: 00248 LookupStatus 00249 getEntriesImpl (const map_type& map, 00250 const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs, 00251 const Teuchos::ArrayView<int> &nodeIDs, 00252 const Teuchos::ArrayView<LocalOrdinal> &localIDs, 00253 const bool computeLIDs) const; 00254 }; 00255 00256 00259 template<class LocalOrdinal, class GlobalOrdinal, class NodeType> 00260 class DistributedContiguousDirectory : 00261 public Directory<LocalOrdinal, GlobalOrdinal, NodeType> { 00262 private: 00263 template <class LO, class GO, class N> friend class DistributedContiguousDirectory; 00264 00266 DistributedContiguousDirectory () {} 00267 00268 public: 00269 typedef Directory<LocalOrdinal, GlobalOrdinal, NodeType> base_type; 00270 typedef typename base_type::map_type map_type; 00271 00273 DistributedContiguousDirectory (const map_type& map); 00274 00275 virtual bool isOneToOne (const Teuchos::Comm<int>&) const { 00276 return true; 00277 } 00278 00279 template <class Node2> 00280 Directory<LocalOrdinal,GlobalOrdinal,Node2>* 00281 clone (const Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const 00282 { 00283 typedef DistributedContiguousDirectory<LocalOrdinal,GlobalOrdinal,Node2> Dir2; 00284 Dir2* dir = new Dir2 (cloneMap); 00285 try { 00286 dir->allMinGIDs_ = allMinGIDs_; 00287 } catch (std::exception& e) { 00288 delete dir; // clean up just in case assignment throws (it shouldn't) 00289 throw; 00290 } 00291 return dir; 00292 } 00293 00295 00296 00298 std::string description () const; 00300 00301 protected: 00303 LookupStatus 00304 getEntriesImpl (const map_type& map, 00305 const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs, 00306 const Teuchos::ArrayView<int> &nodeIDs, 00307 const Teuchos::ArrayView<LocalOrdinal> &localIDs, 00308 const bool computeLIDs) const; 00309 00310 private: 00334 Teuchos::ArrayRCP<GlobalOrdinal> allMinGIDs_; 00335 }; 00336 00339 template<class LocalOrdinal, class GlobalOrdinal, class NodeType> 00340 class DistributedNoncontiguousDirectory : 00341 public Directory<LocalOrdinal, GlobalOrdinal, NodeType> { 00342 private: 00343 template <class LO, class GO, class N> friend class DistributedNoncontiguousDirectory; 00345 DistributedNoncontiguousDirectory () {} 00346 00347 public: 00348 typedef Tpetra::Details::TieBreak<LocalOrdinal, GlobalOrdinal> tie_break_type; 00349 typedef Directory<LocalOrdinal, GlobalOrdinal, NodeType> base_type; 00350 typedef typename base_type::map_type map_type; 00351 00353 DistributedNoncontiguousDirectory (const map_type& map); 00354 00356 DistributedNoncontiguousDirectory (const map_type& map, 00357 const tie_break_type& tie_break); 00358 00359 virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const; 00360 00361 template <class Node2> 00362 Directory<LocalOrdinal,GlobalOrdinal,Node2>* 00363 clone (const Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const 00364 { 00365 typedef DistributedNoncontiguousDirectory<LocalOrdinal,GlobalOrdinal,Node2> Dir2; 00366 typedef Map<LocalOrdinal,GlobalOrdinal,Node2> output_map_type; 00367 Dir2* dir = new Dir2 (cloneMap); 00368 00369 // This method returns a raw pointer. Thus, take care to 00370 // check whether intermediate operations succeed, so that we 00371 // don't leak memory if they don't. 00372 RCP<const output_map_type> outDirMap; 00373 try { 00374 outDirMap = directoryMap_->template clone<Node2> (cloneMap.getNode ()); 00375 } 00376 catch (...) { 00377 outDirMap = Teuchos::null; // deallocate 00378 throw; 00379 } 00380 00381 dir->directoryMap_ = outDirMap; 00382 dir->PIDs_ = PIDs_; 00383 dir->LIDs_ = LIDs_; 00384 dir->lidToPidTable_ = lidToPidTable_; 00385 dir->lidToLidTable_ = lidToLidTable_; 00386 dir->useHashTables_ = useHashTables_; 00387 return dir; 00388 } 00389 00391 00392 00394 std::string description () const; 00396 protected: 00398 LookupStatus 00399 getEntriesImpl (const map_type& map, 00400 const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs, 00401 const Teuchos::ArrayView<int> &nodeIDs, 00402 const Teuchos::ArrayView<LocalOrdinal> &localIDs, 00403 const bool computeLIDs) const; 00404 private: 00411 void 00412 initialize (const map_type& map, 00413 Teuchos::Ptr<const tie_break_type> tie_break); 00414 00427 bool isLocallyOneToOne () const { 00428 return locallyOneToOne_; 00429 } 00430 00448 Teuchos::RCP<const map_type> directoryMap_; 00449 00451 00452 00458 Teuchos::ArrayRCP<int> PIDs_; 00459 00465 Teuchos::ArrayRCP<LocalOrdinal> LIDs_; 00466 00468 00469 00470 00476 Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int> > lidToPidTable_; 00477 00483 Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal> > lidToLidTable_; 00485 00492 mutable enum EOneToOneResult { 00493 ONE_TO_ONE_NOT_CALLED_YET, 00494 ONE_TO_ONE_FALSE, 00495 ONE_TO_ONE_TRUE 00496 } oneToOneResult_; 00497 00501 bool locallyOneToOne_; 00502 00510 bool useHashTables_; 00511 }; 00512 } // namespace Details 00513 } // namespace Tpetra 00514 00515 #endif // __Tpetra_DirectoryImpl_decl_hpp
1.7.6.1