Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros 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
54 #include "Xpetra_TpetraCrsGraph.hpp"
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,
66  class GlobalOrdinal,
69  private:
72 
73  public:
75  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
76  Build (const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap)
77  {
78  TEUCHOS_TEST_FOR_EXCEPTION(rowMap->lib() == UseEpetra, std::logic_error,
79  "Can't create Xpetra::EpetraCrsMatrix with these scalar/LO/GO types");
80 #ifdef HAVE_XPETRA_TPETRA
81  if (rowMap->lib() == UseTpetra)
82  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap, 0) );
83 #endif
84 
86  }
87 
89  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
90  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t maxNumEntriesPerRow) {
91  XPETRA_MONITOR("CrsGraphFactory::Build");
92 
93 #ifdef HAVE_XPETRA_TPETRA
94  if (map->lib() == UseTpetra)
95  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node> (map, maxNumEntriesPerRow) );
96 #endif
97 
100  TEUCHOS_UNREACHABLE_RETURN(null);
101  }
102 
104  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
105  Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap,
106  const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap,
107  const ArrayRCP< const size_t > &NumEntriesPerRowToAlloc,
108  const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
109  XPETRA_MONITOR("CrsGraphFactory::Build");
110 
111 #ifdef HAVE_XPETRA_TPETRA
112  if (rowMap->lib() == UseTpetra)
113  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, plist) );
114 #endif
115 
116  XPETRA_FACTORY_ERROR_IF_EPETRA(rowMap->lib());
118  TEUCHOS_UNREACHABLE_RETURN(null);
119  }
120 
121 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
122 #ifdef HAVE_XPETRA_TPETRA
123  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
143  Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap,
144  const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap,
147  const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
148  XPETRA_MONITOR("CrsMatrixFactory::Build");
149 
150  if (rowMap->lib() == UseTpetra)
152  colMap,
153  rowPointers,
154  columnIndices,
155  plist));
156 
158  }
159 
178  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
179  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
180  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
182  const Teuchos::RCP<Teuchos::ParameterList>& params) {
183  XPETRA_MONITOR("CrsMatrixFactory::Build");
184 
185  if (rowMap->lib() == UseTpetra)
186  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap,
187  colMap,
188  lclGraph,
189  params));
190 
192  }
193 
218  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
220  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
221  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
222  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
223  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
224  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
225  XPETRA_MONITOR("CrsMatrixFactory::Build");
226 
227  if (rowMap->lib() == UseTpetra)
228  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(lclGraph,
229  rowMap,
230  colMap,
231  domainMap,
232  rangeMap,
233  params));
234 
236  }
237 #endif
238 #endif
239 
240  };
241 
242 // we need the Epetra specialization only if Epetra is enabled
243 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES))
244 
245  template <>
246  class CrsGraphFactory<int, int, EpetraNode> {
247 
248  typedef int LocalOrdinal;
249  typedef int GlobalOrdinal;
250  typedef EpetraNode Node;
251 
252  private:
255 
256  public:
258  static RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
259  Build (const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap)
260  {
261  XPETRA_MONITOR("CrsMatrixFactory::Build");
262 #ifdef HAVE_XPETRA_TPETRA
263  if (rowMap->lib() == UseTpetra)
264  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap, 0) );
265 #endif
266 #ifdef HAVE_XPETRA_EPETRA
267  if(rowMap->lib() == UseEpetra)
268  return rcp( new EpetraCrsGraphT<int,Node>(rowMap));
269 #endif
271  }
272 
273  static RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
274  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t maxNumEntriesPerRow) {
275  XPETRA_MONITOR("CrsGraphFactory::Build");
276 
277 #ifdef HAVE_XPETRA_TPETRA
278  if (map->lib() == UseTpetra)
279  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node> (map, maxNumEntriesPerRow) );
280 #endif
281 
282  if (map->lib() == UseEpetra)
283  return rcp( new EpetraCrsGraphT<int, Node>(map, maxNumEntriesPerRow) );
284 
286  TEUCHOS_UNREACHABLE_RETURN(null);
287  }
288 
289  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
290  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, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
291  XPETRA_MONITOR("CrsGraphFactory::Build");
292 
293 #ifdef HAVE_XPETRA_TPETRA
294  if (rowMap->lib() == UseTpetra)
295  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, plist) );
296 #endif
297 
298  if (rowMap->lib() == UseEpetra)
299  return rcp( new EpetraCrsGraphT<int, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, plist) );
300 
302  TEUCHOS_UNREACHABLE_RETURN(null);
303  }
304 
305 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
306 #ifdef HAVE_XPETRA_TPETRA
307  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
327  Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap,
328  const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap,
331  const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
332  XPETRA_MONITOR("CrsMatrixFactory::Build");
333 
334  if (rowMap->lib() == UseTpetra)
336  colMap,
337  rowPointers,
338  columnIndices,
339  plist));
340 
342  }
343 
362  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
363  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
364  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
366  const Teuchos::RCP<Teuchos::ParameterList>& params) {
367  XPETRA_MONITOR("CrsMatrixFactory::Build");
368 
369  if (rowMap->lib() == UseTpetra)
370  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap,
371  colMap,
372  lclGraph,
373  params));
374 
376  }
377 
402  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
404  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
405  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
406  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
407  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
408  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
409  XPETRA_MONITOR("CrsMatrixFactory::Build");
410 
411  if (rowMap->lib() == UseTpetra)
412  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(lclGraph,
413  rowMap,
414  colMap,
415  domainMap,
416  rangeMap,
417  params));
418 
420  }
421 #endif
422 #endif
423 
424  };
425 #endif
426 
427 // we need the Epetra specialization only if Epetra is enabled
428 #if (defined(HAVE_XPETRA_EPETRA) && !defined(XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES))
429 
430  template <>
431  class CrsGraphFactory<int, long long, EpetraNode> {
432 
433  typedef int LocalOrdinal;
434  typedef long long GlobalOrdinal;
435  typedef EpetraNode Node;
436 
437  private:
440 
441  public:
443  static RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
444  Build (const RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &rowMap)
445  {
446  XPETRA_MONITOR("CrsMatrixFactory::Build");
447 #ifdef HAVE_XPETRA_TPETRA
448  if (rowMap->lib() == UseTpetra)
449  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap, 0) );
450 #endif
451 #ifdef HAVE_XPETRA_EPETRA
452  if(rowMap->lib() == UseEpetra)
453  return rcp( new EpetraCrsGraphT<long long,Node>(rowMap));
454 #endif
456  }
457 
458  static RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
459  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > &map, size_t maxNumEntriesPerRow) {
460  XPETRA_MONITOR("CrsGraphFactory::Build");
461 
462 #ifdef HAVE_XPETRA_TPETRA
463  if (map->lib() == UseTpetra)
464  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node> (map, maxNumEntriesPerRow) );
465 #endif
466 
467  if (map->lib() == UseEpetra)
468  return rcp( new EpetraCrsGraphT<long long, Node>(map, maxNumEntriesPerRow) );
469 
471  TEUCHOS_UNREACHABLE_RETURN(null);
472  }
473 
474  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
475  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, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
476  XPETRA_MONITOR("CrsGraphFactory::Build");
477 
478 #ifdef HAVE_XPETRA_TPETRA
479  if (rowMap->lib() == UseTpetra)
480  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, plist) );
481 #endif
482 
483  if (rowMap->lib() == UseEpetra)
484  return rcp( new EpetraCrsGraphT<long long, Node>(rowMap, colMap, NumEntriesPerRowToAlloc, plist) );
485 
487  TEUCHOS_UNREACHABLE_RETURN(null);
488  }
489 
490 #ifdef HAVE_XPETRA_KOKKOS_REFACTOR
491 #ifdef HAVE_XPETRA_TPETRA
492  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
512  Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap,
513  const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &colMap,
516  const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null) {
517  XPETRA_MONITOR("CrsMatrixFactory::Build");
518 
519  if (rowMap->lib() == UseTpetra)
521  colMap,
522  rowPointers,
523  columnIndices,
524  plist));
525 
527  }
528 
547  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
548  Build(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
549  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
551  const Teuchos::RCP<Teuchos::ParameterList>& params) {
552  XPETRA_MONITOR("CrsMatrixFactory::Build");
553 
554  if (rowMap->lib() == UseTpetra)
555  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(rowMap,
556  colMap,
557  lclGraph,
558  params));
559 
561  }
562 
587  static Teuchos::RCP<CrsGraph<LocalOrdinal, GlobalOrdinal, Node> >
589  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rowMap,
590  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& colMap,
591  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& domainMap = Teuchos::null,
592  const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >& rangeMap = Teuchos::null,
593  const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null) {
594  XPETRA_MONITOR("CrsMatrixFactory::Build");
595 
596  if (rowMap->lib() == UseTpetra)
597  return rcp( new TpetraCrsGraph<LocalOrdinal, GlobalOrdinal, Node>(lclGraph,
598  rowMap,
599  colMap,
600  domainMap,
601  rangeMap,
602  params));
603 
605  }
606 #endif
607 #endif
608 
609  };
610 #endif
611 }
612 
613 #define XPETRA_CRSGRAPHFACTORY_SHORT
614 #endif
static RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow)
#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, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
static RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap)
Constructor for empty graph (intended use is an import/export target - can&#39;t insert entries directly)...
static Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap)
Constructor for empty graph (intended use is an import/export target - can&#39;t insert entries directly)...
static RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rowMap)
Constructor for empty graph (intended use is an import/export target - can&#39;t insert entries directly)...
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, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
#define XPETRA_FACTORY_END
static RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow)
CrsGraphFactory()
Private constructor. This is a static class.
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, const Teuchos::RCP< Teuchos::ParameterList > &plist=Teuchos::null)
Constructor specifying column Map and number of entries in each row.
#define XPETRA_MONITOR(funcName)
static Teuchos::RCP< CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow)
Constructor specifying the number of non-zeros for all rows.
CrsGraphFactory()
Private constructor. This is a static class.
CrsGraphFactory()
Private constructor. This is a static class.