Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_MatrixMarket_SymmetrizingGraphAdder.hpp
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef __Teuchos_MatrixMarket_SymmetrizingGraphAdder_hpp
11#define __Teuchos_MatrixMarket_SymmetrizingGraphAdder_hpp
12
13#include <Teuchos_as.hpp>
15#include <string>
16
17
18// Macro that marks a function as "possibly unused," in order to
19// suppress build warnings.
20#if ! defined(TRILINOS_UNUSED_FUNCTION)
21# if defined(__GNUC__) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
22# define TRILINOS_UNUSED_FUNCTION __attribute__((__unused__))
23# elif defined(__clang__)
24# if __has_attribute(unused)
25# define TRILINOS_UNUSED_FUNCTION __attribute__((__unused__))
26# else
27# define TRILINOS_UNUSED_FUNCTION
28# endif // Clang has 'unused' attribute
29# elif defined(__IBMCPP__)
30// IBM's C++ compiler for Blue Gene/Q (V12.1) implements 'used' but not 'unused'.
31//
32// http://pic.dhe.ibm.com/infocenter/compbg/v121v141/index.jsp
33# define TRILINOS_UNUSED_FUNCTION
34# else // some other compiler
35# define TRILINOS_UNUSED_FUNCTION
36# endif
37#endif // ! defined(TRILINOS_UNUSED_FUNCTION)
38
39
40namespace Teuchos {
41 namespace MatrixMarket {
42
62 template<class AdderType>
64 public:
66 typedef typename AdderType::index_type index_type;
67
75 const std::string& symmType) :
76 adder_ (adder),
77 symmetrize_ (needsSymmetrization (symmType)),
78 skew_ (isSkew (symmType))
79 {}
80
82 void
84 const index_type j)
85 {
86 AdderType& theAdder = *adder_;
87
88 theAdder (i, j);
89 if (symmetrize_ && i != j) {
90 // The optional third argument (which defaults to true)
91 // specifies whether or not to count the entry against the
92 // total expected number of entries. We don't want to count
93 // this entry because it wasn't part of the original data;
94 // we inserted it because the caller doesn't want symmetric
95 // storage. The original data's total expected number of
96 // entries only counts the entries that are in the original
97 // data, not those that we insert.
98 theAdder (j, i, false);
99 }
100 }
101
106 return adder_;
107 }
108
109 private:
113 bool symmetrize_;
115 bool skew_;
116 };
117
118 } // namespace MatrixMarket
119} // namespace Teuchos
120
121#endif // __Teuchos_MatrixMarket_SymmetrizingGraphAdder_hpp
Defines basic traits for the scalar field type.
Definition of Teuchos::as, for conversions between types.
Adds entries with optional symmetry to a sparse graph.
void operator()(const index_type i, const index_type j)
Add entry (i,j), and optionally symmetrize.
SymmetrizingGraphAdder(const Teuchos::RCP< AdderType > &adder, const std::string &symmType)
Constructor.
AdderType::index_type index_type
The type of indices of the sparse graph.
Teuchos::RCP< AdderType > getAdder() const
Persisting non-const view of the underlying adder object.
Smart reference counting pointer class for automatic garbage collection.
Matrix Market file utilities.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...