Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90967668
comm_group.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Nov 6, 12:06
Size
4 KB
Mime Type
text/x-c
Expires
Fri, Nov 8, 12:06 (2 d)
Engine
blob
Format
Raw Data
Handle
22169199
Attached To
rLIBMULTISCALE LibMultiScale
comm_group.hh
View Options
#ifndef __LIBMULTISCALE_COMM_GROUP_HH__
#define __LIBMULTISCALE_COMM_GROUP_HH__
/* -------------------------------------------------------------------------- */
#include "lm_common.hh"
#include "lm_object.hh"
/* -------------------------------------------------------------------------- */
#include <memory>
#include <mpi.h>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
struct
MPIProc
{
MPIProc
()
:
sequence_number
(
0
)
{}
UInt
getAbsoluteRank
()
{
return
absolute_mpi_rank
;
};
UInt
id
;
UInt
mpi_rank
;
UInt
sequence_number
;
UInt
absolute_mpi_rank
;
};
struct
CommGroup
:
public
LMObject
{
inline
CommGroup
(
const
LMID
&
id
,
int
color
,
UInt
nb_procs
);
bool
operator
==
(
CommGroup
&
grp
)
{
return
(
grp
.
getID
()
==
this
->
getID
());
}
bool
operator
!=
(
CommGroup
&
grp
)
{
return
!
(
grp
==
*
this
);
}
auto
getMPIComm
()
{
return
mpi_comm
;
};
UInt
getMyRank
()
const
{
if
(
mpi_comm
==
MPI_COMM_NULL
)
LM_FATAL
(
"No member of the group: this call should be secured"
);
int
rank_in_group
;
MPI_Comm_rank
(
mpi_comm
,
&
rank_in_group
);
return
rank_in_group
;
}
// UInt real2GroupRank(UInt real_rank);
const
LMID
&
getID
()
const
override
{
auto
&
id
=
LMObject
::
getID
();
if
(
id
==
"invalid"
)
LM_FATAL
(
"Communication group is invalid"
);
return
id
;
};
template
<
typename
BufType
>
void
allReduce
(
BufType
&&
contrib
,
const
std
::
string
&
comment
,
Operator
op
);
template
<
typename
T
>
void
allReduce
(
T
*
contrib
,
UInt
nb
,
const
std
::
string
&
comment
,
Operator
op
);
template
<
typename
BufType
>
void
reduce
(
BufType
&&
contrib
,
const
std
::
string
&
comment
,
Operator
op
,
UInt
root_rank
=
0
);
template
<
typename
T
>
void
reduce
(
T
*
contrib
,
UInt
nb
,
const
std
::
string
&
comment
,
Operator
op
,
UInt
root_rank
=
0
);
template
<
typename
T
>
void
send
(
T
*
d
,
UInt
nb
,
UInt
to
,
const
std
::
string
&
comment
);
template
<
typename
T
>
inline
void
receive
(
T
*
d
,
UInt
nb
,
UInt
from
,
const
std
::
string
&
comment
);
template
<
typename
BufType
>
inline
void
broadcast
(
BufType
&&
buf
,
UInt
root
,
const
std
::
string
&
comment
);
template
<
typename
T
>
inline
void
broadcast
(
T
*
buf
,
UInt
nb
,
UInt
root
,
const
std
::
string
&
comment
);
template
<
typename
T
>
inline
void
gather
(
T
*
sendbuf
,
UInt
nb
,
T
*
recvbuf
,
UInt
to
,
const
std
::
string
&
comment
);
template
<
typename
BufType
>
inline
void
gather
(
BufType
&&
sendbuf
,
BufType
&&
recvbuf
,
UInt
to
,
const
std
::
string
&
comment
);
template
<
typename
T
>
inline
void
scatter
(
T
*
sendbuf
,
T
*
recvbuf
,
UInt
nb_recv
,
UInt
root
,
const
std
::
string
&
comment
);
template
<
typename
BufType
>
inline
void
scatter
(
BufType
&&
sendbuf
,
BufType
&&
recvbuf
,
UInt
root
,
const
std
::
string
&
comment
);
template
<
typename
T
>
inline
void
allGatherv
(
T
*
send_buffer
,
UInt
send_nb
,
T
*
recv_buffer
,
std
::
vector
<
UInt
>
&
recv_counts
,
const
std
::
string
&
comment
);
template
<
typename
BufType
>
inline
void
allGatherv
(
BufType
&&
send_buffer
,
BufType
&&
recv_buffer
,
std
::
vector
<
UInt
>
&
recv_counts
,
const
std
::
string
&
comment
);
template
<
typename
T
>
inline
void
allGather
(
T
*
send_buffer
,
UInt
nb
,
T
*
recv_buffer
,
const
std
::
string
&
comment
);
template
<
typename
BufType
>
inline
void
allGather
(
BufType
&&
send_buffer
,
BufType
&&
recv_buffer
,
const
std
::
string
&
comment
);
auto
size
()
const
{
return
processors
.
size
();
};
auto
begin
()
{
return
processors
.
begin
();
};
auto
end
()
{
return
processors
.
end
();
};
auto
&
operator
[](
UInt
i
)
{
return
processors
[
i
];
}
inline
bool
isInGroup
(
UInt
mpi_rank
)
const
;
bool
amIinGroup
()
{
return
is_current_proc_in_group
;
};
void
synchronize
()
{
MPI_Barrier
(
mpi_comm
);
};
void
printself
(
std
::
ostream
&
os
)
const
;
template
<
typename
Vec
>
inline
void
send
(
Vec
&&
d
,
UInt
to
,
const
std
::
string
&
comment
);
template
<
typename
Vec
>
inline
void
receive
(
Vec
&&
d
,
UInt
from
,
const
std
::
string
&
comment
);
template
<
typename
T
>
inline
auto
probe
(
UInt
from
,
const
std
::
string
&
comment
);
protected
:
//! the intra communicator of the group
MPI_Comm
mpi_comm
;
//! the mpi group
MPI_Group
mpi_group
;
//! vector of processors
std
::
vector
<
MPIProc
>
processors
;
//! stores the color used at creation of the communicator
bool
is_current_proc_in_group
;
};
/* -------------------------------------------------------------------------- */
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
CommGroup
&
group
)
{
group
.
printself
(
os
);
return
os
;
}
/* -------------------------------------------------------------------------- */
struct
SelfGroup
:
public
CommGroup
{
inline
SelfGroup
();
};
__END_LIBMULTISCALE__
#endif
//__LIBMULTISCALE_COMM_GROUP_HH__
Event Timeline
Log In to Comment