Tpetra parallel linear algebra
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
inout
Tpetra_DistributionMM.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
// Build maps for 1D or 2D matrix distribution
11
// Assumes square matrix
12
// Karen Devine, SNL
13
//
14
15
#ifndef __TPETRA_DISTRIBUTIONMM_HPP
16
#define __TPETRA_DISTRIBUTIONMM_HPP
17
18
namespace
Tpetra
{
19
20
template
<
typename
gno_t,
typename
scalar_t>
21
class
DistributionMMFile :
public
Distribution<gno_t, scalar_t> {
22
// Distribution of nonzeros is determined by nonzero's value
23
// as read from Matrix-Market file.
24
// Vector entry v_i is assigned to the same processor as matrix diagonal a_{ii}.
25
// For now, we derive the vector entry assignment by accruing information
26
// about the diagonal entries' assigments during calls to Mine(I,J,V).
27
// A better scheme might read vector entries' assignments from a file as well,
28
// or have a separate discovery of vector entries' assignments in the
29
// constructor.
30
// Assumptions include:
31
// - If diagonal entries are needed (e.g., for a Laplacian), they are
32
// included in the MMFile
33
// - Part assignments are one-based; that is (I,J,V) = (1,1,4) assigns
34
// (I,J) to process 3.
35
// - Mine(I,J) is undefined; value V must be provided.
36
37
public
:
38
using
Distribution<gno_t, scalar_t>::me;
39
using
Distribution<gno_t, scalar_t>::np;
40
using
Distribution<gno_t, scalar_t>::nrows;
41
42
DistributionMMFile(
size_t
nrows_,
43
const
Teuchos::RCP<
const
Teuchos::Comm<int> > &comm_,
44
const
Teuchos::ParameterList ¶ms)
45
: Distribution<gno_t, scalar_t>(nrows_, comm_, params) {
46
if
(me == 0) std::cout <<
"\n MMFile Distribution: "
47
<<
"\n np = "
<< np << std::endl;
48
}
49
50
inline
enum
DistributionType DistType() {
return
MMFile; }
51
52
bool
Mine(gno_t i, gno_t j) {
53
std::cout <<
"Invalid call to Mine(i,j); "
54
<<
"MMFile-distribution requires use of Mine(i,j,p) providing "
55
<<
"process assignment p."
<< std::endl;
56
exit(-1);
57
}
58
59
bool
Mine(gno_t i, gno_t j,
int
oneBasedRank) {
60
// Nonzero (i,j) is Mine if oneBasedRank-1 == me.
61
62
if
(oneBasedRank < 1 || oneBasedRank > np) {
63
std::cout <<
"Invalid rank "
<< oneBasedRank
64
<<
" provided in user distribution; "
65
<<
"rank must be in range 1 to "
<< np << std::endl;
66
exit(-1);
67
}
68
69
// Keep track of diagonal entries that I own for use in vector map
70
if
(oneBasedRank - 1 == me && i == j) myVecEntries.insert(i);
71
72
return
(oneBasedRank - 1 == me);
73
}
74
75
// myVecEntries keeps track of which diagonal matrix entries are Mine().
76
// myVecEntries is not complete until the entire matrix has been viewed
77
// by Mine(), so use of VecMine before that point may produce misleading
78
// results.
79
inline
bool
VecMine(gno_t i) {
80
return
(myVecEntries.find(i) != myVecEntries.end());
81
}
82
83
private
:
84
std::set<gno_t> myVecEntries;
// vector entries that are assigned to me
85
};
86
87
}
// namespace Tpetra
88
#endif
Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Generated by
1.17.0