All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Xpetra_CrsGraphFactory.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_CRSGRAPHFACTORY_HPP
47 #define XPETRA_CRSGRAPHFACTORY_HPP
48 
49 #include "Xpetra_ConfigDefs.hpp"
50 
51 #include "Xpetra_CrsGraph.hpp"
52 
53 #ifdef HAVE_XPETRA_TPETRA
55 #endif
56 
57 #ifdef HAVE_XPETRA_EPETRA
59 #endif
60 
61 #include "Xpetra_Exceptions.hpp"
62 
63 namespace Xpetra {
64 
65  template <class LocalOrdinal/* = CrsGraph<>::local_ordinal_type*/,
66  class GlobalOrdinal/* =
67  typename CrsGraph<LocalOrdinal>::global_ordinal_type*/,
68  class Node/* =
69  typename CrsGraph<LocalOrdinal, GlobalOrdinal>::node_type*/>
71  private:
74 
75  public:
78  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, ProfileType pftype=DynamicProfile) {
79  XPETRA_MONITOR("CrsGraphFactory::Build");
80 
81 #ifdef HAVE_XPETRA_TPETRA
82  if (map->lib() == UseTpetra)
83  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, pftype) );
84 #endif
85 
89  }
90 
95  const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc,
97  const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
98  XPETRA_MONITOR("CrsGraphFactory::Build");
99 
100 #ifdef HAVE_XPETRA_TPETRA
101  if (rowMap->lib() == UseTpetra)
102  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, pftype, plist) );
103 #endif
104 
105  XPETRA_FACTORY_ERROR_IF_EPETRA(rowMap->lib());
108  }
109 
110 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
111 #ifdef HAVE_XPETRA_TPETRA
136  const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
137  XPETRA_MONITOR("CrsMatrixFactory::Build");
138 
139  if (rowMap->lib() == UseTpetra)
141  colMap,
142  rowPointers,
143  columnIndices,
144  plist));
145 
147  }
148 
168  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
169  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
171  const Teuchos::RCP<Teuchos::ParameterList>& params) {
172  XPETRA_MONITOR("CrsMatrixFactory::Build");
173 
174  if (rowMap->lib() == UseTpetra)
175  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap,
176  colMap,
177  lclGraph,
178  params));
179 
181  }
182 
209  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
210  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
211  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
212  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
213  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
214  XPETRA_MONITOR("CrsMatrixFactory::Build");
215 
216  if (rowMap->lib() == UseTpetra)
217  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(lclGraph,
218  rowMap,
219  colMap,
220  domainMap,
221  rangeMap,
222  params));
223 
225  }
226 #endif
227 #endif
228 
229  };
230 
231 // we need the Epetra specialization only if Epetra is enabled
232 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
233 
234  template <>
235  class CrsGraphFactory<int, int, EpetraNode> {
236 
237  typedef int LocalOrdinal;
238  typedef int GlobalOrdinal;
239  typedef EpetraNode Node;
240 
241  private:
244 
245  public:
246 
248  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, ProfileType pftype=DynamicProfile) {
249  XPETRA_MONITOR("CrsGraphFactory::Build");
250 
251 #ifdef HAVE_XPETRA_TPETRA
252  if (map->lib() == UseTpetra)
253  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, pftype) );
254 #endif
255 
256  if (map->lib() == UseEpetra)
257  return rcp( new EpetraCrsGraphT<int, Node>(map, NumVectors, pftype) );
258 
261  }
262 
265  XPETRA_MONITOR("CrsGraphFactory::Build");
266 
267 #ifdef HAVE_XPETRA_TPETRA
268  if (rowMap->lib() == UseTpetra)
269  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, pftype, plist) );
270 #endif
271 
272  if (rowMap->lib() == UseEpetra)
273  return rcp( new EpetraCrsGraphT<int, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, pftype, plist) );
274 
277  }
278 
279 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
280 #ifdef HAVE_XPETRA_TPETRA
305  const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
306  XPETRA_MONITOR("CrsMatrixFactory::Build");
307 
308  if (rowMap->lib() == UseTpetra)
310  colMap,
311  rowPointers,
312  columnIndices,
313  plist));
314 
316  }
317 
337  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
338  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
340  const Teuchos::RCP<Teuchos::ParameterList>& params) {
341  XPETRA_MONITOR("CrsMatrixFactory::Build");
342 
343  if (rowMap->lib() == UseTpetra)
344  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap,
345  colMap,
346  lclGraph,
347  params));
348 
350  }
351 
378  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
379  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
380  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
381  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
382  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
383  XPETRA_MONITOR("CrsMatrixFactory::Build");
384 
385  if (rowMap->lib() == UseTpetra)
386  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(lclGraph,
387  rowMap,
388  colMap,
389  domainMap,
390  rangeMap,
391  params));
392 
394  }
395 #endif
396 #endif
397 
398  };
399 #endif
400 
401 // we need the Epetra specialization only if Epetra is enabled
402 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
403 
404  template <>
405  class CrsGraphFactory<int, long long, EpetraNode> {
406 
407  typedef int LocalOrdinal;
408  typedef long long GlobalOrdinal;
409  typedef EpetraNode Node;
410 
411  private:
414 
415  public:
416 
418  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t NumVectors, ProfileType pftype=DynamicProfile) {
419  XPETRA_MONITOR("CrsGraphFactory::Build");
420 
421 #ifdef HAVE_XPETRA_TPETRA
422  if (map->lib() == UseTpetra)
423  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node> (map, NumVectors, pftype) );
424 #endif
425 
426  if (map->lib() == UseEpetra)
427  return rcp( new EpetraCrsGraphT<long long, Node>(map, NumVectors, pftype) );
428 
431  }
432 
435  XPETRA_MONITOR("CrsGraphFactory::Build");
436 
437 #ifdef HAVE_XPETRA_TPETRA
438  if (rowMap->lib() == UseTpetra)
439  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, pftype, plist) );
440 #endif
441 
442  if (rowMap->lib() == UseEpetra)
443  return rcp( new EpetraCrsGraphT<long long, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, pftype, plist) );
444 
447  }
448 
449 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
450 #ifdef HAVE_XPETRA_TPETRA
475  const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
476  XPETRA_MONITOR("CrsMatrixFactory::Build");
477 
478  if (rowMap->lib() == UseTpetra)
480  colMap,
481  rowPointers,
482  columnIndices,
483  plist));
484 
486  }
487 
507  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
508  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
510  const Teuchos::RCP<Teuchos::ParameterList>& params) {
511  XPETRA_MONITOR("CrsMatrixFactory::Build");
512 
513  if (rowMap->lib() == UseTpetra)
514  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap,
515  colMap,
516  lclGraph,
517  params));
518 
520  }
521 
548  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
549  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
550  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
551  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
552  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
553  XPETRA_MONITOR("CrsMatrixFactory::Build");
554 
555  if (rowMap->lib() == UseTpetra)
556  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(lclGraph,
557  rowMap,
558  colMap,
559  domainMap,
560  rangeMap,
561  params));
562 
564  }
565 #endif
566 #endif
567 
568  };
569 #endif
570 }
571 
572 #define XPETRA_CRSGRAPHFACTORY_SHORT
573 #endif
static Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
static Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, ProfileType pftype=DynamicProfile)
Constructor specifying the number of non-zeros for all rows.
static Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
static RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, ProfileType pftype=DynamicProfile)
#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
static Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap, const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc, ProfileType pftype=DynamicProfile, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and number of entries in each row.
static RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t NumVectors, ProfileType pftype=DynamicProfile)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define XPETRA_FACTORY_END
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
CrsGraphFactory()
Private constructor. This is a static class.
#define XPETRA_MONITOR(funcName)
CrsGraphFactory()
Private constructor. This is a static class.
CrsGraphFactory()
Private constructor. This is a static class.