Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dumux-repositories
dumux
Commits
9174b273
Commit
9174b273
authored
May 24, 2020
by
Timo Koch
Browse files
[linear] Simplify initialization of parallel helper
parent
00dfe132
Changes
3
Hide whitespace changes
Inline
Side-by-side
dumux/linear/amgbackend.hh
View file @
9174b273
...
...
@@ -60,8 +60,6 @@ public:
{
if
(
isParallel_
)
DUNE_THROW
(
Dune
::
InvalidStateException
,
"Using sequential constructor for parallel run. Use signature with gridView and dofMapper!"
);
reset
();
}
/*!
...
...
@@ -76,11 +74,13 @@ public:
const
std
::
string
&
paramGroup
=
""
)
:
LinearSolver
(
paramGroup
)
#if HAVE_MPI
,
phelper_
(
std
::
make_unique
<
ParallelISTLHelper
<
LinearSolverTraits
>>
(
gridView
,
dofMapper
))
,
isParallel_
(
Dune
::
MPIHelper
::
getCollectiveCommunication
().
size
()
>
1
)
#endif
{
reset
();
#if HAVE_MPI
if
(
isParallel_
)
phelper_
=
std
::
make_unique
<
ParallelISTLHelper
<
LinearSolverTraits
>>
(
gridView
,
dofMapper
);
#endif
}
/*!
...
...
@@ -98,16 +98,9 @@ public:
#else
solveSequential_
(
A
,
x
,
b
);
#endif
firstCall_
=
false
;
return
result_
.
converged
;
}
//! reset the linear solver
void
reset
()
{
firstCall_
=
true
;
}
/*!
* \brief The name of the solver
*/
...
...
@@ -161,9 +154,6 @@ private:
using
LinearOperator
=
typename
ParallelTraits
::
LinearOperator
;
using
ScalarProduct
=
typename
ParallelTraits
::
ScalarProduct
;
if
(
firstCall_
)
phelper_
->
initGhostsAndOwners
();
std
::
shared_ptr
<
Comm
>
comm
;
std
::
shared_ptr
<
LinearOperator
>
linearOperator
;
std
::
shared_ptr
<
ScalarProduct
>
scalarProduct
;
...
...
@@ -224,7 +214,6 @@ private:
#endif
Dune
::
InverseOperatorResult
result_
;
bool
isParallel_
=
false
;
bool
firstCall_
;
};
}
// end namespace Dumux
...
...
dumux/linear/istlsolverfactorybackend.hh
View file @
9174b273
...
...
@@ -131,7 +131,8 @@ public:
if
(
isParallel_
)
DUNE_THROW
(
Dune
::
InvalidStateException
,
"Using sequential constructor for parallel run. Use signature with gridView and dofMapper!"
);
reset
();
firstCall_
=
true
;
initializeParameters_
();
}
/*!
...
...
@@ -146,11 +147,15 @@ public:
const
std
::
string
&
paramGroup
=
""
)
:
paramGroup_
(
paramGroup
)
#if HAVE_MPI
,
parallelHelper_
(
std
::
make_unique
<
ParallelISTLHelper
<
LinearSolverTraits
>>
(
gridView
,
dofMapper
))
,
isParallel_
(
Dune
::
MPIHelper
::
getCollectiveCommunication
().
size
()
>
1
)
#endif
{
reset
();
firstCall_
=
true
;
initializeParameters_
();
#if HAVE_MPI
if
(
isParallel_
)
parallelHelper_
=
std
::
make_unique
<
ParallelISTLHelper
<
LinearSolverTraits
>>
(
gridView
,
dofMapper
);
#endif
}
/*!
...
...
@@ -172,17 +177,6 @@ public:
return
result_
.
converged
;
}
//! reset the linear solver factory
void
reset
()
{
firstCall_
=
true
;
params_
=
LinearSolverParameters
<
LinearSolverTraits
>::
createParameterTree
(
paramGroup_
);
checkMandatoryParameters_
();
name_
=
params_
.
get
<
std
::
string
>
(
"preconditioner.type"
)
+
"-preconditioned "
+
params_
.
get
<
std
::
string
>
(
"type"
);
if
(
params_
.
get
<
int
>
(
"verbose"
,
0
)
>
0
)
std
::
cout
<<
"Initialized linear solver of type: "
<<
name_
<<
std
::
endl
;
}
const
Dune
::
InverseOperatorResult
&
result
()
const
{
return
result_
;
...
...
@@ -195,6 +189,15 @@ public:
private:
void
initializeParameters_
()
{
params_
=
LinearSolverParameters
<
LinearSolverTraits
>::
createParameterTree
(
paramGroup_
);
checkMandatoryParameters_
();
name_
=
params_
.
get
<
std
::
string
>
(
"preconditioner.type"
)
+
"-preconditioned "
+
params_
.
get
<
std
::
string
>
(
"type"
);
if
(
params_
.
get
<
int
>
(
"verbose"
,
0
)
>
0
)
std
::
cout
<<
"Initialized linear solver of type: "
<<
name_
<<
std
::
endl
;
}
void
checkMandatoryParameters_
()
{
if
(
!
params_
.
hasKey
(
"type"
))
...
...
@@ -244,10 +247,7 @@ private:
using
ScalarProduct
=
typename
ParallelTraits
::
ScalarProduct
;
if
(
firstCall_
)
{
initSolverFactories
<
Matrix
,
LinearOperator
>
();
parallelHelper_
->
initGhostsAndOwners
();
}
std
::
shared_ptr
<
Comm
>
comm
;
std
::
shared_ptr
<
LinearOperator
>
linearOperator
;
...
...
dumux/linear/parallelhelpers.hh
View file @
9174b273
...
...
@@ -276,15 +276,17 @@ class ParallelISTLHelper
public:
ParallelISTLHelper
(
const
GridView
&
gridView
,
const
DofMapper
&
mapper
)
:
gridView_
(
gridView
),
mapper_
(
mapper
),
initialized_
(
false
)
{}
:
gridView_
(
gridView
),
mapper_
(
mapper
)
{
initGhostsAndOwners
();
}
// \brief Initializes the markers for ghosts and owners with the correct size and values.
//
void
initGhostsAndOwners
()
{
const
auto
rank
=
gridView_
.
comm
().
rank
();
isOwned_
.
resize
(
mapper_
.
size
(),
rank
);
isOwned_
.
assign
(
mapper_
.
size
(),
rank
);
// find out about ghosts
GhostGatherScatter
ggs
(
isOwned_
,
mapper_
);
...
...
@@ -302,8 +304,6 @@ public:
// convert vector into mask vector
for
(
auto
&
v
:
isOwned_
)
v
=
(
v
==
rank
)
?
1
:
0
;
initialized_
=
true
;
}
bool
isGhost
(
std
::
size_t
i
)
const
...
...
@@ -316,16 +316,8 @@ public:
* communicators.
*/
template
<
class
Comm
>
void
createParallelIndexSet
(
Comm
&
comm
)
void
createParallelIndexSet
(
Comm
&
comm
)
const
{
if
(
!
initialized_
)
{
// This is the first time this function is called.
// Therefore we need to initialize the marker vectors for ghosts and
// owned dofs
initGhostsAndOwners
();
}
if
(
gridView_
.
comm
().
size
()
<=
1
)
{
comm
.
remoteIndices
().
template
rebuild
<
false
>();
...
...
@@ -423,7 +415,6 @@ private:
const
DofMapper
&
mapper_
;
//!< the dof mapper
std
::
vector
<
std
::
size_t
>
isOwned_
;
//!< vector to identify unique decomposition
std
::
vector
<
std
::
size_t
>
isGhost_
;
//!< vector to identify ghost dofs
bool
initialized_
;
//!< whether isGhost and owner arrays are initialized
};
// class ParallelISTLHelper
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment