Commit 25364757 authored by Michael Bareford's avatar Michael Bareford

Added reduce routine

parent d81f3380
......@@ -97,6 +97,7 @@ public:
template <class T>
void SendRecvReplace(int pSendProc, int pRecvProc, T &pData);
template <class T> void Reduce(T &pSendData, T &pRecvData, enum ReduceOperator pOp, int root);
template <class T> void AllReduce(T &pData, enum ReduceOperator pOp);
template <class T> void AlltoAll(T &pSendData, T &pRecvData);
......@@ -155,6 +156,8 @@ protected:
CommDataType recvtype, int source) = 0;
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt,
int pSendProc, int pRecvProc) = 0;
virtual void v_Reduce(void *sendbuf, void *recvbuf, int count, CommDataType dt,
enum ReduceOperator pOp, int root) = 0;
virtual void v_AllReduce(void *buf, int count, CommDataType dt,
enum ReduceOperator pOp) = 0;
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
......@@ -280,6 +283,17 @@ void Comm::SendRecvReplace(int pSendProc, int pRecvProc, T &pData)
pRecvProc);
}
/**
*
*/
template <class T> void Comm::Reduce(T &pSendData, T &pRecvData, enum ReduceOperator pOp, int root)
{
v_Reduce(CommDataTypeTraits<T>::GetPointer(pSendData),
CommDataTypeTraits<T>::GetPointer(pRecvData),
CommDataTypeTraits<T>::GetCount(pSendData),
CommDataTypeTraits<T>::GetDataType(), pOp, root);
}
/**
*
*/
......
......@@ -216,6 +216,36 @@ void CommMpi::v_SendRecvReplace(void *buf, int count, CommDataType dt,
"MPI error performing Send-Receive-Replace of data.");
}
/**
*
*/
void CommMpi::v_Reduce(void *sendbuf, void *recvbuf, int count, CommDataType dt,
enum ReduceOperator pOp, int root)
{
if (GetSize() == 1)
{
return;
}
MPI_Op vOp;
switch (pOp)
{
case ReduceMax:
vOp = MPI_MAX;
break;
case ReduceMin:
vOp = MPI_MIN;
break;
case ReduceSum:
default:
vOp = MPI_SUM;
break;
}
int retval = MPI_Reduce(sendbuf, recvbuf, count, dt, vOp, root, m_comm);
ASSERTL0(retval == MPI_SUCCESS, "MPI error performing Reduce.");
}
/**
*
*/
......
......@@ -97,6 +97,8 @@ protected:
CommDataType recvtype, int source);
virtual void v_SendRecvReplace(void *buf, int count, CommDataType dt,
int pSendProc, int pRecvProc);
virtual void v_Reduce(void *sendbuf, void *recvbuf, int count, CommDataType dt,
enum ReduceOperator pOp, int root);
virtual void v_AllReduce(void *buf, int count, CommDataType dt,
enum ReduceOperator pOp);
virtual void v_AlltoAll(void *sendbuf, int sendcount, CommDataType sendtype,
......
......@@ -131,6 +131,14 @@ void CommSerial::v_SendRecvReplace(void *buf, int count, CommDataType dt,
{
}
/**
*
*/
void CommSerial::v_Reduce(void *sendbuf, void *recvbuf, int count, CommDataType dt,
enum ReduceOperator pOp, int root)
{
}
/**
*
*/
......
......@@ -85,6 +85,10 @@ protected:
CommDataType dt,
int pSendProc,
int pRecvProc);
LIB_UTILITIES_EXPORT virtual void v_Reduce(void *sendbuf, void *recvbuf, int count,
CommDataType dt,
enum ReduceOperator pOp,
int root);
LIB_UTILITIES_EXPORT virtual void v_AllReduce(void *buf, int count,
CommDataType dt,
enum ReduceOperator pOp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment