Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Core Modules
dune-common
Commits
51253c9d
Commit
51253c9d
authored
2 years ago
by
Christian Engwer
Browse files
Options
Downloads
Patches
Plain Diff
[test] add async MPIPack test
parent
4a6c87a1
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1146
Fix async communication of MPIPack
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/common/parallel/test/mpipacktest.cc
+102
-0
102 additions, 0 deletions
dune/common/parallel/test/mpipacktest.cc
with
102 additions
and
0 deletions
dune/common/parallel/test/mpipacktest.cc
+
102
−
0
View file @
51253c9d
...
...
@@ -10,7 +10,9 @@
constexpr
int
TAG
=
42
;
#include
<iostream>
#include
<map>
#include
<dune/common/classname.hh>
#include
<dune/common/parallel/mpihelper.hh>
#include
<dune/common/parallel/mpipack.hh>
#include
<dune/common/test/testsuite.hh>
...
...
@@ -47,6 +49,102 @@ auto testSync(Comm comm)
return
suite
;
}
template
<
typename
Comm
>
auto
testASync
(
Comm
comm
)
{
Dune
::
TestSuite
suite
(
"testASync"
);
int
rank
=
comm
.
rank
();
// we receive from left and right
int
src
=
(
rank
-
1
+
comm
.
size
())
%
comm
.
size
();
int
dest
=
(
rank
+
1
)
%
comm
.
size
();
using
RecvFuture
=
Dune
::
MPIFuture
<
Dune
::
MPIPack
>
;
using
SendFuture
=
Dune
::
MPIFuture
<
Dune
::
MPIPack
>
;
std
::
map
<
int
,
SendFuture
>
sendFutures
;
std
::
map
<
int
,
RecvFuture
>
recvFutures
;
// recv async
{
const
int
reserve
=
100
;
auto
future
=
comm
.
irecv
(
Dune
::
MPIPack
(
comm
,
reserve
),
src
,
TAG
);
// MPIPack is non-copyable, thus we can't use sendFutures[dest] = ...;
recvFutures
.
emplace
(
src
,
std
::
move
(
future
));
// Alternative: sendFutures.insert( std::make_pair(dest, std::move(future)) );
}
// send async
{
Dune
::
MPIPack
pack
(
comm
);
pack
<<
3
<<
comm
.
rank
();
pack
<<
std
::
vector
<
int
>
{
4711
,
42
};
auto
future
=
comm
.
isend
(
std
::
move
(
pack
),
dest
,
TAG
);
// MPIPack is non-copyable, thus we can't use sendFutures[dest] = ...;
sendFutures
.
emplace
(
dest
,
std
::
move
(
future
));
// Alternative: sendFutures.insert( std::make_pair(dest, std::move(future)) );
}
// recv
for
(
auto
&
[
rank
,
future
]
:
recvFutures
)
{
Dune
::
MPIPack
pack
=
future
.
get
();
int
drei
;
pack
>>
drei
;
int
rank_src
;
pack
>>
rank_src
;
std
::
vector
<
int
>
vec
;
pack
>>
vec
;
suite
.
check
(
drei
==
3
)
<<
"received wrong value"
;
suite
.
check
(
rank_src
==
rank
)
<<
"received wrong value"
;
suite
.
check
(
vec
.
size
()
==
2
)
<<
"vector has wrong size!"
;
suite
.
check
(
vec
[
0
]
==
4711
&&
vec
[
1
]
==
42
)
<<
"vector contains wrong values!"
;
}
// wait for send operations to finish
for
(
auto
&
[
rank
,
future
]
:
sendFutures
)
future
.
wait
();
return
suite
;
}
template
<
typename
Comm
>
auto
testASyncVector
(
Comm
comm
)
{
Dune
::
TestSuite
suite
(
"testASync"
);
int
rank
=
comm
.
rank
();
// we receive from left and right
int
src
=
(
rank
-
1
+
comm
.
size
())
%
comm
.
size
();
int
dest
=
(
rank
+
1
)
%
comm
.
size
();
using
RecvFuture
=
Dune
::
MPIFuture
<
std
::
vector
<
int
>>
;
using
SendFuture
=
Dune
::
MPIFuture
<
std
::
vector
<
int
>>
;
SendFuture
sendFuture
;
RecvFuture
recvFuture
;
// recv async
{
const
int
reserve
=
2
;
// size on the receiving side...
recvFuture
=
comm
.
irecv
(
std
::
vector
<
int
>
(
reserve
),
src
,
TAG
+
src
);
}
// send async
{
std
::
vector
<
int
>
vec
{
4711
,
42
};
// we have to keep the vector until send has finished
sendFuture
=
comm
.
isend
(
std
::
move
(
vec
),
dest
,
TAG
+
rank
);
}
// recv
{
std
::
cout
<<
rank
<<
" reading future"
<<
std
::
endl
;
std
::
vector
<
int
>
vec
=
recvFuture
.
get
();
std
::
cout
<<
rank
<<
" done"
<<
std
::
endl
;
suite
.
check
(
vec
.
size
()
==
2
)
<<
"vector has wrong size!"
;
suite
.
check
(
vec
[
0
]
==
4711
&&
vec
[
1
]
==
42
)
<<
"vector contains wrong values!"
;
}
// wait for send to finish
sendFuture
.
wait
();
return
suite
;
}
int
main
(
int
argc
,
char
**
argv
){
Dune
::
MPIHelper
&
helper
=
Dune
::
MPIHelper
::
instance
(
argc
,
argv
);
Dune
::
TestSuite
suite
;
...
...
@@ -54,5 +152,9 @@ int main(int argc, char** argv){
suite
.
subTest
(
testSync
(
comm
));
suite
.
subTest
(
testASyncVector
(
comm
));
suite
.
subTest
(
testASync
(
comm
));
return
suite
.
exit
();
}
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