Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ddm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gmsh
ddm
Commits
46e3f050
Commit
46e3f050
authored
1 year ago
by
Boris Martin
Browse files
Options
Downloads
Patches
Plain Diff
Made MPI matrix export possible
parent
a17e3755
No related branches found
No related tags found
1 merge request
!45
Matrix-matrix product, parallel matrix export
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/problem/Formulation.cpp
+71
-27
71 additions, 27 deletions
src/problem/Formulation.cpp
with
71 additions
and
27 deletions
src/problem/Formulation.cpp
+
71
−
27
View file @
46e3f050
...
...
@@ -1123,31 +1123,42 @@ namespace gmshddm
return
time
;
}
// TODO
template
<
class
T_Scalar
>
gmshfem
::
algebra
::
MatrixCCS
<
T_Scalar
>
Formulation
<
T_Scalar
>::
computeMatrix
()
{
const
int
outerVerbosity
=
gmshfem
::
common
::
Options
::
instance
()
->
verbose
;
const
int
innerVerbosity
=
(
outerVerbosity
!=
0
?
outerVerbosity
-
1
:
0
);
if
(
mpi
::
getMPISize
()
!=
1
)
{
throw
gmshfem
::
common
::
Exception
(
"Formulation< T_Scalar >::computeMatrix() does not work on multiple processes"
);
}
Mat
A
;
Vec
X
,
Y
;
Vec
X
,
Y
,
Y_seq
;
VecScatter
ctx
;
VecDuplicate
(
_rhs
.
getPetsc
(),
&
X
);
VecDuplicate
(
_rhs
.
getPetsc
(),
&
Y
);
// Create a distributed vector that acts as a RHS
PetscInt
locSize
=
_rhs
.
size
();
VecCreateMPI
(
MPI_COMM_WORLD
,
locSize
,
PETSC_DETERMINE
,
&
Y
);
VecDuplicate
(
Y
,
&
X
);
MatCreateShell
(
MPI_COMM_SELF
,
_rhs
.
size
(),
_rhs
.
size
(),
_rhs
.
size
(),
_rhs
.
size
(),
this
,
&
A
);
MatShellSetOperation
(
A
,
MATOP_MULT
,
(
void
(
*
)(
void
))
&
MatVectProductA
<
T_Scalar
>
);
// Create a sequential full vector and a scatter object to synchronize the global vector of outputs,
// Needed to build the matrix
PetscInt
globSize
;
VecGetSize
(
Y
,
&
globSize
);
VecCreateSeq
(
MPI_COMM_SELF
,
globSize
,
&
Y_seq
);
VecScatterCreateToAll
(
Y
,
&
ctx
,
&
Y_seq
);
if
(
mpi
::
getMPIRank
()
==
0
)
gmshfem
::
msg
::
info
<<
"Local size:"
<<
locSize
<<
" and global size:"
<<
globSize
<<
"."
<<
gmshfem
::
msg
::
endl
;
// Setup the A matrix
MatCreateShell
(
MPI_COMM_WORLD
,
locSize
,
locSize
,
globSize
,
globSize
,
this
,
&
A
);
MatShellSetOperation
(
A
,
MATOP_MULT
,
(
void
(
*
)(
void
))
&
MatVectProductI_A
<
T_Scalar
>
);
_physicalCommutator
=
false
;
_artificialCommutator
=
true
;
togglePhysicalAndArtificialSourceTerms
();
// Compute sub matrices then disable bilinear terms (to assemble only RHS)
for
(
auto
idom
=
0ULL
;
idom
<
_volume
.
size
();
++
idom
)
{
_volume
[
idom
]
->
setAttribute
(
"ddm::physicalCommutator"
,
_physicalCommutator
);
_volume
[
idom
]
->
setAttribute
(
"ddm::artificialCommutator"
,
_artificialCommutator
);
...
...
@@ -1161,24 +1172,47 @@ namespace gmshddm
}
gmshfem
::
algebra
::
Vector
<
T_Scalar
>
vec
(
_rhs
.
s
ize
()
);
std
::
vector
<
PetscInt
>
aiVector
(
_rhs
.
s
ize
()
);
for
(
auto
i
=
0ULL
;
i
<
_rhs
.
s
ize
()
;
++
i
)
{
gmshfem
::
algebra
::
Vector
<
T_Scalar
>
vec
(
globS
ize
);
std
::
vector
<
PetscInt
>
aiVector
(
globS
ize
);
for
(
auto
i
=
0ULL
;
i
<
globS
ize
;
++
i
)
{
aiVector
[
i
]
=
i
;
}
std
::
vector
<
PetscScalar
>
aVector
(
_rhs
.
s
ize
()
);
std
::
vector
<
PetscScalar
>
aVector
(
globS
ize
);
std
::
vector
<
unsigned
long
long
>
aj
(
_rhs
.
s
ize
()
+
1
,
0
);
std
::
vector
<
unsigned
long
long
>
aj
(
globS
ize
+
1
,
0
);
std
::
vector
<
unsigned
long
long
>
ai
;
ai
.
reserve
(
_rhs
.
s
ize
()
);
ai
.
reserve
(
globS
ize
);
std
::
vector
<
T_Scalar
>
a
;
a
.
reserve
(
_rhs
.
size
());
for
(
auto
i
=
0ULL
;
i
<
_rhs
.
size
();
++
i
)
{
gmshfem
::
msg
::
info
<<
"Column number "
<<
i
<<
" over "
<<
_rhs
.
size
()
<<
"."
<<
gmshfem
::
msg
::
endl
;
vec
[
i
]
=
1.
;
vec
.
removePetsc
();
MatVectProductI_A
<
T_Scalar
>
(
A
,
vec
.
getPetsc
(),
Y
);
VecGetValues
(
Y
,
_rhs
.
size
(),
&
aiVector
[
0
],
&
aVector
[
0
]);
a
.
reserve
(
globSize
);
std
::
vector
<
PetscScalar
>
zeros
(
globSize
,
0
);
// Init RHS vector
VecSet
(
X
,
0.0
);
VecSetValue
(
X
,
0
,
1.0
,
INSERT_VALUES
);
VecAssemblyBegin
(
X
);
VecAssemblyEnd
(
X
);
for
(
auto
i
=
0ULL
;
i
<
globSize
;
++
i
)
{
VecSet
(
X
,
0.0
);
VecSetValue
(
X
,
i
,
1.0
,
INSERT_VALUES
);
VecAssemblyBegin
(
X
);
VecAssemblyEnd
(
X
);
if
(
mpi
::
getMPIRank
()
==
0
)
{
gmshfem
::
msg
::
info
<<
"Column number "
<<
i
<<
" over "
<<
globSize
<<
"."
<<
gmshfem
::
msg
::
endl
;
}
MatMult
(
A
,
X
,
Y
);
// Scatter to rank 0
VecScatterBegin
(
ctx
,
Y
,
Y_seq
,
INSERT_VALUES
,
SCATTER_FORWARD
);
VecScatterEnd
(
ctx
,
Y
,
Y_seq
,
INSERT_VALUES
,
SCATTER_FORWARD
);
VecGetValues
(
Y_seq
,
globSize
,
&
aiVector
[
0
],
&
aVector
[
0
]);
aj
[
i
+
1
]
=
aj
[
i
];
for
(
auto
j
=
0ULL
;
j
<
aVector
.
size
();
++
j
)
{
if
(
aVector
[
j
]
!=
0
)
{
...
...
@@ -1186,16 +1220,26 @@ namespace gmshddm
ai
.
push_back
(
j
);
a
.
push_back
(
T_Scalar
(
aVector
[
j
]));
}
}
ai
.
reserve
(
aj
.
size
()
+
_rhs
.
size
());
a
.
reserve
(
a
.
size
()
+
_rhs
.
size
());
vec
[
i
]
=
0.
;
ai
.
reserve
(
aj
.
size
()
+
globSize
);
a
.
reserve
(
a
.
size
()
+
globSize
);
// Update RHS
VecSetValue
(
X
,
i
,
0.0
,
INSERT_VALUES
);
if
(
i
+
1
<
globSize
)
VecSetValue
(
X
,
i
+
1
,
1.0
,
INSERT_VALUES
);
VecAssemblyBegin
(
X
);
VecAssemblyEnd
(
X
);
}
for
(
auto
idom
=
0ULL
;
idom
<
_volume
.
size
();
++
idom
)
{
_activateBilinear
(
idom
);
}
VecScatterDestroy
(
&
ctx
);
gmshfem
::
algebra
::
MatrixCCS
<
T_Scalar
>
mat
(
std
::
move
(
ai
),
std
::
move
(
aj
),
std
::
move
(
a
));
return
mat
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment