00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "DAPTA.hpp"
00016
00017 #include <cassert>
00018
00019 namespace DAPTA {
00020
00021 namespace pico {
00022
00023 template <typename V>
00024 FieldExchanger<V>::FieldExchanger(DomainCoupler<V>* coupler, std::vector<int>::iterator lGbegin, int nodes) {
00025 _coupler = coupler;
00026
00027 _coupler->template registerSendBuffer<int>(RED, &(*lGbegin), nodes);
00028 _coupler->exchangeSubdomainDataIntra(RED);
00029
00030
00031 int importedNodes = _coupler->template recvBufferSize<int>(RED);
00032 assert(importedNodes>0);
00033 _importedNodeIDs.reserve(importedNodes);
00034
00035 const int notUsed=0;
00036 int *tmp = _coupler->recvBuffer(RED, notUsed);
00037
00038 for (int i=0; i<importedNodes; ++i) {
00039 std::vector<int>::iterator it = std::find(lGbegin, lGbegin+nodes, tmp[i]);
00040 int localID = std::distance(lGbegin, it);
00041 if (localID<nodes) {
00042 _importedNodeIDs.push_back(localID);
00043 } else {
00044 _importedNodeIDs.push_back(-1);
00045 }
00046 }
00047 }
00048
00049 template <typename V>
00050 template <int NVAR, typename FT, template <typename> class OP>
00051 void FieldExchanger<V>::exchange(FT *field, int fsize) {
00052
00053
00054
00055
00056 _coupler->registerSendBuffer(RED, field, fsize);
00057 _coupler->exchangeSubdomainDataIntra(RED);
00058
00059 const FT notUsed(0);
00060 FT *tmp = _coupler->recvBuffer(RED, notUsed);
00061
00062 OP<FT> operation;
00063 std::vector<int>::iterator it = _importedNodeIDs.begin();
00064 std::vector<int>::iterator ite = _importedNodeIDs.end();
00065 for (int i=0; it!=ite; ++it, ++i) {
00066 if (*it==-1) continue;
00067 for (int j=0; j<NVAR; ++j) {
00068 assert((NVAR*(*it)+j)<fsize);
00069 field[NVAR*(*it)+j] = operation(field[NVAR*(*it)+j], tmp[NVAR*i+j]);
00070 }
00071 }
00072 }
00073
00074 }
00075
00076 }