Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Chaofan Chen
ogs
Commits
8411edf4
Commit
8411edf4
authored
4 months ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
[BL/MPI] allgatherv for variable size data exchg
parent
4ee86862
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
BaseLib/MPI.h
+28
-0
28 additions, 0 deletions
BaseLib/MPI.h
with
28 additions
and
0 deletions
BaseLib/MPI.h
+
28
−
0
View file @
8411edf4
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include
<algorithm>
#include
<algorithm>
#include
"Algorithm.h"
#include
"Error.h"
#include
"Error.h"
#ifdef USE_PETSC
#ifdef USE_PETSC
...
@@ -136,6 +137,33 @@ static void allreduceInplace(std::vector<T>& vector,
...
@@ -136,6 +137,33 @@ static void allreduceInplace(std::vector<T>& vector,
mpi_op
,
mpi_op
,
mpi
.
communicator
);
mpi
.
communicator
);
}
}
/// Allgather for variable data. Returns offsets in the receive buffer.
/// The receive buffer is resized to accommodate the gathered data.
template
<
typename
T
>
static
std
::
vector
<
int
>
allgatherv
(
std
::
span
<
T
>
const
send_buffer
,
std
::
vector
<
std
::
remove_const_t
<
T
>>&
receive_buffer
,
Mpi
const
&
mpi
)
{
// Determine the number of elements to send
int
const
size
=
static_cast
<
int
>
(
send_buffer
.
size
());
// Gather sizes from all ranks
std
::
vector
<
int
>
const
sizes
=
allgather
(
size
,
mpi
);
// Compute offsets based on counts
std
::
vector
<
int
>
const
offsets
=
BaseLib
::
sizesToOffsets
(
sizes
);
// Resize receive buffer to hold all gathered data
receive_buffer
.
resize
(
offsets
.
back
());
MPI_Allgatherv
(
send_buffer
.
data
(),
size
,
mpiType
<
T
>
(),
receive_buffer
.
data
(),
sizes
.
data
(),
offsets
.
data
(),
mpiType
<
T
>
(),
mpi
.
communicator
);
return
offsets
;
}
#endif
#endif
/// The reduction is implemented transparently for with and without MPI. In the
/// The reduction is implemented transparently for with and without MPI. In the
...
...
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