Changeset 1249 for XIOS/dev/XIOS_DEV_CMIP6/src/node/domain.cpp
- Timestamp:
- 08/30/17 15:33:51 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/XIOS_DEV_CMIP6/src/node/domain.cpp
r1236 r1249 86 86 \return the number of indexes written by each server 87 87 */ 88 int CDomain::getNumberWrittenIndexes() const 89 { 90 return numberWrittenIndexes_; 88 int CDomain::getNumberWrittenIndexes(MPI_Comm writtenCom) 89 { 90 int writtenSize; 91 MPI_Comm_size(writtenCom, &writtenSize); 92 return numberWrittenIndexes_[writtenSize]; 91 93 } 92 94 … … 95 97 \return the total number of indexes written by the servers 96 98 */ 97 int CDomain::getTotalNumberWrittenIndexes() const 98 { 99 return totalNumberWrittenIndexes_; 99 int CDomain::getTotalNumberWrittenIndexes(MPI_Comm writtenCom) 100 { 101 int writtenSize; 102 MPI_Comm_size(writtenCom, &writtenSize); 103 return totalNumberWrittenIndexes_[writtenSize]; 100 104 } 101 105 … … 104 108 \return the offset of indexes written by each server 105 109 */ 106 int CDomain::getOffsetWrittenIndexes() const 107 { 108 return offsetWrittenIndexes_; 110 int CDomain::getOffsetWrittenIndexes(MPI_Comm writtenCom) 111 { 112 int writtenSize; 113 MPI_Comm_size(writtenCom, &writtenSize); 114 return offsetWrittenIndexes_[writtenSize]; 115 } 116 117 CArray<int, 1>& CDomain::getCompressedIndexToWriteOnServer(MPI_Comm writtenCom) 118 { 119 int writtenSize; 120 MPI_Comm_size(writtenCom, &writtenSize); 121 return compressedIndexToWriteOnServer[writtenSize]; 109 122 } 110 123 … … 1497 1510 void CDomain::checkArea(void) 1498 1511 { 1499 bool hasAreaValue = ( 0 != areavalue.numElements());1500 hasArea = !area.isEmpty() || !areavalue.isEmpty();1501 if (hasArea )1512 bool hasAreaValue = (!areavalue.isEmpty() && 0 != areavalue.numElements()); 1513 hasArea = !area.isEmpty(); 1514 if (hasArea && !hasAreaValue) 1502 1515 { 1503 1516 if (area.extent(0) != ni || area.extent(1) != nj) … … 1902 1915 } 1903 1916 1904 if (isCompressible()) 1905 { 1906 nbWritten = 0; 1907 boost::unordered_map<size_t,size_t> localGlobalIndexMap; 1908 for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) 1909 { 1910 indGlo = *itSrv; 1911 if (ite != globalLocalIndexMap_.find(indGlo)) 1912 { 1913 localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo; 1914 ++nbWritten; 1915 } 1916 } 1917 1918 nbWritten = 0; 1919 for (int idx = 0; idx < data_i_index.numElements(); ++idx) 1920 { 1921 if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 1922 { 1923 ++nbWritten; 1924 } 1925 } 1926 1927 compressedIndexToWriteOnServer.resize(nbWritten); 1928 nbWritten = 0; 1929 for (int idx = 0; idx < data_i_index.numElements(); ++idx) 1930 { 1931 if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 1932 { 1933 compressedIndexToWriteOnServer(nbWritten) = localGlobalIndexMap[data_i_index(idx)]; 1934 ++nbWritten; 1935 } 1936 } 1937 1938 numberWrittenIndexes_ = nbWritten; 1939 if (isDistributed()) 1940 { 1941 MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 1942 MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 1943 offsetWrittenIndexes_ -= numberWrittenIndexes_; 1944 } 1945 else 1946 totalNumberWrittenIndexes_ = numberWrittenIndexes_; 1947 } 1948 } 1917 // if (isCompressible()) 1918 // { 1919 // nbWritten = 0; 1920 // boost::unordered_map<size_t,size_t> localGlobalIndexMap; 1921 // for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) 1922 // { 1923 // indGlo = *itSrv; 1924 // if (ite != globalLocalIndexMap_.find(indGlo)) 1925 // { 1926 // localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo; 1927 // ++nbWritten; 1928 // } 1929 // } 1930 1931 // nbWritten = 0; 1932 // for (int idx = 0; idx < data_i_index.numElements(); ++idx) 1933 // { 1934 // if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 1935 // { 1936 // ++nbWritten; 1937 // } 1938 // } 1939 1940 // compressedIndexToWriteOnServer.resize(nbWritten); 1941 // nbWritten = 0; 1942 // for (int idx = 0; idx < data_i_index.numElements(); ++idx) 1943 // { 1944 // if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 1945 // { 1946 // compressedIndexToWriteOnServer(nbWritten) = localGlobalIndexMap[data_i_index(idx)]; 1947 // ++nbWritten; 1948 // } 1949 // } 1950 1951 // numberWrittenIndexes_ = nbWritten; 1952 // if (isDistributed()) 1953 // { 1954 // MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 1955 // MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 1956 // offsetWrittenIndexes_ -= numberWrittenIndexes_; 1957 // } 1958 // else 1959 // totalNumberWrittenIndexes_ = numberWrittenIndexes_; 1960 // } 1961 } 1962 1963 void CDomain::computeWrittenCompressedIndex(MPI_Comm writtenComm) 1964 { 1965 int writtenCommSize; 1966 MPI_Comm_size(writtenComm, &writtenCommSize); 1967 if (compressedIndexToWriteOnServer.find(writtenCommSize) != compressedIndexToWriteOnServer.end()) 1968 return; 1969 1970 if (isCompressible()) 1971 { 1972 size_t nbWritten = 0, indGlo; 1973 CContext* context=CContext::getCurrent(); 1974 CContextServer* server = context->server; 1975 1976 std::vector<int> nBegin(2), nSize(2), nBeginGlobal(2), nGlob(2); 1977 nBegin[0] = zoom_ibegin; nBegin[1] = zoom_jbegin; 1978 nSize[0] = zoom_ni; nSize[1] = zoom_nj; 1979 nBeginGlobal[0] = 0; nBeginGlobal[1] = 0; 1980 nGlob[0] = ni_glo; nGlob[1] = nj_glo; 1981 CDistributionServer srvDist(server->intraCommSize, nBegin, nSize, nBeginGlobal, nGlob); 1982 const CArray<size_t,1>& writtenGlobalIndex = srvDist.getGlobalIndex(); 1983 1984 boost::unordered_map<size_t,size_t>::const_iterator itb = globalLocalIndexMap_.begin(), 1985 ite = globalLocalIndexMap_.end(), it; 1986 CArray<size_t,1>::const_iterator itSrvb = writtenGlobalIndex.begin(), 1987 itSrve = writtenGlobalIndex.end(), itSrv; 1988 boost::unordered_map<size_t,size_t> localGlobalIndexMap; 1989 for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) 1990 { 1991 indGlo = *itSrv; 1992 if (ite != globalLocalIndexMap_.find(indGlo)) 1993 { 1994 localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo; 1995 ++nbWritten; 1996 } 1997 } 1998 1999 nbWritten = 0; 2000 for (int idx = 0; idx < data_i_index.numElements(); ++idx) 2001 { 2002 if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 2003 { 2004 ++nbWritten; 2005 } 2006 } 2007 2008 compressedIndexToWriteOnServer[writtenCommSize].resize(nbWritten); 2009 nbWritten = 0; 2010 for (int idx = 0; idx < data_i_index.numElements(); ++idx) 2011 { 2012 if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 2013 { 2014 compressedIndexToWriteOnServer[writtenCommSize](nbWritten) = localGlobalIndexMap[data_i_index(idx)]; 2015 ++nbWritten; 2016 } 2017 } 2018 2019 numberWrittenIndexes_[writtenCommSize] = nbWritten; 2020 if (isDistributed()) 2021 { 2022 2023 MPI_Allreduce(&numberWrittenIndexes_[writtenCommSize], &totalNumberWrittenIndexes_[writtenCommSize], 1, MPI_INT, MPI_SUM, writtenComm); 2024 MPI_Scan(&numberWrittenIndexes_[writtenCommSize], &offsetWrittenIndexes_[writtenCommSize], 1, MPI_INT, MPI_SUM, writtenComm); 2025 offsetWrittenIndexes_[writtenCommSize] -= numberWrittenIndexes_[writtenCommSize]; 2026 } 2027 else 2028 totalNumberWrittenIndexes_[writtenCommSize] = numberWrittenIndexes_[writtenCommSize]; 2029 } 2030 } 1949 2031 1950 2032 /*! … … 2406 2488 void CDomain::recvIndex(std::map<int, CBufferIn*>& rankBuffers) 2407 2489 { 2408 int nbReceived = rankBuffers.size(), i, ind, index, type_int ;2490 int nbReceived = rankBuffers.size(), i, ind, index, type_int, iIndex, jIndex; 2409 2491 recvClientRanks_.resize(nbReceived); 2410 2492 … … 2426 2508 globalLocalIndexMap_.rehash(std::ceil(nbIndGlob/globalLocalIndexMap_.max_load_factor())); 2427 2509 i_index.resize(nbIndGlob); 2428 j_index.resize(nbIndGlob); 2510 j_index.resize(nbIndGlob); 2511 int nbIndexGlobMax = nbIndGlob, nbIndLoc; 2512 2429 2513 nbIndGlob = 0; 2430 2514 for (i = 0; i < nbReceived; ++i) … … 2436 2520 if (0 == globalLocalIndexMap_.count(index)) 2437 2521 { 2438 i_index(nbIndGlob) = index % ni_glo; 2439 j_index(nbIndGlob) = index / ni_glo; 2440 globalLocalIndexMap_[index] = nbIndGlob; 2441 ++nbIndGlob; 2522 iIndex = (index%ni_glo)-ibegin; 2523 iIndex = (iIndex < 0) ? 0 : iIndex; 2524 jIndex = (index/ni_glo)-jbegin; 2525 jIndex = (jIndex < 0) ? 0 : jIndex; 2526 nbIndLoc = iIndex + ni * jIndex; 2527 if (nbIndLoc < nbIndexGlobMax) 2528 { 2529 i_index(nbIndLoc) = index % ni_glo; 2530 j_index(nbIndLoc) = index / ni_glo; 2531 globalLocalIndexMap_[index] = nbIndLoc; 2532 ++nbIndGlob; 2533 } 2534 // i_index(nbIndGlob) = index % ni_glo; 2535 // j_index(nbIndGlob) = index / ni_glo; 2536 // globalLocalIndexMap_[index] = nbIndGlob; 2537 // ++nbIndGlob; 2442 2538 } 2443 2539 } … … 2497 2593 if (zoom_ni<=0 || zoom_nj<=0) 2498 2594 { 2499 zoom_ ibegin=0 ; zoom_iend=0 ; zoom_ni=0 ;2500 zoom_ jbegin=0 ; zoom_jend=0 ; zoom_nj=0 ;2595 zoom_ni=0 ; zoom_ibegin=global_zoom_ibegin ; //=0; zoom_iend=0 ; 2596 zoom_nj=0 ; zoom_jbegin=global_zoom_jbegin ; //=0; zoom_jend=0 ; 2501 2597 } 2502 2598 … … 2555 2651 nbMaskInd = globalLocalIndexMap_.size(); 2556 2652 mask_1d.resize(nbMaskInd); 2653 mask_1d = false; 2557 2654 2558 2655 for (i = 0; i < nbReceived; ++i) … … 2862 2959 Receive data index information from client(s) 2863 2960 A client receives data index from different clients to rebuild its own data index. 2961 Because we use global index + mask info to calculate the sending data to client(s), 2962 this data index must be updated with mask info (maybe it will change in the future) 2864 2963 Because the data index is local, to rebuild data index of received client, we should use global index along with. 2964 2865 2965 \param[in] rankBuffers rank of sending client and the corresponding receive buffer 2866 2966 */ … … 2901 3001 lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; 2902 3002 dataIIndex(lInd) = (-1 == dataIIndex(lInd)) ? tmpI(ind) : dataIIndex(lInd); // Only fill in dataIndex if there is no data 2903 dataJIndex(lInd) = (-1 == dataJIndex(lInd)) ? tmpJ(ind) : dataJIndex(lInd); 3003 dataJIndex(lInd) = (-1 == dataJIndex(lInd)) ? tmpJ(ind) : dataJIndex(lInd); 3004 3005 if (!mask_1d(lInd)) // Include mask info into data index on the RECEIVE getServerDimensionSizes 3006 { 3007 dataIIndex(lInd) = dataJIndex(lInd) = -1; 3008 } 2904 3009 } 2905 3010 }
Note: See TracChangeset
for help on using the changeset viewer.