Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
67f83665
Commit
67f83665
authored
6 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Write broadcast of any trivial type values
Remind that TinyVector, TinyMatrix, CellType,... are trivial types
parent
f8b39f8a
No related branches found
No related tags found
1 merge request
!11
Feature/mpi
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils/Messenger.cpp
+0
-9
0 additions, 9 deletions
src/utils/Messenger.cpp
src/utils/Messenger.hpp
+35
-6
35 additions, 6 deletions
src/utils/Messenger.hpp
with
35 additions
and
15 deletions
src/utils/Messenger.cpp
+
0
−
9
View file @
67f83665
...
...
@@ -66,12 +66,3 @@ _allGather(int& data) const
return
gather
;
}
int
Messenger
::
_broadcast_value
(
int
&
data
,
int
root_rank
)
const
{
#ifdef PASTIS_HAS_MPI
MPI_Bcast
(
&
data
,
1
,
MPI_INT
,
root_rank
,
MPI_COMM_WORLD
);
#endif // PASTIS_HAS_MPI
return
data
;
}
This diff is collapsed.
Click to expand it.
src/utils/Messenger.hpp
+
35
−
6
View file @
67f83665
...
...
@@ -84,13 +84,26 @@ class Messenger
Array
<
int
>
_allGather
(
int
&
data
)
const
;
int
_broadcast_value
(
int
&
data
,
int
root_rank
)
const
;
template
<
typename
DataType
>
void
_broadcast_value
(
DataType
&
data
,
int
root_rank
)
const
{
#ifdef PASTIS_HAS_MPI
static_assert
(
not
std
::
is_const_v
<
DataType
>
);
static_assert
(
std
::
is_arithmetic_v
<
DataType
>
);
MPI_Datatype
mpi_datatype
=
Messenger
::
helper
::
mpiType
<
DataType
>
();
MPI_Bcast
(
&
data
,
1
,
mpi_datatype
,
root_rank
,
MPI_COMM_WORLD
);
#endif // PASTIS_HAS_MPI
}
template
<
typename
ArrayType
>
void
_broadcast_array
(
ArrayType
&
array
,
int
root_rank
)
const
{
using
DataType
=
typename
ArrayType
::
data_type
;
static_assert
(
not
std
::
is_const_v
<
DataType
>
);
static_assert
(
std
::
is_arithmetic_v
<
DataType
>
);
#ifdef PASTIS_HAS_MPI
MPI_Datatype
mpi_datatype
...
...
@@ -260,10 +273,26 @@ class Messenger
PASTIS_INLINE
void
broadcast
(
DataType
&
data
,
int
root_rank
)
const
{
if
constexpr
(
std
::
is_same
<
DataType
,
int
>
())
{
return
_broadcast_value
(
data
,
root_rank
);
static_assert
(
not
std
::
is_const_v
<
DataType
>
,
"cannot broadcast const data"
);
if
constexpr
(
std
::
is_arithmetic_v
<
DataType
>
)
{
_broadcast_value
(
data
,
root_rank
);
}
else
if
constexpr
(
std
::
is_trivial_v
<
DataType
>
)
{
using
CastType
=
helper
::
split_cast_t
<
DataType
>
;
if
constexpr
(
sizeof
(
CastType
)
==
sizeof
(
DataType
))
{
CastType
&
cast_data
=
reinterpret_cast
<
CastType
&>
(
data
);
_broadcast_value
(
cast_data
,
root_rank
);
}
else
{
static_assert
(
std
::
is_same
<
DataType
,
int
>
(),
"unexpected type of data"
);
#ifdef PASTIS_HAS_MPI
MPI_Datatype
mpi_datatype
=
Messenger
::
helper
::
mpiType
<
CastType
>
();
MPI_Bcast
(
reinterpret_cast
<
CastType
*>
(
&
data
),
sizeof
(
DataType
)
/
sizeof
(
CastType
),
mpi_datatype
,
root_rank
,
MPI_COMM_WORLD
);
#endif // PASTIS_HAS_MPI
}
}
else
{
static_assert
(
std
::
is_trivial_v
<
DataType
>
,
"unexpected non trivial type of data"
);
}
}
...
...
@@ -351,9 +380,9 @@ void barrier()
template
<
typename
DataType
>
PASTIS_INLINE
DataType
broadcast
(
const
DataType
&
data
,
int
root_rank
)
void
broadcast
(
DataType
&
data
,
int
root_rank
)
{
return
messenger
().
broadcast
(
data
,
root_rank
);
messenger
().
broadcast
(
data
,
root_rank
);
}
template
<
typename
DataType
>
...
...
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