mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-11 16:49:16 +05:00
Merge branch 'array_sendrecv_to_netgen' into 'master'
move array-send and recv to ngcore (needs array-ptr) See merge request jschoeberl/netgen!214
This commit is contained in:
commit
76ab713a80
@ -6,6 +6,7 @@
|
|||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "array.hpp"
|
||||||
#include "exception.hpp"
|
#include "exception.hpp"
|
||||||
|
|
||||||
namespace ngcore
|
namespace ngcore
|
||||||
@ -127,11 +128,32 @@ namespace ngcore
|
|||||||
MPI_Send (&val, 1, GetMPIType<T>(), dest, tag, comm);
|
MPI_Send (&val, 1, GetMPIType<T>(), dest, tag, comm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename T2 = decltype(GetMPIType<T>())>
|
||||||
|
void Send(FlatArray<T> s, int dest, int tag) const {
|
||||||
|
MPI_Send (s.Data(), s.Size(), GetMPIType<T>(), dest, tag, comm);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, typename T2 = decltype(GetMPIType<T>())>
|
template<typename T, typename T2 = decltype(GetMPIType<T>())>
|
||||||
void Recv (T & val, int src, int tag) const {
|
void Recv (T & val, int src, int tag) const {
|
||||||
MPI_Recv (&val, 1, GetMPIType<T>(), src, tag, comm, MPI_STATUS_IGNORE);
|
MPI_Recv (&val, 1, GetMPIType<T>(), src, tag, comm, MPI_STATUS_IGNORE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, typename T2 = decltype(GetMPIType<T>())>
|
||||||
|
void Recv (FlatArray <T> s, int src, int tag) const {
|
||||||
|
MPI_Recv (s.Data(), s.Size(), GetMPIType<T> (), src, tag, comm, MPI_STATUS_IGNORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename T2 = decltype(GetMPIType<T>())>
|
||||||
|
void Recv (Array <T> & s, int src, int tag) const
|
||||||
|
{
|
||||||
|
MPI_Status status;
|
||||||
|
int len;
|
||||||
|
const MPI_Datatype MPI_T = GetMPIType<T> ();
|
||||||
|
MPI_Probe (src, tag, comm, &status);
|
||||||
|
MPI_Get_count (&status, MPI_T, &len);
|
||||||
|
s.SetSize (len);
|
||||||
|
MPI_Recv (s.Data(), len, MPI_T, src, tag, comm, MPI_STATUS_IGNORE);
|
||||||
|
}
|
||||||
|
|
||||||
/** --- non-blocking P2P --- **/
|
/** --- non-blocking P2P --- **/
|
||||||
|
|
||||||
@ -144,13 +166,22 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename T2 = decltype(GetMPIType<T>())>
|
template<typename T, typename T2 = decltype(GetMPIType<T>())>
|
||||||
MPI_Request IRecv (T & val, int dest, int tag) const
|
MPI_Request IRecv (T & val, int src, int tag) const
|
||||||
{
|
{
|
||||||
MPI_Request request;
|
MPI_Request request;
|
||||||
MPI_Irecv (&val, 1, GetMPIType<T>(), dest, tag, comm, &request);
|
MPI_Irecv (&val, 1, GetMPIType<T>(), src, tag, comm, &request);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, typename T2 = decltype(GetMPIType<T>())>
|
||||||
|
MPI_Request IRecv (const FlatArray<T> & s, int src, int tag) const
|
||||||
|
{
|
||||||
|
MPI_Request request;
|
||||||
|
MPI_Irecv (s.Data(), s.Size(), GetMPIType<T>(), src, tag, comm, &request);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** --- collectives --- **/
|
/** --- collectives --- **/
|
||||||
|
|
||||||
template <typename T, typename T2 = decltype(GetMPIType<T>())>
|
template <typename T, typename T2 = decltype(GetMPIType<T>())>
|
||||||
@ -188,10 +219,21 @@ namespace ngcore
|
|||||||
MPI_Bcast (&s[0], len, MPI_CHAR, root, comm);
|
MPI_Bcast (&s[0], len, MPI_CHAR, root, comm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}; // class NgMPI_Comm
|
||||||
};
|
|
||||||
|
|
||||||
|
NETGEN_INLINE void MyMPI_WaitAll (FlatArray<MPI_Request> requests)
|
||||||
|
{
|
||||||
|
if (!requests.Size()) return;
|
||||||
|
MPI_Waitall (requests.Size(), requests.Data(), MPI_STATUSES_IGNORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
NETGEN_INLINE int MyMPI_WaitAny (FlatArray<MPI_Request> requests)
|
||||||
|
{
|
||||||
|
int nr;
|
||||||
|
MPI_Waitany (requests.Size(), requests.Data(), &nr, MPI_STATUS_IGNORE);
|
||||||
|
return nr;
|
||||||
|
}
|
||||||
|
|
||||||
#else // PARALLEL
|
#else // PARALLEL
|
||||||
class MPI_Comm {
|
class MPI_Comm {
|
||||||
int nr;
|
int nr;
|
||||||
@ -223,24 +265,44 @@ namespace ngcore
|
|||||||
void Send( T & val, int dest, int tag) const { ; }
|
void Send( T & val, int dest, int tag) const { ; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void MyMPI_Recv (T & val, int src, int tag) const { ; }
|
void Send(FlatArray<T> s, int dest, int tag) const { ; }
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void Recv (T & val, int src, int tag) const { ; }
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void Recv (FlatArray <T> s, int src, int tag) const { ; }
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void Recv (Array <T> & s, int src, int tag) const { ; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MPI_Request ISend (T & val, int dest, int tag) const { return 0; }
|
MPI_Request ISend (T & val, int dest, int tag) const { return 0; }
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
MPI_Request ISend (const FlatArray<T> & s, int dest, int tag) const { return 0; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
MPI_Request IRecv (T & val, int dest, int tag) const { return 0; }
|
MPI_Request IRecv (T & val, int dest, int tag) const { return 0; }
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
MPI_Request IRecv (const FlatArray<T> & s, int src, int tag) const { return 0; }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T Reduce (T d, const MPI_Op & op, int root = 0) { return d; }
|
T Reduce (T d, const MPI_Op & op, int root = 0) const { return d; }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T AllReduce (T d, const MPI_Op & op) const { return d; }
|
T AllReduce (T d, const MPI_Op & op) const { return d; }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Bcast (T & s, int root = 0) const { ; }
|
void Bcast (T & s, int root = 0) const { ; }
|
||||||
|
|
||||||
|
NgMPI_Comm SubCommunicator (FlatArray<int> procs) const
|
||||||
|
{ return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NETGEN_INLINE void MyMPI_WaitAll (FlatArray<MPI_Request> requests) { ; }
|
||||||
|
|
||||||
#endif // PARALLEL
|
#endif // PARALLEL
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user