Changeset 1025 for XIOS/dev/dev_olga/src/node/domain.cpp
- Timestamp:
- 01/11/17 15:14:22 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_olga/src/node/domain.cpp
r1009 r1025 31 31 : CObjectTemplate<CDomain>(), CDomainAttributes() 32 32 , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_() 33 , hasBounds(false), hasArea(false), isDistributed_(false), nGlobDomain_(),isCompressible_(false), isUnstructed_(false)33 , hasBounds(false), hasArea(false), isDistributed_(false), isCompressible_(false), isUnstructed_(false) 34 34 , isClientAfterTransformationChecked(false), hasLonLat(false) 35 , lonvalue_client(), latvalue_client(), bounds_lon_client(), bounds_lat_client()36 35 , isRedistributed_(false), hasPole(false) 37 36 { … … 41 40 : CObjectTemplate<CDomain>(id), CDomainAttributes() 42 41 , isChecked(false), relFiles(), isClientChecked(false), nbConnectedClients_(), indSrv_(), connectedServerRank_() 43 , hasBounds(false), hasArea(false), isDistributed_(false), nGlobDomain_(),isCompressible_(false), isUnstructed_(false)42 , hasBounds(false), hasArea(false), isDistributed_(false), isCompressible_(false), isUnstructed_(false) 44 43 , isClientAfterTransformationChecked(false), hasLonLat(false) 45 , lonvalue_client(), latvalue_client(), bounds_lon_client(), bounds_lat_client()46 44 , isRedistributed_(false), hasPole(false) 47 45 { … … 113 111 { 114 112 return offsetWrittenIndexes_; 113 } 114 115 /*! 116 Returns the start of indexes written by each server. 117 \return the start of indexes written by each server 118 */ 119 const std::vector<int>& CDomain::getStartWriteIndex() const 120 { 121 return start_write_index_; 122 } 123 124 /*! 125 Returns the count of indexes written by each server. 126 \return the count of indexes written by each server 127 */ 128 const std::vector<int>& CDomain::getCountWriteIndex() const 129 { 130 return count_write_index_; 131 } 132 133 /*! 134 Returns the local data written by each server. 135 */ 136 const std::vector<int>& CDomain::getLocalWriteSize() const 137 { 138 return local_write_size_; 139 } 140 141 /*! 142 Returns the global data written by all server. 143 */ 144 const std::vector<int>& CDomain::getGlobalWriteSize() const 145 { 146 return global_write_size_; 115 147 } 116 148 … … 130 162 if (client->isServerLeader()) 131 163 { 132 // size estimation for send ServerAttribut164 // size estimation for sendDistributionAttribut 133 165 size_t size = 11 * sizeof(size_t); 134 166 … … 141 173 } 142 174 143 std::map<int, std::vector<size_t> >::const_iterator itIndexEnd = indSrv_.end();175 boost::unordered_map<int, vector<size_t> >::const_iterator itIndexEnd = indSrv_.end(); 144 176 std::map<int, std::vector<int> >::const_iterator itWrittenIndexEnd = indWrittenSrv_.end(); 145 177 for (size_t k = 0; k < connectedServerRank_.size(); ++k) 146 178 { 147 179 int rank = connectedServerRank_[k]; 148 std::map<int, std::vector<size_t> >::const_iterator it = indSrv_.find(rank);180 boost::unordered_map<int, std::vector<size_t> >::const_iterator it = indSrv_.find(rank); 149 181 size_t idxCount = (it != itIndexEnd) ? it->second.size() : 0; 150 182 … … 175 207 bool CDomain::isEmpty(void) const 176 208 { 177 return ((this->zoom_ni_srv == 0) || 178 (this->zoom_nj_srv == 0)); 209 return ((this->zoom_i_index.isEmpty()) || (0 == this->zoom_i_index.numElements())); 210 // return ((this->zoom_ni_srv == 0) || 211 // (this->zoom_nj_srv == 0)); 179 212 } 180 213 … … 695 728 for (int j = 0; j < nj; ++j) 696 729 for (int i = 0; i < ni; ++i) j_index(i+j*ni) = j+jbegin; 697 } 698 computeNGlobDomain(); 730 } 699 731 checkZoom(); 700 732 … … 715 747 if (global_zoom_nj.isEmpty()) 716 748 global_zoom_nj.setValue(nj_glo); 749 if (zoom_i_index.isEmpty()) zoom_i_index.setValue(i_index.getValue()); 750 if (zoom_j_index.isEmpty()) zoom_j_index.setValue(j_index.getValue()); 717 751 } 718 752 … … 993 1027 localMask.resize(ni*nj) ; 994 1028 localMask=false ; 995 size_t zoom_ibegin= global_zoom_ibegin ;996 size_t zoom_iend= global_zoom_ibegin+global_zoom_ni-1 ;997 size_t zoom_jbegin= global_zoom_jbegin ;998 size_t zoom_jend= global_zoom_jbegin+global_zoom_nj-1 ;1029 size_t zoom_ibegin= global_zoom_ibegin ; 1030 size_t zoom_iend= global_zoom_ibegin+global_zoom_ni-1 ; 1031 size_t zoom_jbegin= global_zoom_jbegin ; 1032 size_t zoom_jend= global_zoom_jbegin+global_zoom_nj-1 ; 999 1033 1000 1034 … … 1037 1071 if (!lonvalue_2d.isEmpty()) 1038 1072 { 1039 lonvalue _client.resize(ni * nj);1040 latvalue _client.resize(ni * nj);1073 lonvalue.resize(ni * nj); 1074 latvalue.resize(ni * nj); 1041 1075 if (hasBounds) 1042 1076 { 1043 bounds_lon _client.resize(nvertex, ni * nj);1044 bounds_lat _client.resize(nvertex, ni * nj);1077 bounds_lonvalue.resize(nvertex, ni * nj); 1078 bounds_latvalue.resize(nvertex, ni * nj); 1045 1079 } 1046 1080 … … 1051 1085 int k = j * ni + i; 1052 1086 1053 lonvalue _client(k) = lonvalue_2d(i,j);1054 latvalue _client(k) = latvalue_2d(i,j);1087 lonvalue(k) = lonvalue_2d(i,j); 1088 latvalue(k) = latvalue_2d(i,j); 1055 1089 1056 1090 if (hasBounds) … … 1058 1092 for (int n = 0; n < nvertex; ++n) 1059 1093 { 1060 bounds_lon _client(n,k) = bounds_lon_2d(n,i,j);1061 bounds_lat _client(n,k) = bounds_lat_2d(n,i,j);1094 bounds_lonvalue(n,k) = bounds_lon_2d(n,i,j); 1095 bounds_latvalue(n,k) = bounds_lat_2d(n,i,j); 1062 1096 } 1063 1097 } … … 1071 1105 if (ni == lonvalue_1d.numElements() && nj == latvalue_1d.numElements()) 1072 1106 { 1073 lonvalue _client.resize(ni * nj);1074 latvalue _client.resize(ni * nj);1107 lonvalue.resize(ni * nj); 1108 latvalue.resize(ni * nj); 1075 1109 if (hasBounds) 1076 1110 { 1077 bounds_lon _client.resize(nvertex, ni * nj);1078 bounds_lat _client.resize(nvertex, ni * nj);1111 bounds_lonvalue.resize(nvertex, ni * nj); 1112 bounds_latvalue.resize(nvertex, ni * nj); 1079 1113 } 1080 1114 … … 1085 1119 int k = j * ni + i; 1086 1120 1087 lonvalue _client(k) = lonvalue_1d(i);1088 latvalue _client(k) = latvalue_1d(j);1121 lonvalue(k) = lonvalue_1d(i); 1122 latvalue(k) = latvalue_1d(j); 1089 1123 1090 1124 if (hasBounds) … … 1092 1126 for (int n = 0; n < nvertex; ++n) 1093 1127 { 1094 bounds_lon _client(n,k) = bounds_lon_1d(n,i);1095 bounds_lat _client(n,k) = bounds_lat_1d(n,j);1128 bounds_lonvalue(n,k) = bounds_lon_1d(n,i); 1129 bounds_latvalue(n,k) = bounds_lat_1d(n,j); 1096 1130 } 1097 1131 } … … 1101 1135 else if (i_index.numElements() == lonvalue_1d.numElements() && j_index.numElements() == latvalue_1d.numElements()) 1102 1136 { 1103 lonvalue _client.reference(lonvalue_1d);1104 latvalue _client.reference(latvalue_1d);1137 lonvalue.reference(lonvalue_1d); 1138 latvalue.reference(latvalue_1d); 1105 1139 if (hasBounds) 1106 1140 { 1107 bounds_lon _client.reference(bounds_lon_1d);1108 bounds_lat _client.reference(bounds_lat_1d);1141 bounds_lonvalue.reference(bounds_lon_1d); 1142 bounds_latvalue.reference(bounds_lat_1d); 1109 1143 } 1110 1144 } … … 1120 1154 else if (type == type_attr::curvilinear || type == type_attr::unstructured) 1121 1155 { 1122 lonvalue _client.reference(lonvalue_1d);1123 latvalue _client.reference(latvalue_1d);1156 lonvalue.reference(lonvalue_1d); 1157 latvalue.reference(latvalue_1d); 1124 1158 if (hasBounds) 1125 1159 { 1126 bounds_lon _client.reference(bounds_lon_1d);1127 bounds_lat _client.reference(bounds_lat_1d);1160 bounds_lonvalue.reference(bounds_lon_1d); 1161 bounds_latvalue.reference(bounds_lat_1d); 1128 1162 } 1129 1163 } … … 1221 1255 void CDomain::checkArea(void) 1222 1256 { 1223 hasArea = !area.isEmpty() ;1257 hasArea = !area.isEmpty() || !areavalue.isEmpty(); 1224 1258 if (hasArea) 1225 1259 { … … 1231 1265 << "Local size is " << ni.getValue() << " x " << nj.getValue() << "." << std::endl 1232 1266 << "Area size is " << area.extent(0) << " x " << area.extent(1) << "."); 1267 } 1268 if (areavalue.isEmpty()) 1269 { 1270 areavalue.resize(ni*nj); 1271 for (int j = 0; j < nj; ++j) 1272 { 1273 for (int i = 0; i < ni; ++i) 1274 { 1275 int k = j * ni + i; 1276 areavalue(k) = area(i,j); 1277 } 1278 } 1233 1279 } 1234 1280 } … … 1302 1348 if (context->hasClient) 1303 1349 { 1304 this->checkMask(); 1305 if (hasLonLat || hasArea || isCompressible_) this->computeConnectedServer(); 1350 // this->checkMask(); 1351 this->computeConnectedClients(); 1352 // if (hasLonLat || hasArea || isCompressible_) this->computeConnectedClients(); 1306 1353 if (hasLonLat) this->completeLonLatClient(); 1307 1354 } … … 1318 1365 CContext* context=CContext::getCurrent(); 1319 1366 1367 if (context->hasClient && !context->hasServer) 1368 { 1369 this->checkDomain(); 1370 this->checkBounds(); 1371 this->checkArea(); 1372 this->checkLonLat(); 1373 } 1374 1375 if (context->hasClient && !context->hasServer) 1376 { // CÃŽté client uniquement 1377 this->checkMask(); 1378 this->checkDomainData(); 1379 this->checkCompression(); 1380 this->computeLocalMask() ; 1381 } 1382 else 1383 { // CÃŽté serveur uniquement 1384 } 1385 1386 this->isClientChecked = true; 1387 } 1388 1389 // Send all checked attributes to server 1390 void CDomain::sendCheckedAttributes() 1391 { 1392 if (!this->isClientChecked) checkAttributesOnClient(); 1393 if (!this->isClientAfterTransformationChecked) checkAttributesOnClientAfterTransformation(); 1394 CContext* context=CContext::getCurrent() ; 1395 1396 if (this->isChecked) return; 1397 if (context->hasClient) 1398 { 1399 sendAttributes(); 1400 } 1401 this->isChecked = true; 1402 } 1403 1404 void CDomain::checkAttributes(void) 1405 { 1406 if (this->isChecked) return; 1407 CContext* context=CContext::getCurrent() ; 1408 1320 1409 this->checkDomain(); 1410 this->checkLonLat(); 1321 1411 this->checkBounds(); 1322 1412 this->checkArea(); 1323 this->checkLonLat();1324 1413 1325 1414 if (context->hasClient) … … 1329 1418 this->checkCompression(); 1330 1419 this->computeLocalMask() ; 1420 1331 1421 } 1332 1422 else … … 1334 1424 } 1335 1425 1336 this->isClientChecked = true;1337 }1338 1339 // Send all checked attributes to server1340 void CDomain::sendCheckedAttributes()1341 {1342 if (!this->isClientChecked) checkAttributesOnClient();1343 if (!this->isClientAfterTransformationChecked) checkAttributesOnClientAfterTransformation();1344 CContext* context=CContext::getCurrent() ;1345 1346 if (this->isChecked) return;1347 if (context->hasClient)1348 {1349 sendServerAttribut();1350 if (hasLonLat || hasArea || isCompressible_) sendLonLatArea();1351 }1352 this->isChecked = true;1353 }1354 1355 void CDomain::checkAttributes(void)1356 {1357 if (this->isChecked) return;1358 CContext* context=CContext::getCurrent() ;1359 1360 this->checkDomain();1361 this->checkLonLat();1362 this->checkBounds();1363 this->checkArea();1364 1365 1426 if (context->hasClient) 1366 { // CÃŽté client uniquement 1367 this->checkMask(); 1368 this->checkDomainData(); 1369 this->checkCompression(); 1370 this->computeLocalMask() ; 1371 1372 } 1373 else 1374 { // CÃŽté serveur uniquement 1375 } 1376 1377 if (context->hasClient) 1378 { 1379 this->computeConnectedServer(); 1427 { 1428 this->computeConnectedClients(); 1380 1429 this->completeLonLatClient(); 1381 this->sendServerAttribut();1382 this->sendLonLatArea();1383 1430 } 1384 1431 … … 1386 1433 } 1387 1434 1388 void CDomain::sendServerAttribut(void) 1435 /*! 1436 Send distribution from client to other clients 1437 Because a client in a level knows correctly the grid distribution of client on the next level 1438 it calculates this distribution then sends it to the corresponding clients on the next level 1439 */ 1440 void CDomain::sendDistributionAttributes(void) 1389 1441 { 1390 1442 CContext* context = CContext::getCurrent(); … … 1394 1446 { 1395 1447 CContextClient* contextClientTmp = (context->hasServer) ? context->clientPrimServer[i] 1396 : context->client; 1397 // CContextClient* client = context->client; 1448 : context->client; 1398 1449 int nbServer = contextClientTmp->serverSize; 1399 1400 CServerDistributionDescription serverDescription(nGlobDomain_, nbServer); 1450 std::vector<int> nGlobDomain(2); 1451 nGlobDomain[0] = this->ni_glo; 1452 nGlobDomain[1] = this->nj_glo; 1453 1454 CServerDistributionDescription serverDescription(nGlobDomain, nbServer); 1401 1455 if (isUnstructed_) serverDescription.computeServerDistribution(false, 0); 1402 1456 else serverDescription.computeServerDistribution(false, 1); … … 1418 1472 const int ni_srv = serverDimensionSizes[*itRank][0]; 1419 1473 const int nj_srv = serverDimensionSizes[*itRank][1]; 1420 const int iend_srv = ibegin_srv + ni_srv - 1;1421 const int jend_srv = jbegin_srv + nj_srv - 1;1422 1474 1423 1475 msgs.push_back(CMessage()); 1424 1476 CMessage& msg = msgs.back(); 1425 1477 msg << this->getId() ; 1426 msg << ni_srv << ibegin_srv << iend_srv << nj_srv << jbegin_srv << jend_srv; 1427 msg << global_zoom_ni.getValue() << global_zoom_ibegin.getValue() << global_zoom_nj.getValue() << global_zoom_jbegin.getValue(); 1478 msg << ni_srv << ibegin_srv << nj_srv << jbegin_srv; 1428 1479 msg << isCompressible_; 1429 1480 … … 1436 1487 } 1437 1488 1438 void CDomain::computeNGlobDomain() 1439 { 1440 nGlobDomain_.resize(2); 1441 nGlobDomain_[0] = ni_glo.getValue(); 1442 nGlobDomain_[1] = nj_glo.getValue(); 1443 } 1444 1445 void CDomain::computeConnectedServer(void) 1489 // void CDomain::computeConnectedClients(const std::vector<int>& globalDim, int orderPositionInGrid, 1490 // CServerDistributionDescription::ServerDistributionType distType) 1491 /*! 1492 Compute the connection of a client to other clients to determine which clients to send attributes to 1493 */ 1494 void CDomain::computeConnectedClients() 1446 1495 { 1447 1496 CContext* context=CContext::getCurrent() ; 1448 CContextClient* client =context->client;1497 CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 1449 1498 int nbServer=client->serverSize; 1450 1499 int rank = client->clientRank; 1451 1500 bool doComputeGlobalIndexServer = true; 1452 1501 1453 int i,j,i_ind,j_ind, nbIndex ;1502 int i,j,i_ind,j_ind, nbIndex, nbIndexZoom; 1454 1503 int global_zoom_iend=global_zoom_ibegin+global_zoom_ni-1 ; 1455 1504 int global_zoom_jend=global_zoom_jbegin+global_zoom_nj-1 ; … … 1458 1507 int globalIndexCountZoom = 0; 1459 1508 nbIndex = i_index.numElements(); 1460 for (i = 0; i < nbIndex; ++i)1461 {1462 i_ind=i_index(i);1463 j_ind=j_index(i);1464 1465 if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend)1466 {1467 ++globalIndexCountZoom;1468 }1469 }1470 1471 int globalIndexWrittenCount = 0;1472 if (isCompressible_)1473 {1474 for (i = 0; i < data_i_index.numElements(); ++i)1475 {1476 i_ind = CDistributionClient::getDomainIndex(data_i_index(i), data_j_index(i),1477 data_ibegin, data_jbegin, data_dim, ni,1478 j_ind);1479 if (i_ind >= 0 && i_ind < ni && j_ind >= 0 && j_ind < nj && mask_1d(i_ind + j_ind * ni))1480 {1481 i_ind += ibegin;1482 j_ind += jbegin;1483 if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend)1484 ++globalIndexWrittenCount;1485 }1486 }1487 }1509 // for (i = 0; i < nbIndex; ++i) 1510 // { 1511 // i_ind=i_index(i); 1512 // j_ind=j_index(i); 1513 1514 // if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 1515 // { 1516 // ++globalIndexCountZoom; 1517 // } 1518 // } 1519 1520 // int globalIndexWrittenCount = 0; 1521 // if (isCompressible_) 1522 // { 1523 // for (i = 0; i < data_i_index.numElements(); ++i) 1524 // { 1525 // i_ind = CDistributionClient::getDomainIndex(data_i_index(i), data_j_index(i), 1526 // data_ibegin, data_jbegin, data_dim, ni, 1527 // j_ind); 1528 // if (i_ind >= 0 && i_ind < ni && j_ind >= 0 && j_ind < nj && mask_1d(i_ind + j_ind * ni)) 1529 // { 1530 // i_ind += ibegin; 1531 // j_ind += jbegin; 1532 // if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 1533 // ++globalIndexWrittenCount; 1534 // } 1535 // } 1536 // } 1488 1537 1489 1538 // Fill in index 1490 CArray<size_t,1> globalIndexDomainZoom(globalIndexCountZoom);1539 1491 1540 CArray<size_t,1> localIndexDomainZoom(globalIndexCountZoom); 1492 1541 CArray<size_t,1> globalIndexDomain(nbIndex); 1493 1542 size_t globalIndex; 1494 1543 int globalIndexCount = 0; 1495 globalIndexCountZoom = 0;1544 1496 1545 1497 1546 for (i = 0; i < nbIndex; ++i) … … 1501 1550 globalIndex = i_ind + j_ind * ni_glo; 1502 1551 globalIndexDomain(globalIndexCount) = globalIndex; 1552 globalLocalIndexMap_[globalIndex] = i; 1503 1553 ++globalIndexCount; 1504 if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 1505 { 1506 globalIndexDomainZoom(globalIndexCountZoom) = globalIndex; 1507 localIndexDomainZoom(globalIndexCountZoom) = i; 1508 ++globalIndexCountZoom; 1509 } 1510 } 1511 1512 CArray<int,1> globalIndexWrittenDomain(globalIndexWrittenCount); 1513 if (isCompressible_) 1514 { 1515 globalIndexWrittenCount = 0; 1516 for (i = 0; i < data_i_index.numElements(); ++i) 1517 { 1518 i_ind = CDistributionClient::getDomainIndex(data_i_index(i), data_j_index(i), 1519 data_ibegin, data_jbegin, data_dim, ni, 1520 j_ind); 1521 if (i_ind >= 0 && i_ind < ni && j_ind >= 0 && j_ind < nj && mask_1d(i_ind + j_ind * ni)) 1522 { 1523 i_ind += ibegin; 1524 j_ind += jbegin; 1525 if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 1526 { 1527 globalIndexWrittenDomain(globalIndexWrittenCount) = i_ind + j_ind * ni_glo; 1528 ++globalIndexWrittenCount; 1529 } 1530 } 1531 } 1532 } 1554 } 1555 1556 nbIndexZoom = zoom_i_index.numElements(); 1557 CArray<size_t,1> globalIndexDomainZoom(nbIndexZoom); 1558 globalIndexCountZoom = 0; 1559 for (i = 0; i < nbIndexZoom; ++i) 1560 { 1561 i_ind=zoom_i_index(i); 1562 j_ind=zoom_j_index(i); 1563 globalIndex = i_ind + j_ind * ni_glo; 1564 globalIndexDomainZoom(globalIndexCountZoom) = globalIndex; 1565 1566 ++globalIndexCountZoom; 1567 // if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 1568 // { 1569 // globalIndexDomainZoom(globalIndexCountZoom) = globalIndex; 1570 // localIndexDomainZoom(globalIndexCountZoom) = i; 1571 // ++globalIndexCountZoom; 1572 // } 1573 } 1574 1575 // CArray<int,1> globalIndexWrittenDomain(globalIndexWrittenCount); 1576 // if (isCompressible_) 1577 // { 1578 // globalIndexWrittenCount = 0; 1579 // for (i = 0; i < data_i_index.numElements(); ++i) 1580 // { 1581 // i_ind = CDistributionClient::getDomainIndex(data_i_index(i), data_j_index(i), 1582 // data_ibegin, data_jbegin, data_dim, ni, 1583 // j_ind); 1584 // if (i_ind >= 0 && i_ind < ni && j_ind >= 0 && j_ind < nj && mask_1d(i_ind + j_ind * ni)) 1585 // { 1586 // i_ind += ibegin; 1587 // j_ind += jbegin; 1588 // if (i_ind >= global_zoom_ibegin && i_ind <= global_zoom_iend && j_ind >= global_zoom_jbegin && j_ind <= global_zoom_jend) 1589 // { 1590 // globalIndexWrittenDomain(globalIndexWrittenCount) = i_ind + j_ind * ni_glo; 1591 // ++globalIndexWrittenCount; 1592 // } 1593 // } 1594 // } 1595 // } 1533 1596 1534 1597 size_t globalSizeIndex = 1, indexBegin, indexEnd; 1535 1598 int range, clientSize = client->clientSize; 1536 for (int i = 0; i < nGlobDomain_.size(); ++i) globalSizeIndex *= nGlobDomain_[i]; 1599 std::vector<int> nGlobDomain(2); 1600 nGlobDomain[0] = this->ni_glo; 1601 nGlobDomain[1] = this->nj_glo; 1602 for (int i = 0; i < nGlobDomain.size(); ++i) globalSizeIndex *= nGlobDomain[i]; 1537 1603 indexBegin = 0; 1538 1604 if (globalSizeIndex <= clientSize) … … 1553 1619 } 1554 1620 1555 CServerDistributionDescription serverDescription(nGlobDomain _, nbServer);1621 CServerDistributionDescription serverDescription(nGlobDomain, nbServer); 1556 1622 if (isUnstructed_) serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd), 0); 1557 1623 else serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd), 1); … … 1560 1626 client->intraComm); 1561 1627 clientServerMap->computeServerIndexMapping(globalIndexDomain); 1562 constCClientServerMapping::GlobalIndexMap& globalIndexDomainOnServer = clientServerMap->getGlobalIndexOnServer();1628 CClientServerMapping::GlobalIndexMap& globalIndexDomainOnServer = clientServerMap->getGlobalIndexOnServer(); 1563 1629 1564 1630 CClientServerMapping::GlobalIndexMap::const_iterator it = globalIndexDomainOnServer.begin(), 1565 1631 ite = globalIndexDomainOnServer.end(); 1566 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch;1567 std::vector<int>::iterator itVec;1568 1569 indSrv_.clear();1570 indWrittenSrv_.clear();1571 for (; it != ite; ++it)1572 {1573 int rank = it->first;1574 int indexSize = it->second.size();1575 std::vector<int> permutIndex(indexSize);1576 XIOSAlgorithms::fillInIndex(indexSize, permutIndex);1577 XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(it->second, permutIndex);1578 BinarySearch binSearch(it->second);1579 int nb = globalIndexDomainZoom.numElements();1580 for (int i = 0; i < nb; ++i)1581 {1582 if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexDomainZoom(i), itVec))1583 {1584 indSrv_[rank].push_back(localIndexDomainZoom(i));1585 }1586 }1587 for (int i = 0; i < globalIndexWrittenDomain.numElements(); ++i)1588 {1589 if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexWrittenDomain(i), itVec))1590 {1591 indWrittenSrv_[rank].push_back(globalIndexWrittenDomain(i));1592 }1593 }1594 }1632 // typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 1633 // std::vector<int>::iterator itVec; 1634 1635 // indSrv_.clear(); 1636 // indWrittenSrv_.clear(); 1637 // for (; it != ite; ++it) 1638 // { 1639 // int rank = it->first; 1640 // int indexSize = it->second.size(); 1641 // std::vector<int> permutIndex(indexSize); 1642 // XIOSAlgorithms::fillInIndex(indexSize, permutIndex); 1643 // XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(it->second, permutIndex); 1644 // BinarySearch binSearch(it->second); 1645 // int nb = globalIndexDomainZoom.numElements(); 1646 // for (int i = 0; i < nb; ++i) 1647 // { 1648 // if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexDomainZoom(i), itVec)) 1649 // { 1650 // indSrv_[rank].push_back(localIndexDomainZoom(i)); 1651 // } 1652 // } 1653 // for (int i = 0; i < globalIndexWrittenDomain.numElements(); ++i) 1654 // { 1655 // if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexWrittenDomain(i), itVec)) 1656 // { 1657 // indWrittenSrv_[rank].push_back(globalIndexWrittenDomain(i)); 1658 // } 1659 // } 1660 // } 1595 1661 1596 1662 connectedServerRank_.clear(); … … 1599 1665 } 1600 1666 1667 indSrv_.swap(globalIndexDomainOnServer); 1601 1668 nbConnectedClients_ = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 1602 1669 1670 clientServerMap->computeServerIndexMapping(globalIndexDomainZoom); 1671 CClientServerMapping::GlobalIndexMap& globalIndexDomainZoomOnServer = clientServerMap->getGlobalIndexOnServer(); 1672 indZoomSrv_.swap(globalIndexDomainZoomOnServer); 1673 std::vector<int> connectedServerZoomRank(indZoomSrv_.size()); 1674 for (it = indZoomSrv_.begin(); it != indZoomSrv_.end(); ++it) 1675 connectedServerZoomRank.push_back(it->first); 1676 nbConnectedClientsZoom_ = clientServerMap->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerZoomRank); 1677 1603 1678 delete clientServerMap; 1604 1679 } 1605 1680 1606 const std::map<int, vector<size_t> >& CDomain::getIndexServer() const1681 const boost::unordered_map<int, vector<size_t> >& CDomain::getIndexServer() const 1607 1682 { 1608 1683 return indSrv_; … … 1610 1685 1611 1686 /*! 1612 Send index from client to server(s) 1687 Send all attributes from client to connected clients 1688 The attributes will be rebuilt on receiving side 1689 */ 1690 void CDomain::sendAttributes() 1691 { 1692 sendIndex(); 1693 sendDistributionAttributes(); 1694 sendMask(); 1695 sendLonLat(); 1696 sendArea(); 1697 sendDataIndex(); 1698 } 1699 1700 /*! 1701 Send global index and zoom index from client to connected client(s) 1702 zoom index can be smaller than global index 1613 1703 */ 1614 1704 void CDomain::sendIndex() … … 1616 1706 int ns, n, i, j, ind, nv, idx; 1617 1707 CContext* context = CContext::getCurrent(); 1618 CContextClient* client =context->client;1708 CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 1619 1709 1620 1710 CEventClient eventIndex(getType(), EVENT_ID_INDEX); 1621 1711 1622 1712 list<CMessage> list_msgsIndex; 1623 list<CArray<int,1> > list_indi, list_indj, list_writtenInd; 1624 1625 std::map<int, std::vector<size_t> >::const_iterator it, iteMap; 1713 list<CArray<int,1> > list_indZoom, list_writtenInd, list_indGlob; 1714 1715 boost::unordered_map<int, vector<size_t> >::const_iterator itIndex, iteIndex, itZoom, iteZoom; 1716 iteIndex = indSrv_.end(); iteZoom = indZoomSrv_.end(); 1717 for (int k = 0; k < connectedServerRank_.size(); ++k) 1718 { 1719 int nbIndGlob = 0; 1720 int rank = connectedServerRank_[k]; 1721 itIndex = indSrv_.find(rank); 1722 if (iteIndex != itIndex) 1723 nbIndGlob = itIndex->second.size(); 1724 int nbIndZoom = 0; 1725 itZoom = indZoomSrv_.find(rank); 1726 if (iteZoom != itZoom) 1727 nbIndZoom = itZoom->second.size(); 1728 1729 list_indGlob.push_back(CArray<int,1>(nbIndGlob)); 1730 list_indZoom.push_back(CArray<int,1>(nbIndZoom)); 1731 1732 CArray<int,1>& indZoom = list_indZoom.back(); 1733 CArray<int,1>& indGlob = list_indGlob.back(); 1734 for (n = 0; n < nbIndGlob; ++n) 1735 { 1736 indGlob(n) = static_cast<int>(itIndex->second[n]); 1737 } 1738 1739 for (n = 0; n < nbIndZoom; ++n) 1740 { 1741 indZoom(n) = static_cast<int>(itZoom->second[n]); 1742 } 1743 1744 list_msgsIndex.push_back(CMessage()); 1745 list_msgsIndex.back() << this->getId() << (int)type; // enum ne fonctionne pour les message => ToFix 1746 list_msgsIndex.back() << isCurvilinear; 1747 list_msgsIndex.back() << list_indGlob.back() << list_indZoom.back(); //list_indi.back() << list_indj.back(); 1748 1749 // if (isCompressible_) 1750 // { 1751 // std::vector<int>& writtenIndSrc = indWrittenSrv_[rank]; 1752 // list_writtenInd.push_back(CArray<int,1>(writtenIndSrc.size())); 1753 // CArray<int,1>& writtenInd = list_writtenInd.back(); 1754 1755 // for (n = 0; n < writtenInd.numElements(); ++n) 1756 // writtenInd(n) = writtenIndSrc[n]; 1757 1758 // list_msgsIndex.back() << writtenInd; 1759 // } 1760 1761 eventIndex.push(rank, nbConnectedClients_[rank], list_msgsIndex.back()); 1762 } 1763 1764 client->sendEvent(eventIndex); 1765 } 1766 1767 /*! 1768 Send mask index from client to connected(s) 1769 */ 1770 void CDomain::sendMask() 1771 { 1772 int ns, n, i, j, ind, nv, idx; 1773 CContext* context = CContext::getCurrent(); 1774 CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 1775 1776 // send area for each connected server 1777 CEventClient eventMask(getType(), EVENT_ID_MASK); 1778 1779 list<CMessage> list_msgsMask; 1780 list<CArray<bool,1> > list_mask; 1781 1782 boost::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; 1626 1783 iteMap = indSrv_.end(); 1627 1784 for (int k = 0; k < connectedServerRank_.size(); ++k) … … 1632 1789 if (iteMap != it) 1633 1790 nbData = it->second.size(); 1634 1635 list_indi.push_back(CArray<int,1>(nbData)); 1636 list_indj.push_back(CArray<int,1>(nbData)); 1637 1638 CArray<int,1>& indi = list_indi.back(); 1639 CArray<int,1>& indj = list_indj.back(); 1791 list_mask.push_back(CArray<bool,1>(nbData)); 1792 1640 1793 const std::vector<size_t>& temp = it->second; 1641 1794 for (n = 0; n < nbData; ++n) 1642 1795 { 1643 1796 idx = static_cast<int>(it->second[n]); 1644 indi(n) = i_index(idx); 1645 indj(n) = j_index(idx); 1646 } 1647 1648 list_msgsIndex.push_back(CMessage()); 1649 1650 list_msgsIndex.back() << this->getId() << (int)type; // enum ne fonctionne pour les message => ToFix 1651 list_msgsIndex.back() << isCurvilinear; 1652 list_msgsIndex.back() << list_indi.back() << list_indj.back(); 1653 1654 if (isCompressible_) 1655 { 1656 std::vector<int>& writtenIndSrc = indWrittenSrv_[rank]; 1657 list_writtenInd.push_back(CArray<int,1>(writtenIndSrc.size())); 1658 CArray<int,1>& writtenInd = list_writtenInd.back(); 1659 1660 for (n = 0; n < writtenInd.numElements(); ++n) 1661 writtenInd(n) = writtenIndSrc[n]; 1662 1663 list_msgsIndex.back() << writtenInd; 1664 } 1665 1666 eventIndex.push(rank, nbConnectedClients_[rank], list_msgsIndex.back()); 1667 } 1668 1669 client->sendEvent(eventIndex); 1797 list_mask.back()(n) = mask_1d(globalLocalIndexMap_[idx]); 1798 } 1799 1800 list_msgsMask.push_back(CMessage()); 1801 list_msgsMask.back() << this->getId() << list_mask.back(); 1802 eventMask.push(rank, nbConnectedClients_[rank], list_msgsMask.back()); 1803 } 1804 client->sendEvent(eventMask); 1670 1805 } 1671 1806 1672 1807 /*! 1673 Send area from client to server(s)1808 Send area from client to connected client(s) 1674 1809 */ 1675 1810 void CDomain::sendArea() … … 1679 1814 int ns, n, i, j, ind, nv, idx; 1680 1815 CContext* context = CContext::getCurrent(); 1681 CContextClient* client =context->client;1816 CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 1682 1817 1683 1818 // send area for each connected server … … 1687 1822 list<CArray<double,1> > list_area; 1688 1823 1689 std::map<int, std::vector<size_t> >::const_iterator it, iteMap;1824 boost::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; 1690 1825 iteMap = indSrv_.end(); 1691 1826 for (int k = 0; k < connectedServerRank_.size(); ++k) … … 1702 1837 { 1703 1838 idx = static_cast<int>(it->second[n]); 1704 i = i_index(idx); 1705 j = j_index(idx); 1706 if (hasArea) 1707 list_area.back()(n) = area(i - ibegin, j - jbegin); 1839 list_area.back()(n) = areavalue(globalLocalIndexMap_[idx]); 1708 1840 } 1709 1841 1710 1842 list_msgsArea.push_back(CMessage()); 1711 list_msgsArea.back() << this->getId() << list_area.back(); 1843 list_msgsArea.back() << this->getId() << hasArea; 1844 list_msgsArea.back() << list_area.back(); 1712 1845 eventArea.push(rank, nbConnectedClients_[rank], list_msgsArea.back()); 1713 1846 } … … 1726 1859 int ns, n, i, j, ind, nv, idx; 1727 1860 CContext* context = CContext::getCurrent(); 1728 CContextClient* client =context->client;1861 CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 1729 1862 1730 1863 // send lon lat for each connected server … … 1736 1869 list<CArray<double,2> > list_boundslon, list_boundslat; 1737 1870 1738 std::map<int, std::vector<size_t> >::const_iterator it, iteMap;1871 boost::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; 1739 1872 iteMap = indSrv_.end(); 1740 1873 for (int k = 0; k < connectedServerRank_.size(); ++k) … … 1761 1894 { 1762 1895 idx = static_cast<int>(it->second[n]); 1763 lon(n) = lonvalue_client(idx); 1764 lat(n) = latvalue_client(idx); 1896 int localInd = globalLocalIndexMap_[idx]; 1897 lon(n) = lonvalue(localInd); 1898 lat(n) = latvalue(localInd); 1765 1899 1766 1900 if (hasBounds) … … 1771 1905 for (nv = 0; nv < nvertex; ++nv) 1772 1906 { 1773 boundslon(nv, n) = bounds_lon _client(nv, idx);1774 boundslat(nv, n) = bounds_lat _client(nv, idx);1907 boundslon(nv, n) = bounds_lonvalue(nv, localInd); 1908 boundslat(nv, n) = bounds_latvalue(nv, localInd); 1775 1909 } 1776 1910 } … … 1780 1914 list_msgsLat.push_back(CMessage()); 1781 1915 1782 list_msgsLon.back() << this->getId() << list_lon.back();1783 list_msgsLat.back() << this->getId() << list_lat.back();1916 list_msgsLon.back() << this->getId() << hasLonLat << list_lon.back() << hasBounds; 1917 list_msgsLat.back() << this->getId() << hasLonLat << list_lat.back() << hasBounds; 1784 1918 1785 1919 if (hasBounds) … … 1798 1932 1799 1933 /*! 1800 Send some optional information to server(s) 1801 In the future, this function can be extended with more optional information to send 1934 Send data index to corresponding connected clients. 1935 Data index can be compressed however, we always send decompressed data index 1936 and they will be compressed on receiving. 1802 1937 */ 1803 void CDomain::sendLonLatArea(void) 1804 { 1805 sendIndex(); 1806 sendLonLat(); 1807 sendArea(); 1808 } 1809 1938 void CDomain::sendDataIndex() 1939 { 1940 int ns, n, i, j, ind, nv, idx; 1941 CContext* context = CContext::getCurrent(); 1942 CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; 1943 1944 // send area for each connected server 1945 CEventClient eventDataIndex(getType(), EVENT_ID_DATA_INDEX); 1946 1947 list<CMessage> list_msgsDataIndex; 1948 list<CArray<int,1> > list_data_i_index, list_data_j_index; 1949 1950 int nbIndex = i_index.numElements(); 1951 CArray<int,1> dataIIndex(nbIndex), dataJIndex(nbIndex); 1952 dataIIndex = -1; dataJIndex = -1, ind = 0; 1953 for (idx = 0; idx < data_i_index.numElements(); ++idx) 1954 { 1955 if ((0 <= data_i_index(idx)) && (data_i_index(idx) < ni) && (ind < nbIndex)) 1956 { 1957 dataIIndex(ind) = data_i_index(idx); 1958 dataJIndex(ind) = data_j_index(idx); 1959 ++ind; 1960 } 1961 } 1962 1963 boost::unordered_map<int, vector<size_t> >::const_iterator it, iteMap; 1964 iteMap = indSrv_.end(); 1965 for (int k = 0; k < connectedServerRank_.size(); ++k) 1966 { 1967 int nbData = 0; 1968 int rank = connectedServerRank_[k]; 1969 it = indSrv_.find(rank); 1970 if (iteMap != it) 1971 nbData = it->second.size(); 1972 list_data_i_index.push_back(CArray<int,1>(nbData)); 1973 list_data_j_index.push_back(CArray<int,1>(nbData)); 1974 1975 const std::vector<size_t>& temp = it->second; 1976 for (n = 0; n < nbData; ++n) 1977 { 1978 idx = static_cast<int>(it->second[n]); 1979 i = globalLocalIndexMap_[idx]; 1980 list_data_i_index.back()(n) = dataIIndex(i); 1981 list_data_j_index.back()(n) = dataJIndex(i); 1982 } 1983 1984 list_msgsDataIndex.push_back(CMessage()); 1985 list_msgsDataIndex.back() << this->getId(); 1986 list_msgsDataIndex.back() << list_data_i_index.back() << list_data_j_index.back(); 1987 eventDataIndex.push(rank, nbConnectedClients_[rank], list_msgsDataIndex.back()); 1988 } 1989 client->sendEvent(eventDataIndex); 1990 } 1991 1810 1992 bool CDomain::dispatchEvent(CEventServer& event) 1811 1993 { … … 1816 1998 { 1817 1999 case EVENT_ID_SERVER_ATTRIBUT: 1818 recv ServerAttribut(event);2000 recvDistributionAttributes(event); 1819 2001 return true; 1820 2002 break; 1821 2003 case EVENT_ID_INDEX: 1822 2004 recvIndex(event); 2005 return true; 2006 break; 2007 case EVENT_ID_MASK: 2008 recvMask(event); 1823 2009 return true; 1824 2010 break; … … 1834 2020 recvArea(event); 1835 2021 return true; 2022 break; 2023 case EVENT_ID_DATA_INDEX: 2024 recvDataIndex(event); 2025 return true; 1836 2026 break; 1837 2027 default: … … 1847 2037 \param[in] event event contain info about rank and associated attributes 1848 2038 */ 1849 void CDomain::recv ServerAttribut(CEventServer& event)2039 void CDomain::recvDistributionAttributes(CEventServer& event) 1850 2040 { 1851 2041 CBufferIn* buffer=event.subEvents.begin()->buffer; 1852 2042 string domainId ; 1853 2043 *buffer>>domainId ; 1854 get(domainId)->recvServerAttribut(*buffer) ; 1855 1856 CContext* context = CContext::getCurrent(); 1857 if (context->hasClient && context->hasServer) 1858 { 1859 get(domainId)->sendServerAttribut(); 1860 } 1861 2044 get(domainId)->recvDistributionAttributes(*buffer) ; 1862 2045 } 1863 2046 … … 1867 2050 \param[in] buffer message containing attributes info 1868 2051 */ 1869 void CDomain::recvServerAttribut(CBufferIn& buffer) 1870 { 1871 int global_zoom_ni_tmp, global_zoom_ibegin_tmp, global_zoom_nj_tmp, global_zoom_jbegin_tmp; 1872 buffer >> ni_srv >> ibegin_srv >> iend_srv >> nj_srv >> jbegin_srv >> jend_srv 1873 >> global_zoom_ni_tmp >> global_zoom_ibegin_tmp >> global_zoom_nj_tmp >> global_zoom_jbegin_tmp 2052 void CDomain::recvDistributionAttributes(CBufferIn& buffer) 2053 { 2054 int ni_tmp, ibegin_tmp, nj_tmp, jbegin_tmp; 2055 buffer >> ni_tmp >> ibegin_tmp >> nj_tmp >> jbegin_tmp 1874 2056 >> isCompressible_; 1875 1876 global_zoom_ni.setValue(global_zoom_ni_tmp); 1877 global_zoom_ibegin.setValue(global_zoom_ibegin_tmp); 1878 global_zoom_nj.setValue(global_zoom_nj_tmp); 1879 global_zoom_jbegin.setValue(global_zoom_jbegin_tmp); 1880 1881 int zoom_iend = global_zoom_ibegin + global_zoom_ni - 1; 1882 int zoom_jend = global_zoom_jbegin + global_zoom_nj - 1; 1883 1884 zoom_ibegin_srv = global_zoom_ibegin > ibegin_srv ? global_zoom_ibegin : ibegin_srv ; 1885 zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; 1886 zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; 1887 1888 zoom_jbegin_srv = global_zoom_jbegin > jbegin_srv ? global_zoom_jbegin : jbegin_srv ; 1889 zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; 1890 zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; 1891 1892 if (zoom_ni_srv<=0 || zoom_nj_srv<=0) 1893 { 1894 zoom_ibegin_srv=0 ; zoom_iend_srv=0 ; zoom_ni_srv=0 ; 1895 zoom_jbegin_srv=0 ; zoom_jend_srv=0 ; zoom_nj_srv=0 ; 1896 } 1897 lonvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; 1898 lonvalue_srv = 0. ; 1899 latvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; 1900 latvalue_srv = 0. ; 1901 if (hasBounds) 1902 { 1903 bounds_lon_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; 1904 bounds_lon_srv = 0. ; 1905 bounds_lat_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; 1906 bounds_lat_srv = 0. ; 1907 } 1908 1909 if (hasArea) 1910 { 1911 area_srv.resize(zoom_ni_srv * zoom_nj_srv); 1912 area_srv = 0.; 1913 } 1914 2057 ni.setValue(ni_tmp); 2058 ibegin.setValue(ibegin_tmp); 2059 nj.setValue(nj_tmp); 2060 jbegin.setValue(jbegin_tmp); 1915 2061 } 1916 2062 … … 1921 2067 void CDomain::recvIndex(CEventServer& event) 1922 2068 { 1923 CDomain* domain; 2069 string domainId; 2070 std::map<int, CBufferIn*> rankBuffers; 1924 2071 1925 2072 list<CEventServer::SSubEvent>::iterator it; 1926 2073 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 1927 { 2074 { 1928 2075 CBufferIn* buffer = it->buffer; 1929 string domainId;1930 2076 *buffer >> domainId; 1931 domain = get(domainId);1932 domain->recvIndex(it->rank, *buffer);1933 }1934 1935 if (domain->isCompressible_)1936 {1937 std::sort(domain->indexesToWrite.begin(), domain->indexesToWrite.end());1938 1939 CContextServer* server = CContext::getCurrent()->server;1940 domain->numberWrittenIndexes_ = domain->indexesToWrite.size();1941 MPI_Allreduce(&domain->numberWrittenIndexes_, &domain->totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm);1942 MPI_Scan(&domain->numberWrittenIndexes_, &domain->offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm);1943 domain->offsetWrittenIndexes_ -= domain->numberWrittenIndexes_;1944 }2077 rankBuffers[it->rank] = buffer; 2078 } 2079 get(domainId)->recvIndex(rankBuffers); 2080 2081 // if (domain->isCompressible_) 2082 // { 2083 // std::sort(domain->indexesToWrite.begin(), domain->indexesToWrite.end()); 2084 2085 // CContextServer* server = CContext::getCurrent()->server; 2086 // domain->numberWrittenIndexes_ = domain->indexesToWrite.size(); 2087 // MPI_Allreduce(&domain->numberWrittenIndexes_, &domain->totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 2088 // MPI_Scan(&domain->numberWrittenIndexes_, &domain->offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 2089 // domain->offsetWrittenIndexes_ -= domain->numberWrittenIndexes_; 2090 // } 1945 2091 } 1946 2092 1947 2093 /*! 1948 2094 Receive index information from client(s) 1949 \param[in] rank rank of client source 1950 \param[in] buffer message containing index info 2095 \param[in] rankBuffers rank of sending client and the corresponding receive buffer 1951 2096 */ 1952 void CDomain::recvIndex(int rank, CBufferIn& buffer) 1953 { 1954 int type_int; 1955 buffer >> type_int >> isCurvilinear >> indiSrv[rank] >> indjSrv[rank]; 1956 type.setValue((type_attr::t_enum)type_int); // probleme des type enum avec les buffers : ToFix 1957 1958 if (isCompressible_) 1959 { 1960 CArray<int, 1> writtenIndexes; 1961 buffer >> writtenIndexes; 1962 indexesToWrite.reserve(indexesToWrite.size() + writtenIndexes.numElements()); 1963 for (int i = 0; i < writtenIndexes.numElements(); ++i) 1964 indexesToWrite.push_back(writtenIndexes(i)); 1965 } 2097 void CDomain::recvIndex(std::map<int, CBufferIn*>& rankBuffers) 2098 { 2099 int nbReceived = rankBuffers.size(), i, ind, index, type_int; 2100 recvClientRanks_.resize(nbReceived); 2101 vector<CArray<int,1> > recvZoomInd(nbReceived); 2102 2103 std::map<int, CBufferIn*>::iterator it = rankBuffers.begin(), ite = rankBuffers.end(); 2104 ind = 0; 2105 for (ind = 0; it != ite; ++it, ++ind) 2106 { 2107 recvClientRanks_[ind] = it->first; 2108 CBufferIn& buffer = *(it->second); 2109 buffer >> type_int >> isCurvilinear >> indGlob_[it->first] >> recvZoomInd[ind]; //recvIndGlob[ind]; 2110 type.setValue((type_attr::t_enum)type_int); // probleme des type enum avec les buffers : ToFix 2111 } 2112 int nbIndGlob = 0; 2113 for (i = 0; i < nbReceived; ++i) 2114 { 2115 nbIndGlob += indGlob_[recvClientRanks_[i]].numElements(); 2116 } 2117 2118 i_index.resize(nbIndGlob); 2119 j_index.resize(nbIndGlob); 2120 2121 nbIndGlob = 0; 2122 for (i = 0; i < nbReceived; ++i) 2123 { 2124 CArray<int,1>& tmp = indGlob_[recvClientRanks_[i]]; 2125 for (ind = 0; ind < tmp.numElements(); ++ind) 2126 { 2127 index = tmp(ind); 2128 i_index(nbIndGlob) = index / ni_glo; 2129 j_index(nbIndGlob) = index % ni_glo; 2130 ++nbIndGlob; 2131 } 2132 } 2133 2134 int nbZoomInd = 0; 2135 for (i = 0; i < nbReceived; ++i) 2136 { 2137 nbZoomInd += recvZoomInd[i].numElements(); 2138 } 2139 2140 zoom_i_index.resize(nbZoomInd); 2141 zoom_j_index.resize(nbZoomInd); 2142 2143 nbZoomInd = 0; 2144 for (i = 0; i < nbReceived; ++i) 2145 { 2146 CArray<int,1>& tmp = recvZoomInd[i]; 2147 for (ind = 0; ind < tmp.numElements(); ++ind) 2148 { 2149 index = tmp(ind); 2150 zoom_i_index(nbZoomInd) = index / ni_glo; 2151 zoom_j_index(nbZoomInd) = index % ni_glo; 2152 ++nbZoomInd; 2153 } 2154 } 2155 2156 { 2157 CContextServer* server = CContext::getCurrent()->server; 2158 count_write_index_.resize(2); 2159 start_write_index_.resize(2); 2160 local_write_size_.resize(2); 2161 global_write_size_.resize(2); 2162 if ((this->type) == CDomain::type_attr::unstructured) 2163 { 2164 count_write_index_[0] = zoom_i_index.numElements(); 2165 count_write_index_[1] = 0; 2166 } 2167 else 2168 { 2169 int ni_zoom = zoom_i_index.numElements(), idx, nbIZoom = 0, nbJZoom = 0; 2170 for (idx =0; idx < ni_zoom; ++idx) 2171 { 2172 if ((ibegin <= zoom_i_index(idx)) && (zoom_i_index(idx) < ibegin+ni) && (nbIZoom < ni)) 2173 ++nbIZoom; 2174 if ((jbegin <= zoom_j_index(idx)) && (zoom_j_index(idx) < jbegin+nj) && (nbJZoom < nj)) 2175 ++nbJZoom; 2176 } 2177 count_write_index_[0] = nbIZoom; 2178 count_write_index_[1] = nbJZoom; 2179 } 2180 2181 MPI_Scan(&count_write_index_[0], &start_write_index_[0], 2, MPI_INT, MPI_SUM, server->intraComm); 2182 start_write_index_[0] = 0; 2183 start_write_index_[1] -= count_write_index_[1]; 2184 local_write_size_[0] = count_write_index_[0]; 2185 local_write_size_[1] = count_write_index_[1]; 2186 MPI_Allreduce(&count_write_index_[0], &global_write_size_[0], 2, MPI_INT, MPI_SUM, server->intraComm); 2187 global_write_size_[0] = count_write_index_[0]; 2188 global_write_size_[1] = (global_write_size_[1] > nj_glo) ? nj_glo : global_write_size_[1]; 2189 2190 } 2191 2192 // int type_int; 2193 // buffer >> type_int >> isCurvilinear >> indiSrv[rank] >> indjSrv[rank]; 2194 // type.setValue((type_attr::t_enum)type_int); // probleme des type enum avec les buffers : ToFix 2195 2196 // if (isCompressible_) 2197 // { 2198 // CArray<int, 1> writtenIndexes; 2199 // buffer >> writtenIndexes; 2200 // indexesToWrite.reserve(indexesToWrite.size() + writtenIndexes.numElements()); 2201 // for (int i = 0; i < writtenIndexes.numElements(); ++i) 2202 // indexesToWrite.push_back(writtenIndexes(i)); 2203 // } 2204 } 2205 2206 /*! 2207 Receive area event from clients(s) 2208 \param[in] event event contain info about rank and associated area 2209 */ 2210 void CDomain::recvMask(CEventServer& event) 2211 { 2212 string domainId; 2213 std::map<int, CBufferIn*> rankBuffers; 2214 2215 list<CEventServer::SSubEvent>::iterator it; 2216 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 2217 { 2218 CBufferIn* buffer = it->buffer; 2219 *buffer >> domainId; 2220 rankBuffers[it->rank] = buffer; 2221 } 2222 get(domainId)->recvMask(rankBuffers); 2223 } 2224 2225 2226 /*! 2227 Receive mask information from client(s) 2228 \param[in] rankBuffers rank of sending client and the corresponding receive buffer 2229 */ 2230 void CDomain::recvMask(std::map<int, CBufferIn*>& rankBuffers) 2231 { 2232 int nbReceived = rankBuffers.size(), i, ind, index; 2233 if (nbReceived != recvClientRanks_.size()) 2234 ERROR("void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers)", 2235 << "The number of sending clients is not correct." 2236 << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 2237 2238 vector<CArray<bool,1> > recvMaskValue(nbReceived); 2239 for (i = 0; i < recvClientRanks_.size(); ++i) 2240 { 2241 int rank = recvClientRanks_[i]; 2242 CBufferIn& buffer = *(rankBuffers[rank]); 2243 buffer >> recvMaskValue[i]; 2244 } 2245 2246 int nbMaskInd = 0; 2247 for (i = 0; i < nbReceived; ++i) 2248 { 2249 nbMaskInd += recvMaskValue[i].numElements(); 2250 } 2251 2252 mask_1d.resize(nbMaskInd); 2253 nbMaskInd = 0; 2254 for (i = 0; i < nbReceived; ++i) 2255 { 2256 CArray<bool,1>& tmp = recvMaskValue[i]; 2257 for (ind = 0; ind < tmp.numElements(); ++ind) 2258 { 2259 mask_1d(nbMaskInd) = tmp(ind); 2260 ++nbMaskInd; 2261 } 2262 } 1966 2263 } 1967 2264 … … 1972 2269 void CDomain::recvLon(CEventServer& event) 1973 2270 { 2271 string domainId; 2272 std::map<int, CBufferIn*> rankBuffers; 2273 1974 2274 list<CEventServer::SSubEvent>::iterator it; 1975 2275 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 1976 { 2276 { 1977 2277 CBufferIn* buffer = it->buffer; 1978 string domainId;1979 2278 *buffer >> domainId; 1980 get(domainId)->recvLon(it->rank, *buffer); 1981 } 2279 rankBuffers[it->rank] = buffer; 2280 } 2281 get(domainId)->recvLon(rankBuffers); 1982 2282 } 1983 2283 1984 2284 /*! 1985 2285 Receive longitude information from client(s) 1986 \param[in] rank rank of client source 1987 \param[in] buffer message containing longitude info 2286 \param[in] rankBuffers rank of sending client and the corresponding receive buffer 1988 2287 */ 1989 void CDomain::recvLon(int rank, CBufferIn& buffer) 1990 { 1991 CArray<int,1> &indi = indiSrv[rank], &indj = indjSrv[rank]; 1992 CArray<double,1> lon; 1993 CArray<double,2> boundslon; 1994 1995 buffer >> lon; 1996 1997 if (hasBounds) buffer >> boundslon; 1998 1999 int i, j, ind_srv; 2000 for (int ind = 0; ind < indi.numElements(); ind++) 2001 { 2002 i = indi(ind); j = indj(ind); 2003 ind_srv = (i - zoom_ibegin_srv) + (j - zoom_jbegin_srv) * zoom_ni_srv; 2004 lonvalue_srv(ind_srv) = lon(ind); 2288 void CDomain::recvLon(std::map<int, CBufferIn*>& rankBuffers) 2289 { 2290 int nbReceived = rankBuffers.size(), i, ind, index; 2291 if (nbReceived != recvClientRanks_.size()) 2292 ERROR("void CDomain::recvLon(std::map<int, CBufferIn*>& rankBuffers)", 2293 << "The number of sending clients is not correct." 2294 << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 2295 2296 vector<CArray<double,1> > recvLonValue(nbReceived); 2297 vector<CArray<double,2> > recvBoundsLonValue(nbReceived); 2298 for (i = 0; i < recvClientRanks_.size(); ++i) 2299 { 2300 int rank = recvClientRanks_[i]; 2301 CBufferIn& buffer = *(rankBuffers[rank]); 2302 buffer >> hasLonLat; 2303 buffer >> recvLonValue[i]; 2304 buffer >> hasBounds; 2005 2305 if (hasBounds) 2006 { 2007 for (int nv = 0; nv < nvertex; ++nv) 2008 bounds_lon_srv(nv, ind_srv) = boundslon(nv, ind); 2306 buffer >> recvBoundsLonValue[i]; 2307 } 2308 2309 int nbLonInd = 0; 2310 for (i = 0; i < nbReceived; ++i) 2311 { 2312 nbLonInd += recvLonValue[i].numElements(); 2313 } 2314 2315 lonvalue.resize(nbLonInd); 2316 if (hasBounds) 2317 { 2318 bounds_lonvalue.resize(nvertex, nbLonInd); 2319 } 2320 2321 nbLonInd = 0; 2322 for (i = 0; i < nbReceived; ++i) 2323 { 2324 CArray<double,1>& tmp = recvLonValue[i]; 2325 for (ind = 0; ind < tmp.numElements(); ++ind) 2326 { 2327 lonvalue(nbLonInd) = tmp(ind); 2328 if (hasBounds) 2329 { 2330 CArray<double,2>& tmpBnds = recvBoundsLonValue[i]; 2331 for (int nv = 0; nv < nvertex; ++nv) 2332 bounds_lonvalue(nv, nbLonInd) = tmpBnds(nv, ind); 2333 } 2334 ++nbLonInd; 2009 2335 } 2010 2336 } … … 2017 2343 void CDomain::recvLat(CEventServer& event) 2018 2344 { 2345 string domainId; 2346 std::map<int, CBufferIn*> rankBuffers; 2347 2019 2348 list<CEventServer::SSubEvent>::iterator it; 2020 2349 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 2021 { 2350 { 2022 2351 CBufferIn* buffer = it->buffer; 2023 string domainId;2024 2352 *buffer >> domainId; 2025 get(domainId)->recvLat(it->rank, *buffer); 2026 } 2353 rankBuffers[it->rank] = buffer; 2354 } 2355 get(domainId)->recvLat(rankBuffers); 2027 2356 } 2028 2357 2029 2358 /*! 2030 2359 Receive latitude information from client(s) 2031 \param[in] rank rank of client source 2032 \param[in] buffer message containing latitude info 2360 \param[in] rankBuffers rank of sending client and the corresponding receive buffer 2033 2361 */ 2034 void CDomain::recvLat(int rank, CBufferIn& buffer) 2035 { 2036 CArray<int,1> &indi = indiSrv[rank], &indj = indjSrv[rank]; 2037 CArray<double,1> lat; 2038 CArray<double,2> boundslat; 2039 2040 buffer >> lat; 2041 if (hasBounds) buffer >> boundslat; 2042 2043 int i, j, ind_srv; 2044 for (int ind = 0; ind < indi.numElements(); ind++) 2045 { 2046 i = indi(ind); j = indj(ind); 2047 ind_srv = (i - zoom_ibegin_srv) + (j - zoom_jbegin_srv) * zoom_ni_srv; 2048 latvalue_srv(ind_srv) = lat(ind); 2362 void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers) 2363 { 2364 int nbReceived = rankBuffers.size(), i, ind, index; 2365 if (nbReceived != recvClientRanks_.size()) 2366 ERROR("void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers)", 2367 << "The number of sending clients is not correct." 2368 << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 2369 2370 vector<CArray<double,1> > recvLatValue(nbReceived); 2371 vector<CArray<double,2> > recvBoundsLatValue(nbReceived); 2372 for (i = 0; i < recvClientRanks_.size(); ++i) 2373 { 2374 int rank = recvClientRanks_[i]; 2375 CBufferIn& buffer = *(rankBuffers[rank]); 2376 buffer >> hasLonLat; 2377 buffer >> recvLatValue[i]; 2378 buffer >> hasBounds; 2049 2379 if (hasBounds) 2050 { 2051 for (int nv = 0; nv < nvertex; nv++) 2052 bounds_lat_srv(nv, ind_srv) = boundslat(nv, ind); 2380 buffer >> recvBoundsLatValue[i]; 2381 } 2382 2383 int nbLatInd = 0; 2384 for (i = 0; i < nbReceived; ++i) 2385 { 2386 nbLatInd += recvLatValue[i].numElements(); 2387 } 2388 2389 latvalue.resize(nbLatInd); 2390 if (hasBounds) 2391 { 2392 bounds_latvalue.resize(nvertex, nbLatInd); 2393 } 2394 2395 nbLatInd = 0; 2396 for (i = 0; i < nbReceived; ++i) 2397 { 2398 CArray<double,1>& tmp = recvLatValue[i]; 2399 for (ind = 0; ind < tmp.numElements(); ++ind) 2400 { 2401 latvalue(nbLatInd) = tmp(ind); 2402 if (hasBounds) 2403 { 2404 CArray<double,2>& tmpBnds = recvBoundsLatValue[i]; 2405 for (int nv = 0; nv < nvertex; ++nv) 2406 bounds_latvalue(nv, nbLatInd) = tmpBnds(nv, ind); 2407 } 2408 ++nbLatInd; 2053 2409 } 2054 2410 } … … 2061 2417 void CDomain::recvArea(CEventServer& event) 2062 2418 { 2419 string domainId; 2420 std::map<int, CBufferIn*> rankBuffers; 2421 2063 2422 list<CEventServer::SSubEvent>::iterator it; 2064 2423 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 2065 { 2424 { 2066 2425 CBufferIn* buffer = it->buffer; 2067 string domainId;2068 2426 *buffer >> domainId; 2069 get(domainId)->recvArea(it->rank, *buffer); 2070 } 2071 } 2427 rankBuffers[it->rank] = buffer; 2428 } 2429 get(domainId)->recvArea(rankBuffers); 2430 } 2431 2072 2432 2073 2433 /*! 2074 2434 Receive area information from client(s) 2075 \param[in] rank rank of client source 2076 \param[in] buffer message containing area info 2435 \param[in] rankBuffers rank of sending client and the corresponding receive buffer 2077 2436 */ 2078 void CDomain::recvArea(int rank, CBufferIn& buffer) 2079 { 2080 CArray<int,1> &indi = indiSrv[rank], &indj = indjSrv[rank]; 2081 CArray<double,1> clientArea; 2082 2083 buffer >> clientArea; 2084 2085 int i, j, ind_srv; 2086 for (int ind = 0; ind < indi.numElements(); ind++) 2087 { 2088 i = indi(ind); j = indj(ind); 2089 ind_srv = (i - zoom_ibegin_srv) + (j - zoom_jbegin_srv) * zoom_ni_srv; 2090 area_srv(ind_srv) = clientArea(ind); 2437 void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers) 2438 { 2439 int nbReceived = rankBuffers.size(), i, ind, index; 2440 if (nbReceived != recvClientRanks_.size()) 2441 ERROR("void CDomain::recvArea(std::map<int, CBufferIn*>& rankBuffers)", 2442 << "The number of sending clients is not correct." 2443 << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 2444 2445 vector<CArray<double,1> > recvAreaValue(nbReceived); 2446 for (i = 0; i < recvClientRanks_.size(); ++i) 2447 { 2448 int rank = recvClientRanks_[i]; 2449 CBufferIn& buffer = *(rankBuffers[rank]); 2450 buffer >> hasArea; 2451 if (hasArea) 2452 buffer >> recvAreaValue[i]; 2453 } 2454 2455 int nbAreaInd = 0; 2456 for (i = 0; i < nbReceived; ++i) 2457 { 2458 if (hasArea) 2459 nbAreaInd += recvAreaValue[i].numElements(); 2460 } 2461 2462 areavalue.resize(nbAreaInd); 2463 nbAreaInd = 0; 2464 if (hasArea) 2465 { 2466 for (i = 0; i < nbReceived; ++i) 2467 { 2468 CArray<double,1>& tmp = recvAreaValue[i]; 2469 for (ind = 0; ind < tmp.numElements(); ++ind) 2470 { 2471 area(nbAreaInd) = tmp(ind); 2472 ++nbAreaInd; 2473 } 2474 } 2475 } 2476 } 2477 2478 /*! 2479 Receive data index event from clients(s) 2480 \param[in] event event contain info about rank and associated index 2481 */ 2482 void CDomain::recvDataIndex(CEventServer& event) 2483 { 2484 string domainId; 2485 std::map<int, CBufferIn*> rankBuffers; 2486 2487 list<CEventServer::SSubEvent>::iterator it; 2488 for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) 2489 { 2490 CBufferIn* buffer = it->buffer; 2491 *buffer >> domainId; 2492 rankBuffers[it->rank] = buffer; 2493 } 2494 get(domainId)->recvDataIndex(rankBuffers); 2495 2496 // if (domain->isCompressible_) 2497 // { 2498 // std::sort(domain->indexesToWrite.begin(), domain->indexesToWrite.end()); 2499 2500 // CContextServer* server = CContext::getCurrent()->server; 2501 // domain->numberWrittenIndexes_ = domain->indexesToWrite.size(); 2502 // MPI_Allreduce(&domain->numberWrittenIndexes_, &domain->totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 2503 // MPI_Scan(&domain->numberWrittenIndexes_, &domain->offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 2504 // domain->offsetWrittenIndexes_ -= domain->numberWrittenIndexes_; 2505 // } 2506 } 2507 2508 /*! 2509 Receive data index information from client(s) 2510 A client receives data index from different clients to rebuild its own data index. 2511 Because the data index is local, to rebuild data index of received client, we should use global index along with. 2512 \param[in] rankBuffers rank of sending client and the corresponding receive buffer 2513 */ 2514 void CDomain::recvDataIndex(std::map<int, CBufferIn*>& rankBuffers) 2515 { 2516 int nbReceived = rankBuffers.size(), i, ind, index, indexI, type_int; 2517 if (nbReceived != recvClientRanks_.size()) 2518 ERROR("void CDomain::recvLat(std::map<int, CBufferIn*>& rankBuffers)", 2519 << "The number of sending clients is not correct." 2520 << "Expected number: " << recvClientRanks_.size() << " but received " << nbReceived); 2521 2522 vector<CArray<int,1> > recvDataIIndex(nbReceived),recvDataJIndex(nbReceived); 2523 for (i = 0; i < recvClientRanks_.size(); ++i) 2524 { 2525 int rank = recvClientRanks_[i]; 2526 CBufferIn& buffer = *(rankBuffers[rank]); 2527 buffer >> recvDataIIndex[i]; 2528 buffer >> recvDataJIndex[i]; 2529 } 2530 2531 int nbCompressedData = 0; 2532 for (i = 0; i < nbReceived; ++i) 2533 { 2534 CArray<int,1>& tmp = recvDataIIndex[i]; 2535 for (ind = 0; ind < tmp.numElements(); ++ind) 2536 { 2537 index = tmp(ind); 2538 if (0 <= index) 2539 ++nbCompressedData; 2540 } 2541 } 2542 2543 data_i_index.resize(nbCompressedData); 2544 data_j_index.resize(nbCompressedData); 2545 2546 nbCompressedData = 0; 2547 for (i = 0; i < nbReceived; ++i) 2548 { 2549 CArray<int,1>& tmpI = recvDataIIndex[i]; 2550 CArray<int,1>& tmpIndex = indGlob_[recvClientRanks_[i]]; 2551 for (ind = 0; ind < tmpI.numElements(); ++ind) 2552 { 2553 indexI = tmpI(ind); 2554 index = tmpIndex(ind); 2555 if (0 <= indexI) 2556 { 2557 data_i_index(nbCompressedData) = index % ni_glo - ibegin; 2558 data_j_index(nbCompressedData) = index / ni_glo - jbegin; 2559 ++nbCompressedData; 2560 } 2561 } 2091 2562 } 2092 2563 } … … 2123 2594 { 2124 2595 return transformationMap_; 2125 }2126 2127 /*!2128 Check the validity of all transformations applied on domain2129 This functions is called AFTER all inherited attributes are solved2130 */2131 void CDomain::checkTransformations()2132 {2133 TransMapTypes::const_iterator itb = transformationMap_.begin(), it,2134 ite = transformationMap_.end();2135 // for (it = itb; it != ite; ++it)2136 // {2137 // (it->second)->checkValid(this);2138 // }2139 2596 } 2140 2597
Note: See TracChangeset
for help on using the changeset viewer.