Changeset 1637 for XIOS/trunk/src/node/domain.cpp
- Timestamp:
- 01/14/19 13:33:48 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/domain.cpp
r1622 r1637 179 179 // size estimation for sendIndex (and sendArea which is always smaller or equal) 180 180 size_t sizeIndexEvent = 2 * sizeof(size_t) + 2 * CArray<int,1>::size(idxCount); 181 // if (isCompressible_)182 // {183 // std::map<int, std::vector<int> >::const_iterator itWritten = indWrittenSrv_.find(rank);184 // size_t writtenIdxCount = (itWritten != itWrittenIndexEnd) ? itWritten->second.size() : 0;185 // sizeIndexEvent += CArray<int,1>::size(writtenIdxCount);186 // }187 181 188 182 // size estimation for sendLonLat … … 1139 1133 TRY 1140 1134 { 1135 int i,j,ind; 1141 1136 if (!data_i_index.isEmpty()) 1142 1137 { … … 1159 1154 << "'data_j_index' must be defined when 'data_i_index' is set and 'data_dim' is 2."); 1160 1155 } 1156 for (int k=0; k<data_i_index.numElements(); ++k) 1157 { 1158 i = data_i_index(k)+data_ibegin ; 1159 j = data_j_index(k)+data_jbegin ; 1160 if (i>=0 && i<ni && j>=0 && j<nj) 1161 { 1162 ind=j*ni+i ; 1163 if (!domainMask(ind)) 1164 { 1165 data_i_index(k) = -1; 1166 data_j_index(k) = -1; 1167 } 1168 } 1169 else 1170 { 1171 data_i_index(k) = -1; 1172 data_j_index(k) = -1; 1173 } 1174 } 1161 1175 } 1162 1176 else // (1 == data_dim) … … 1165 1179 { 1166 1180 data_j_index.resize(data_ni); 1167 for (int j = 0; j < data_ni; ++j) data_j_index(j) = 0; 1181 data_j_index = 0; 1182 } 1183 for (int k=0; k<data_i_index.numElements(); ++k) 1184 { 1185 i=data_i_index(k)+data_ibegin ; 1186 if (i>=0 && i < domainMask.size()) 1187 { 1188 if (!domainMask(i)) data_i_index(k) = -1; 1189 } 1190 else 1191 data_i_index(k) = -1; 1192 1193 if (!domainMask(i)) data_i_index(k) = -1; 1168 1194 } 1169 1195 } … … 1180 1206 data_i_index.resize(data_ni); 1181 1207 data_j_index.resize(data_ni); 1182 1183 for (int i = 0; i < data_ni; ++i) 1208 data_j_index = 0; 1209 1210 for (int k = 0; k < data_ni; ++k) 1184 1211 { 1185 data_i_index(i) = i; 1186 data_j_index(i) = 0; 1212 i=k+data_ibegin ; 1213 if (i>=0 && i < domainMask.size()) 1214 { 1215 if (domainMask(i)) 1216 data_i_index(k) = k; 1217 else 1218 data_i_index(k) = -1; 1219 } 1220 else 1221 data_i_index(k) = -1; 1187 1222 } 1188 1223 } … … 1193 1228 data_j_index.resize(dsize); 1194 1229 1195 for(int count = 0, j = 0; j < data_nj; ++j)1230 for(int count = 0, kj = 0; kj < data_nj; ++kj) 1196 1231 { 1197 for(int i = 0; i < data_ni; ++i, ++count)1232 for(int ki = 0; ki < data_ni; ++ki, ++count) 1198 1233 { 1199 data_i_index(count) = i; 1200 data_j_index(count) = j; 1234 i = ki + data_ibegin; 1235 j = kj + data_jbegin; 1236 ind=j*ni+i ; 1237 if (i>=0 && i<ni && j>=0 && j<nj) 1238 { 1239 if (domainMask(ind)) 1240 { 1241 data_i_index(count) = ki; 1242 data_j_index(count) = kj; 1243 } 1244 else 1245 { 1246 data_i_index(count) = -1; 1247 data_j_index(count) = -1; 1248 } 1249 } 1250 else 1251 { 1252 data_i_index(count) = -1; 1253 data_j_index(count) = -1; 1254 } 1201 1255 } 1202 1256 } … … 1872 1926 connectedServerRank_[nbServer].push_back(client->clientRank % client->serverSize); 1873 1927 1928 // Now check if all servers have data to receive. If not, master client will send empty data. 1929 // This ensures that all servers will participate in collective calls upon receiving even if they have no date to receive. 1930 std::vector<int> counts (clientSize); 1931 std::vector<int> displs (clientSize); 1932 displs[0] = 0; 1933 int localCount = connectedServerRank_[nbServer].size() ; 1934 MPI_Gather(&localCount, 1, MPI_INT, &counts[0], 1, MPI_INT, 0, client->intraComm) ; 1935 for (int i = 0; i < clientSize-1; ++i) 1936 { 1937 displs[i+1] = displs[i] + counts[i]; 1938 } 1939 std::vector<int> allConnectedServers(displs[clientSize-1]+counts[clientSize-1]); 1940 MPI_Gatherv(&(connectedServerRank_[nbServer])[0], localCount, MPI_INT, &allConnectedServers[0], &counts[0], &displs[0], MPI_INT, 0, client->intraComm); 1941 1942 if ((allConnectedServers.size() != nbServer) && (rank == 0)) 1943 { 1944 std::vector<bool> isSrvConnected (nbServer, false); 1945 for (int i = 0; i < allConnectedServers.size(); ++i) isSrvConnected[allConnectedServers[i]] = true; 1946 for (int i = 0; i < nbServer; ++i) 1947 { 1948 if (!isSrvConnected[i]) connectedServerRank_[nbServer].push_back(i); 1949 } 1950 } 1874 1951 nbSenders[nbServer] = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_[nbServer]); 1875 1952 delete clientServerMap; … … 1908 1985 itSrve = writtenGlobalIndex.end(), itSrv; 1909 1986 1910 // for (itSrv = itSrvb; itSrv != itSrve; ++itSrv)1911 // {1912 // indGlo = *itSrv;1913 // if (ite != globalLocalIndexMap_.find(indGlo))1914 // {1915 // ++nbWritten;1916 // }1917 // }1918 1919 // localIndexToWriteOnServer.resize(nbWritten);1920 1987 localIndexToWriteOnServer.resize(writtenGlobalIndex.numElements()); 1921 1922 1988 nbWritten = 0; 1923 1989 for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) … … 1927 1993 { 1928 1994 localIndexToWriteOnServer(nbWritten) = globalLocalIndexMap_[indGlo]; 1929 ++nbWritten;1930 1995 } 1931 1996 else 1932 1997 { 1933 localIndexToWriteOnServer(nbWritten) = 0; 1934 ++nbWritten; 1935 } 1936 } 1937 1938 // if (isCompressible()) 1939 // { 1940 // nbWritten = 0; 1941 // std::unordered_map<size_t,size_t> localGlobalIndexMap; 1942 // for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) 1943 // { 1944 // indGlo = *itSrv; 1945 // if (ite != globalLocalIndexMap_.find(indGlo)) 1946 // { 1947 // localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo; 1948 // ++nbWritten; 1949 // } 1950 // } 1951 1952 // nbWritten = 0; 1953 // for (int idx = 0; idx < data_i_index.numElements(); ++idx) 1954 // { 1955 // if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 1956 // { 1957 // ++nbWritten; 1958 // } 1959 // } 1960 1961 // compressedIndexToWriteOnServer.resize(nbWritten); 1962 // nbWritten = 0; 1963 // for (int idx = 0; idx < data_i_index.numElements(); ++idx) 1964 // { 1965 // if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 1966 // { 1967 // compressedIndexToWriteOnServer(nbWritten) = localGlobalIndexMap[data_i_index(idx)]; 1968 // ++nbWritten; 1969 // } 1970 // } 1971 1972 // numberWrittenIndexes_ = nbWritten; 1973 // if (isDistributed()) 1974 // { 1975 // MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 1976 // MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 1977 // offsetWrittenIndexes_ -= numberWrittenIndexes_; 1978 // } 1979 // else 1980 // totalNumberWrittenIndexes_ = numberWrittenIndexes_; 1981 // } 1998 localIndexToWriteOnServer(nbWritten) = -1; 1999 } 2000 ++nbWritten; 2001 } 1982 2002 } 1983 2003 CATCH_DUMP_ATTR … … 2063 2083 sendDistributionAttributes(); 2064 2084 sendIndex(); 2065 sendMask();2066 2085 sendLonLat(); 2067 2086 sendArea(); … … 2174 2193 2175 2194 /*! 2176 Send mask index from client to connected(s) clients2177 */2178 void CDomain::sendMask()2179 TRY2180 {2181 int ns, n, i, j, ind, nv, idx;2182 std::list<CContextClient*>::iterator it;2183 for (it=clients.begin(); it!=clients.end(); ++it)2184 {2185 CContextClient* client = *it;2186 int serverSize = client->serverSize;2187 2188 // send area for each connected server2189 CEventClient eventMask(getType(), EVENT_ID_MASK);2190 2191 list<CMessage> list_msgsMask;2192 list<CArray<bool,1> > list_mask;2193 2194 std::unordered_map<int, vector<size_t> >::const_iterator it, iteMap;2195 iteMap = indSrv_[serverSize].end();2196 for (int k = 0; k < connectedServerRank_[serverSize].size(); ++k)2197 {2198 int nbData = 0;2199 int rank = connectedServerRank_[serverSize][k];2200 it = indSrv_[serverSize].find(rank);2201 if (iteMap != it)2202 nbData = it->second.size();2203 list_mask.push_back(CArray<bool,1>(nbData));2204 2205 const std::vector<size_t>& temp = it->second;2206 for (n = 0; n < nbData; ++n)2207 {2208 idx = static_cast<int>(it->second[n]);2209 list_mask.back()(n) = domainMask(globalLocalIndexMap_[idx]);2210 }2211 2212 list_msgsMask.push_back(CMessage());2213 list_msgsMask.back() << this->getId() << list_mask.back();2214 eventMask.push(rank, nbSenders[serverSize][rank], list_msgsMask.back());2215 }2216 client->sendEvent(eventMask);2217 }2218 }2219 CATCH_DUMP_ATTR2220 2221 /*!2222 2195 Send area from client to connected client(s) 2223 2196 */ … … 2458 2431 case EVENT_ID_INDEX: 2459 2432 recvIndex(event); 2460 return true;2461 break;2462 case EVENT_ID_MASK:2463 recvMask(event);2464 2433 return true; 2465 2434 break; … … 2555 2524 jIndex = (jIndex < 0) ? 0 : jIndex; 2556 2525 nbIndLoc = iIndex + ni * jIndex; 2557 if (nbIndLoc < nbIndexGlobMax) 2558 { 2559 i_index(nbIndLoc) = index % ni_glo; 2560 j_index(nbIndLoc) = index / ni_glo; 2561 globalLocalIndexMap_[index] = nbIndLoc; 2562 ++nbIndGlob; 2563 } 2564 // i_index(nbIndGlob) = index % ni_glo; 2565 // j_index(nbIndGlob) = index / ni_glo; 2566 // globalLocalIndexMap_[index] = nbIndGlob; 2567 // ++nbIndGlob; 2526 i_index(nbIndGlob) = index % ni_glo; 2527 j_index(nbIndGlob) = index / ni_glo; 2528 globalLocalIndexMap_[index] = nbIndGlob; 2529 ++nbIndGlob; 2568 2530 } 2569 2531 } … … 2580 2542 j_index.resizeAndPreserve(nbIndGlob); 2581 2543 } 2544 2545 domainMask.resize(0); // Mask is not defined anymore on servers 2582 2546 } 2583 2547 CATCH … … 2619 2583 2620 2584 } 2621 CATCH_DUMP_ATTR 2622 2623 /*! 2624 Receive area event from clients(s) 2625 \param[in] event event contain info about rank and associated area 2626 */ 2627 void CDomain::recvMask(CEventServer& event) 2628 TRY 2629 { 2630 string domainId; 2631 std::map<int, CBufferIn*> rankBuffers; 2632 2633 list<CEventServer::SSubEvent>::iterator it; 2634 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 2635 { 2636 CBufferIn* buffer = it->buffer; 2637 *buffer >> domainId; 2638 rankBuffers[it->rank] = buffer; 2639 } 2640 get(domainId)->recvMask(rankBuffers); 2641 } 2642 CATCH 2643 2644 /*! 2645 Receive mask information from client(s) 2646 \param[in] rankBuffers rank of sending client and the corresponding receive buffer 2647 */ 2648 void CDomain::recvMask(std::map<int, CBufferIn*>& rankBuffers) 2649 TRY 2650 { 2651 int nbReceived = rankBuffers.size(), i, ind, index, lInd; 2652 if (nbReceived != recvClientRanks_.size()) 2653 ERROR("void CDomain::recvMask(std::map<int, CBufferIn*>& rankBuffers)", 2654 << "The number of sending clients is not correct." 2655 << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 2656 2657 vector<CArray<bool,1> > recvMaskValue(nbReceived); 2658 for (i = 0; i < recvClientRanks_.size(); ++i) 2659 { 2660 int rank = recvClientRanks_[i]; 2661 CBufferIn& buffer = *(rankBuffers[rank]); 2662 buffer >> recvMaskValue[i]; 2663 } 2664 2665 int nbMaskInd = 0; 2666 for (i = 0; i < nbReceived; ++i) 2667 { 2668 nbMaskInd += recvMaskValue[i].numElements(); 2669 } 2670 2671 if (nbMaskInd != globalLocalIndexMap_.size()) 2672 info (0) << "If domain " << this->getDomainOutputName() <<" does not have overlapped regions between processes " 2673 << "something must be wrong with mask index "<< std::endl; 2674 2675 nbMaskInd = globalLocalIndexMap_.size(); 2676 mask_1d.resize(nbMaskInd); 2677 domainMask.resize(nbMaskInd); 2678 mask_1d = false; 2679 2680 for (i = 0; i < nbReceived; ++i) 2681 { 2682 CArray<int,1>& tmpInd = indGlob_[recvClientRanks_[i]]; 2683 CArray<bool,1>& tmp = recvMaskValue[i]; 2684 for (ind = 0; ind < tmp.numElements(); ++ind) 2685 { 2686 lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; 2687 if (!mask_1d(lInd)) // Only rewrite mask_1d if it's not true 2688 mask_1d(lInd) = tmp(ind); 2689 } 2690 } 2691 domainMask=mask_1d ; 2692 } 2693 CATCH_DUMP_ATTR 2694 2585 CATCH_DUMP_ATTR 2695 2586 /*! 2696 2587 Receive longitude event from clients(s) … … 3046 2937 dataIIndex(lInd) = (-1 == dataIIndex(lInd)) ? tmpI(ind) : dataIIndex(lInd); // Only fill in dataIndex if there is no data 3047 2938 dataJIndex(lInd) = (-1 == dataJIndex(lInd)) ? tmpJ(ind) : dataJIndex(lInd); 3048 3049 if (!domainMask(lInd)) // Include mask info into data index on the RECEIVE getServerDimensionSizes3050 {3051 dataIIndex(lInd) = dataJIndex(lInd) = -1;3052 }3053 2939 } 3054 2940 }
Note: See TracChangeset
for help on using the changeset viewer.