Skip to content

Commit

Permalink
fixed the issues found during PR-review
Browse files Browse the repository at this point in the history
* properly use MasterRank in MachEnv instead of rank=0
* renamed variable names to match with Clang style
* updated document accordingly
  • Loading branch information
grnydawn committed Nov 17, 2023
1 parent 5e81522 commit 790b716
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 157 deletions.
26 changes: 13 additions & 13 deletions components/omega/doc/design/Broadcast.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function with simplified arguments.

### 4.1 Data types and parameters

For non-blocking broadcasts, we will alias the MPI_request type
For non-blocking broadcasts, we will alias the `MPI_request` type
to a Broadcast ID:

```c++
Expand All @@ -67,15 +67,15 @@ The first form is the simplest for a broadcast within the default
environment and from the master task:

```c++
int Broadcast([data type] value);
int Broadcast([data type] Value);
```
where `[data type]` is one of the supported types (I4, I8 R4, R8, Real,
boolean, std::string). In actual use, this would look like:
```c++
ierr = Broadcast(myIntVar);
ierr = Broadcast(myRealVar);
int Err = Broadcast(MyIntValue);
int Err = Broadcast(MyRealValue);
[etc for all data types]
```

Expand All @@ -88,8 +88,8 @@ This is similar to the above, but adds the additional argument
for the source rank to broadcast from.

```c++
int Broadcast([data type] value, ///< [in] value to be broadcast
const int srcRank ///< [in] rank to broadcast from
int Broadcast([data type] Value, ///< [in] value to be broadcast
const int SrcRank ///< [in] rank to broadcast from
); //
```
Expand All @@ -98,8 +98,8 @@ int Broadcast([data type] value, ///< [in] value to be broadcast
As in 4.2.1, but adds the machine environment as an argument:
```c++
int Broadcast([data type] value, ///< [in] value to be broadcast
const MachEnv *subEnv, ///< [in] defined OMEGA environment
int Broadcast([data type] Value, ///< [in] value to be broadcast
const MachEnv *SubEnv, ///< [in] defined OMEGA environment
);
```

Expand All @@ -108,9 +108,9 @@ int Broadcast([data type] value, ///< [in] value to be broadcast
As in 4.2.2, but adds the machine environment as an argument:

```c++
int Broadcast([data type] value, ///< [in] value to be broadcast
const MachEnv *subEnv, ///< [in] defined OMEGA environment
const int srcRank ///< [in] rank to broadcast from
int Broadcast([data type] Value, ///< [in] value to be broadcast
const MachEnv *SubEnv, ///< [in] defined OMEGA environment
const int SrcRank ///< [in] rank to broadcast from
);
```
Expand All @@ -128,9 +128,9 @@ included to wait for the request to complete. A non-blocking
sequence would look like:
```c++
BroadcastID myReqID = IBroadcast(myVar);
BroadcastID myReqID = IBroadcast(MyVar);
[ perform other tasks/computation ]
int err = IBroadcastWait(myReqID);
int Err = IBroadcastWait(MyReqID);
```

## 5 Verification and Testing
Expand Down
170 changes: 90 additions & 80 deletions components/omega/src/infra/Broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,170 +15,180 @@
namespace OMEGA {

//------------------------------------------------------------------------------
// Broadcast I4 scalar value
int Broadcast(I4 &value, const MachEnv *InEnv, const int rankBcast) {
int retval = 0;
// Broadcast I4 scalar Value
int Broadcast(I4 &Value, const MachEnv *InEnv, const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast(&value, 1, MPI_INT32_T, rankBcast, InEnv->getComm());
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast(&Value, 1, MPI_INT32_T, Root, InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast for I4 data type

int Broadcast(I4 &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(I4 &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
} // end Broadcast for I4 data type

//------------------------------------------------------------------------------
// Broadcast I8 scalar value
int Broadcast(I8 &value, const MachEnv *InEnv, const int rankBcast) {
int retval = 0;
// Broadcast I8 scalar Value
int Broadcast(I8 &Value, const MachEnv *InEnv, const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast(&value, 1, MPI_INT64_T, rankBcast, InEnv->getComm());
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast(&Value, 1, MPI_INT64_T, Root, InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast for I8 data type

int Broadcast(I8 &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(I8 &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
} // end Broadcast for I8 data type

//------------------------------------------------------------------------------
// Broadcast R4 scalar value
int Broadcast(R4 &value, const MachEnv *InEnv, const int rankBcast) {
int retval = 0;
// Broadcast R4 scalar Value
int Broadcast(R4 &Value, const MachEnv *InEnv, const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast(&value, 1, MPI_FLOAT, rankBcast, InEnv->getComm());
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast(&Value, 1, MPI_FLOAT, Root, InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast

int Broadcast(R4 &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(R4 &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
} // end Broadcast

//------------------------------------------------------------------------------
// Broadcast R8 scalar value
int Broadcast(R8 &value, const MachEnv *InEnv, const int rankBcast) {
int retval = 0;
// Broadcast R8 scalar Value
int Broadcast(R8 &Value, const MachEnv *InEnv, const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast(&value, 1, MPI_DOUBLE, rankBcast, InEnv->getComm());
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast(&Value, 1, MPI_DOUBLE, Root, InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast

int Broadcast(R8 &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(R8 &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
} // end Broadcast

//------------------------------------------------------------------------------
// Broadcast bool scalar value
int Broadcast(bool &value, const MachEnv *InEnv, const int rankBcast) {
int retval = 0;
// Broadcast bool scalar Value
int Broadcast(bool &Value, const MachEnv *InEnv, const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast(&value, 1, MPI_C_BOOL, rankBcast, InEnv->getComm());
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast(&Value, 1, MPI_C_BOOL, Root, InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast

int Broadcast(bool &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(bool &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
} // end Broadcast

//------------------------------------------------------------------------------
// Broadcast std::string value
int Broadcast(std::string &value, const MachEnv *InEnv, const int rankBcast) {
int retval = 0;
// Broadcast std::string Value
int Broadcast(std::string &Value, const MachEnv *InEnv, const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast((void *)value.c_str(), value.size(), MPI_CHAR, rankBcast,
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast((void *)Value.c_str(), Value.size(), MPI_CHAR, Root,
InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast

int Broadcast(std::string &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(std::string &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
} // end Broadcast

//------------------------------------------------------------------------------
// Broadcast I4 array
int Broadcast(std::vector<I4> &value, const MachEnv *InEnv,
const int rankBcast) {
int retval = 0;
int Broadcast(std::vector<I4> &Value, const MachEnv *InEnv,
const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast((void *)value.data(), value.size(), MPI_INT32_T,
rankBcast, InEnv->getComm());
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast((void *)Value.data(), Value.size(), MPI_INT32_T, Root,
InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast

int Broadcast(std::vector<I4> &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(std::vector<I4> &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
} // end Broadcast

//------------------------------------------------------------------------------
// Broadcast I8 array
int Broadcast(std::vector<I8> &value, const MachEnv *InEnv,
const int rankBcast) {
int retval = 0;
int Broadcast(std::vector<I8> &Value, const MachEnv *InEnv,
const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast((void *)value.data(), value.size(), MPI_INT64_T,
rankBcast, InEnv->getComm());
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast((void *)Value.data(), Value.size(), MPI_INT64_T, Root,
InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast

int Broadcast(std::vector<I8> &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(std::vector<I8> &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
} // end Broadcast

//------------------------------------------------------------------------------
// Broadcast R4 array
int Broadcast(std::vector<R4> &value, const MachEnv *InEnv,
const int rankBcast) {
int retval = 0;
int Broadcast(std::vector<R4> &Value, const MachEnv *InEnv,
const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast((void *)value.data(), value.size(), MPI_FLOAT, rankBcast,
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast((void *)Value.data(), Value.size(), MPI_FLOAT, Root,
InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast

int Broadcast(std::vector<R4> &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(std::vector<R4> &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
} // end Broadcast

//------------------------------------------------------------------------------
// Broadcast R8 array
int Broadcast(std::vector<R8> &value, const MachEnv *InEnv,
const int rankBcast) {
int retval = 0;
int Broadcast(std::vector<R8> &Value, const MachEnv *InEnv,
const int RankBcast) {
int RetVal, Root;

retval = MPI_Bcast((void *)value.data(), value.size(), MPI_DOUBLE, rankBcast,
Root = (RankBcast < 0) ? InEnv->getMasterTask() : RankBcast;
RetVal = MPI_Bcast((void *)Value.data(), Value.size(), MPI_DOUBLE, Root,
InEnv->getComm());

return retval;
return RetVal;
} // end Broadcast

int Broadcast(std::vector<R8> &value, const int rankBcast) {
return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
int Broadcast(std::vector<R8> &Value, const int RankBcast) {
return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
}

//------------------------------------------------------------------------------
// Broadcast bool array
// Elements of vector<bool> seem to be non-addressable
// int Broadcast(std::vector<bool> &value, const MachEnv *InEnv, const int
// rankBcast ) {
// int retval = 0;
// int Broadcast(std::vector<bool> &Value, const MachEnv *InEnv, const int
// RankBcast ) {
// int RetVal;
//
// retval = MPI_Bcast((void *)value.data(), value.size(), MPI_C_BOOL,
// rankBcast, InEnv->getComm());
// RetVal = MPI_Bcast((void *)Value.data(), Value.size(), MPI_C_BOOL,
// RankBcast, InEnv->getComm());
//
// return retval;
// return RetVal;
//} // end Broadcast
//
// int Broadcast(std::vector<bool> &value, const int rankBcast
// int Broadcast(std::vector<bool> &Value, const int RankBcast
//) {
// return Broadcast(value, MachEnv::getDefaultEnv(), rankBcast);
// return Broadcast(Value, MachEnv::getDefaultEnv(), RankBcast);
//}

} // namespace OMEGA
Loading

0 comments on commit 790b716

Please sign in to comment.