Skip to content

Commit 8b00c2d

Browse files
author
Erik
committed
Adapated also functions that are not necessary for GoL
1 parent 96e3f58 commit 8b00c2d

File tree

1 file changed

+49
-219
lines changed

1 file changed

+49
-219
lines changed

include/BMPI.hpp

Lines changed: 49 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -20,85 +20,6 @@ namespace mpi = boost::mpi;
2020

2121
namespace graybat {
2222

23-
/**
24-
* @brief Construction of MPI_Op from binary operation *Op* with type *T*
25-
*
26-
* @todo is it possible to get rid of this static shit ?
27-
*/
28-
// template<typename T, typename Op>
29-
// class UserOperation
30-
// {
31-
// public:
32-
// explicit UserOperation(Op& op){
33-
// bool isCommutative = true;
34-
// MPI_Op_create(&UserOperation<T, Op>::perform, isCommutative, &_mpiOp);
35-
// _op = &op;
36-
// }
37-
38-
// ~UserOperation(){
39-
// MPI_Op_free(&_mpiOp);
40-
// }
41-
42-
// MPI_Op& getMpiOp(){
43-
// return _mpiOp;
44-
// }
45-
46-
// static void perform(void* vinvec, void* voutvec, int* plen, MPI_Datatype*)
47-
// {
48-
// T* invec = static_cast<T*>(vinvec);
49-
// T* outvec = static_cast<T*>(voutvec);
50-
// std::transform(invec, invec + *plen, outvec, outvec, *_op);
51-
// }
52-
53-
// private:
54-
// MPI_Op _mpiOp;
55-
// static Op* _op;
56-
57-
// };
58-
59-
// template<typename T, typename Op> Op* UserOperation<T, Op>::_op = 0;
60-
61-
/**
62-
* @brief Type traits for transformation of primitive
63-
* C++ data types to MPI data types.
64-
*
65-
*/
66-
// template<typename T>
67-
// struct MPIDatatypes{
68-
// static constexpr MPI_Datatype type = MPI_CHAR;
69-
// };
70-
71-
// template<>
72-
// struct MPIDatatypes<float>{
73-
// static constexpr MPI_Datatype type = MPI_FLOAT;
74-
// };
75-
76-
// template<>
77-
// struct MPIDatatypes<double>{
78-
// static constexpr MPI_Datatype type = MPI_DOUBLE;
79-
// };
80-
81-
// template<>
82-
// struct MPIDatatypes<int>{
83-
// static constexpr MPI_Datatype type = MPI_INT;
84-
// };
85-
86-
// template<>
87-
// struct MPIDatatypes<unsigned>{
88-
// static constexpr MPI_Datatype type = MPI_UNSIGNED;
89-
// };
90-
91-
// template<>
92-
// struct MPIDatatypes<const char>{
93-
// static constexpr MPI_Datatype type = MPI_CHAR;
94-
// };
95-
96-
// template<>
97-
// struct MPIDatatypes<const bool>{
98-
// static constexpr MPI_Datatype type = MPI_CHAR;
99-
// };
100-
101-
10223
namespace communicationPolicy {
10324

10425
/************************************************************************//**
@@ -214,8 +135,6 @@ namespace graybat {
214135
mpi::request request;
215136
};
216137

217-
218-
219138

220139
// Type defs
221140
typedef unsigned Tag;
@@ -274,11 +193,8 @@ namespace graybat {
274193
* @return Event
275194
*/
276195
template <typename T_Send>
277-
Event asyncSend(const VAddr destVAddr, const Tag tag, const Context context, const T_Send& sendData){
278-
Uri destUri = getVAddrUri(context, destVAddr);
279-
196+
Event asyncSend(const VAddr destVAddr, const Tag tag, const Context context, const T_Send& sendData){ Uri destUri = getVAddrUri(context, destVAddr);
280197
mpi::request request = context.comm.isend(destUri, tag, sendData.data(), sendData.size());
281-
282198
return Event(request);
283199

284200
}
@@ -296,12 +212,11 @@ namespace graybat {
296212
* return the amount of data elements to send. Notice, that
297213
* std::vector and std::array implement this interface.
298214
*/
299-
// template <typename T_Send>
300-
// void send(const VAddr destVAddr, const Tag tag, const Context context, const T_Send& sendData){
301-
// Uri destUri = getVAddrUri(context, destVAddr);
302-
// MPI_Send(const_cast<typename T_Send::value_type*>(sendData.data()), sendData.size(),
303-
// MPIDatatypes<typename T_Send::value_Type>::type, destUri, tag, contextMap[context.getID()]);
304-
// }
215+
template <typename T_Send>
216+
void send(const VAddr destVAddr, const Tag tag, const Context context, const T_Send& sendData){
217+
Uri destUri = getVAddrUri(context, destVAddr);
218+
context.comm.send(destUri, tag, sendData.data(), sendData.size());
219+
}
305220

306221

307222
/**
@@ -319,15 +234,12 @@ namespace graybat {
319234
* @return Event
320235
*
321236
*/
322-
// template <typename T_Recv>
323-
// Event asyncRecv(const VAddr srcVAddr, const Tag tag, const Context context, const T_Recv& recvData){
324-
// MPI_Request request;
325-
// Uri srcUri = getVAddrUri(context, srcVAddr);
326-
// MPI_Irecv(const_cast<typename T_Recv::value_type*>(recvData.data()), recvData.size(),
327-
// MPIDatatypes<typename T_Recv::value_type>::type, srcUri, tag,
328-
// contextMap[context.getID()], &request);
329-
// return Event(request);
330-
// }
237+
template <typename T_Recv>
238+
Event asyncRecv(const VAddr srcVAddr, const Tag tag, const Context context, T_Recv& recvData){
239+
Uri srcUri = getVAddrUri(context, srcVAddr);
240+
mpi::request request = context.comm.irecv(srcUri, tag, recvData.data(), recvData.size());
241+
return Event(request);
242+
}
331243

332244

333245
/**
@@ -371,16 +283,10 @@ namespace graybat {
371283
* *rootVAddr* will receive. *recvData* of all other members of the
372284
* *context* will be empty.
373285
*/
374-
// template <typename T_Send, typename T_Recv>
375-
// void gather(const VAddr rootVAddr, const Context context, const T_Send& sendData, T_Recv& recvData){
376-
// Uri rootUri = getVAddrUri(context, rootVAddr);
377-
378-
// MPI_Gather(const_cast<typename T_Send::value_type*>(sendData.data()), sendData.size(),
379-
// MPIDatatypes<typename T_Send::value_type>::type,
380-
// const_cast<typename T_Recv::value_type*>(recvData.data()), sendData.size(),
381-
// MPIDatatypes<typename T_Recv::value_type>::type,
382-
// rootUri, contextMap[context.getID()]);
383-
// }
286+
template <typename T_Send, typename T_Recv>
287+
void gather(const VAddr rootVAddr, const Context context, const T_Send& sendData, T_Recv& recvData){ Uri rootUri = getVAddrUri(context, rootVAddr);
288+
mpi::gather(context.comm, sendData.data(), sendData.size(), recvData, rootUri);
289+
}
384290

385291

386292
/**
@@ -435,31 +341,11 @@ namespace graybat {
435341
* @param[out] recvCount Number of elements each peer sends (can by varying).
436342
*
437343
*/
438-
// template <typename T_Send, typename T_Recv>
439-
// void allGatherVar(const Context context, const T_Send& sendData, T_Recv& recvData, std::vector<unsigned>& recvCount){
440-
// // Retrieve number of elements each peer sends
441-
// recvCount.resize(context.size());
442-
// allGather(context, std::array<unsigned, 1>{{(unsigned)sendData.size()}}, recvCount);
443-
// recvData.resize(std::accumulate(recvCount.begin(), recvCount.end(), 0U));
444-
445-
// int rdispls[context.size()];
446-
447-
// // Create offset map
448-
// unsigned offset = 0;
449-
// for (unsigned i=0; i < context.size(); ++i) {
450-
// rdispls[i] = offset;
451-
// offset += recvCount[i];
452-
453-
// }
454-
455-
// // Gather data with varying size
456-
// MPI_Allgatherv(const_cast<typename T_Send::value_type*>(sendData.data()), sendData.size(),
457-
// MPIDatatypes<typename T_Send::value_type>::type,
458-
// const_cast<typename T_Recv::value_type*>(recvData.data()),
459-
// const_cast<int*>((int*)recvCount.data()), rdispls,
460-
// MPIDatatypes<typename T_Recv::value_type>::type,
461-
// contextMap[context.getID()]);
462-
// }
344+
template <typename T_Send, typename T_Recv>
345+
void allGatherVar(const Context context, const T_Send& sendData, T_Recv& recvData, std::vector<unsigned>& recvCount){
346+
mpi::all_gather(context.comm, sendData.data(), sendData.size(), recvData.data());
347+
348+
}
463349

464350

465351
/**
@@ -474,16 +360,12 @@ namespace graybat {
474360
* @param[out] recvData Data from peer with *rootVAddr*.
475361
*
476362
*/
477-
// template <typename T_Send, typename T_Recv>
478-
// void scatter(const VAddr rootVAddr, const Context context, const T_Send& sendData, T_Recv& recvData){
479-
// Uri rootUri = getVAddrUri(context, rootVAddr);
480-
// MPI_Scatter(const_cast<typename T_Send::value_type*>(sendData.data()), recvData.size(),
481-
// MPIDatatypes<typename T_Send::value_type>::type,
482-
// const_cast<typename T_Recv::value_type*>(recvData.data()), recvData.size(),
483-
// MPIDatatypes<typename T_Recv::value_type>::type,
484-
// rootUri, contextMap[context.getID()]);
363+
template <typename T_Send, typename T_Recv>
364+
void scatter(const VAddr rootVAddr, const Context context, const T_Send& sendData, T_Recv& recvData){
365+
Uri rootUri = getVAddrUri(context, rootVAddr);
366+
mpi::scatter(context.comm, sendData.data(), recvData.data(), recvData.size(), rootUri);
485367

486-
// }
368+
}
487369

488370

489371
/**
@@ -498,16 +380,13 @@ namespace graybat {
498380
* @param[out] recvData Data from all peer.
499381
*
500382
*/
501-
// template <typename T_Send, typename T_Recv>
502-
// void allToAll(const Context context, const T_Send& sendData, T_Recv& recvData){
503-
// unsigned elementsPerPeer = sendData.size() / context.size();
504-
// MPI_Alltoall(const_cast<typename T_Send::value_type*>(sendData.data()), elementsPerPeer,
505-
// MPIDatatypes<typename T_Send::value_type>::type,
506-
// const_cast<typename T_Recv::value_type*>(recvData), elementsPerPeer,
507-
// MPIDatatypes<typename T_Recv::value_type>::type,
508-
// contextMap[context.getID()]);
383+
template <typename T_Send, typename T_Recv>
384+
void allToAll(const Context context, const T_Send& sendData, T_Recv& recvData){
385+
unsigned elementsPerPeer = sendData.size() / context.size();
386+
387+
mpi::all_to_all(context.comm, sendData.data(), elementsPerPeer, recvData.data());
509388

510-
// }
389+
}
511390

512391

513392
/**
@@ -526,17 +405,12 @@ namespace graybat {
526405
* reduced sendData values.
527406
*
528407
*/
529-
// template <typename T_Send, typename T_Recv, typename T_Op>
530-
// void reduce(const VAddr rootVAddr, const Context context, const T_Op op, const T_Send& sendData, const T_Recv& recvData){
531-
532-
// UserOperation<typename T_Send::value_type, T_Op> mpiOp(op);
533-
// Uri rootUri = getVAddrUri(context, rootVAddr);
534-
// MPI_Reduce(const_cast<typename T_Send::value_type*>(sendData.data()),
535-
// const_cast<typename T_Recv::value_type*>(recvData.data()), sendData.size(),
536-
// MPIDatatypes<typename T_Send::value_type>::type, mpiOp.getMpiOp(),
537-
// rootUri, contextMap[context.getID()]);
408+
template <typename T_Send, typename T_Recv, typename T_Op>
409+
void reduce(const VAddr rootVAddr, const Context context, const T_Op op, const T_Send& sendData, const T_Recv& recvData){
410+
Uri rootUri = getVAddrUri(context, rootVAddr);
411+
mpi::reduce(context.comm, sendData.data(), sendData.size(), recvData.data(), op, rootUri);
538412

539-
// }
413+
}
540414

541415
/**
542416
* @brief Performs a reduction with a binary operator *op* on all *sendData* elements from all peers
@@ -552,7 +426,7 @@ namespace graybat {
552426
*/
553427
template <typename T_Send, typename T_Recv, typename T_Op>
554428
void allReduce(const Context context, T_Op op, const T_Send& sendData, T_Recv& recvData){
555-
mpi::all_reduce(context.comm, sendData.data(), sendData.size() , recvData.data(), op);
429+
mpi::all_reduce(context.comm, sendData.data(), sendData.size(), recvData.data(), op);
556430

557431
}
558432

@@ -569,22 +443,21 @@ namespace graybat {
569443
* @param[out] recvData Data from peer with *rootVAddr*.
570444
*
571445
*/
572-
// template <typename T_SendRecv>
573-
// void broadcast(const VAddr rootVAddr, const Context context, const T_SendRecv& data){
574-
// Uri rootUri = uriMap.at(context.getID()).at(rootVAddr);
575-
// MPI_Bcast(const_cast<typename T_SendRecv::value_type*>(data.data()), data.size(),
576-
// MPIDatatypes<typename T_SendRecv::value_type>::type, rootUri, contextMap[context.getID()]);
577-
// }
446+
template <typename T_SendRecv>
447+
void broadcast(const VAddr rootVAddr, const Context context, const T_SendRecv& data){
448+
Uri rootUri = uriMap.at(context.getID()).at(rootVAddr);
449+
mpi::broadcast(context.comm, data.data(), data.size(), rootUri);
450+
}
578451

579452

580453
/**
581454
* @brief Synchronizes all peers within *context* to the same point
582455
* in the programm execution (barrier).
583456
*
584457
*/
585-
// void synchronize(const Context context){
586-
// MPI_Barrier(contextMap[context.getID()]);
587-
// }
458+
void synchronize(const Context context){
459+
context.comm.barrier();
460+
}
588461

589462

590463
/**
@@ -594,9 +467,9 @@ namespace graybat {
594467
* @see getGlobalContext()
595468
*
596469
*/
597-
// void synchronize(){
598-
// synchronize(getGlobalContext());
599-
// }
470+
void synchronize(){
471+
synchronize(getGlobalContext());
472+
}
600473

601474

602475

@@ -667,49 +540,6 @@ namespace graybat {
667540
*
668541
***************************************************************************/
669542

670-
/**
671-
* @brief Initilizes MPI if it was not initialized
672-
* before.
673-
*
674-
*/
675-
// void initMPI(){
676-
// int flag = 0;
677-
// MPI_Initialized(&flag);
678-
// if(!flag){
679-
// int argc = 0;
680-
// char **argv;
681-
// MPI_Init(&argc, &argv);
682-
// }
683-
// }
684-
685-
/**
686-
* @brief Returns the initial VAddr of the peer
687-
* in the global context. This is the
688-
* rank of the MPI process in the global
689-
* communicator.
690-
*
691-
*/
692-
// VAddr initialVAddr(){
693-
// initMPI();
694-
// Uri uriTmp;
695-
// MPI_Comm_rank(MPI_COMM_WORLD, &uriTmp);
696-
// return (VAddr)uriTmp;
697-
698-
// }
699-
700-
/**
701-
* @brief Returns the number of processes
702-
* in a communicator and ensures
703-
* that MPI is initialized.
704-
*
705-
*/
706-
// size_t MPICommSize(MPI_Comm comm){
707-
// initMPI();
708-
// int n;
709-
// MPI_Comm_size(comm, &n);
710-
// return n;
711-
// }
712-
713543
void error(VAddr vAddr, std::string msg){
714544
using namespace dout;
715545
Dout dout = Dout::getInstance();

0 commit comments

Comments
 (0)