Changeset 1021 for XIOS/dev/dev_olga/src/server.cpp
- Timestamp:
- 01/10/17 14:36:29 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_olga/src/server.cpp
r1009 r1021 22 22 list<MPI_Comm> CServer::interComm ; 23 23 std::list<MPI_Comm> CServer::contextInterComms; 24 int CServer::nbSndSrvPools = (CXios::serverLevel == 0) ? 0 : 1; 25 int CServer::poolNb = 0; 24 int CServer::serverLevel = 0 ; 25 int CServer::nbPools = 0; 26 int CServer::poolId = 0; 27 int CServer::serverSize = 0; 26 28 bool CServer::isRoot = false ; 27 29 int CServer::rank = INVALID_RANK; 28 int CServer::rankSndServers = 0;29 30 StdOFStream CServer::m_infoStream; 30 31 StdOFStream CServer::m_errorStream; … … 37 38 /*! 38 39 * \fn void CServer::initialize(void) 39 * Function creates intra and inter comm for each initialized server pool40 * Creates intraComm and interComm for a server pool (primary or secondary). 40 41 */ 41 42 void CServer::initialize(void) … … 46 47 else is_MPI_Initialized=false ; 47 48 48 49 49 // Not using OASIS 50 50 if (!CXios::usingOasis) … … 58 58 59 59 boost::hash<string> hashString ; 60 unsigned long hashServer1 = hashString(CXios::xiosCodeIdPrm); 61 unsigned long hashServer2 = hashString(CXios::xiosCodeIdSnd); 62 unsigned long hashServer = (CXios::serverLevel < 2) ? hashServer1 : hashServer2; 60 // unsigned long hashServer1 = hashString(CXios::xiosCodeIdPrm); 61 // unsigned long hashServer2 = hashString(CXios::xiosCodeIdSnd); 62 // unsigned long hashServer = (CXios::serverLevel < 2) ? hashServer1 : hashServer2; 63 unsigned long hashServer = hashString(CXios::xiosCodeId); 63 64 64 65 unsigned long* hashAll ; 65 unsigned long* hashAllServers ;66 // unsigned long* hashAllServers ; 66 67 67 68 // int rank ; … … 69 70 int myColor ; 70 71 int i,c ; 71 MPI_Comm newComm, servers InterComm;72 MPI_Comm newComm, serversComm; 72 73 73 74 MPI_Comm_size(CXios::globalComm, &size) ; … … 77 78 MPI_Allgather(&hashServer, 1, MPI_LONG, hashAll, 1, MPI_LONG, CXios::globalComm) ; 78 79 79 map<unsigned long, int> colors , colorsServers;80 map<unsigned long, int> colors ; 80 81 map<unsigned long, int> leaders ; 81 82 map<unsigned long, int>::iterator it ; 82 // map<unsigned long, int> leadersServers ;83 vector<int> leadersServers;84 83 85 84 for(i=0,c=0;i<size;i++) … … 93 92 } 94 93 95 nbSndSrvPools = size - leaders[hashServer2]; // one proc per secondary-server pool 96 97 // Taking into account multiple pools on secondary server 98 if (nbSndSrvPools > 1) 99 { 100 if (CXios::serverLevel > 1) 94 // Setting the number of secondary pools 95 myColor = colors[hashServer]; 96 if (CXios::usingServer2) 97 { 98 int serverRank = rank - leaders[hashServer]; // server proc rank starting 0 99 serverSize = size - leaders[hashServer]; 100 nbPools = serverSize * CXios::ratioServer2 / 100; 101 if ( serverRank < (serverSize - nbPools) ) 101 102 { 102 int nbProcs = size - leaders[hashServer2]; 103 int remain = nbProcs % nbSndSrvPools; 104 int procsPerPool = nbProcs / nbSndSrvPools; 105 rankSndServers = rank - leaders[hashServer2]; 106 StdString strTmp = CXios::xiosCodeIdSnd; 107 108 if (remain == 0) 109 { 110 poolNb = rankSndServers/procsPerPool; 111 } 112 else 113 { 114 if (rankSndServers <= (procsPerPool + 1) * remain) 115 poolNb = rankSndServers/(procsPerPool+1); 116 else 117 { 118 poolNb = remain + 1; 119 rankSndServers -= (procsPerPool + 1) * remain; 120 rankSndServers -= procsPerPool; 121 poolNb += rankSndServers/procsPerPool; 122 } 123 } 124 strTmp += boost::lexical_cast<string>(poolNb+1); // add 1 to avoid hashing zero 125 hashServer = hashString(strTmp); 126 hashServer2 = hashString(strTmp); 103 serverLevel = 1; 104 } 105 else 106 { 107 serverLevel = 2; 108 poolId = serverRank - serverSize + nbPools; 109 myColor = rank; 127 110 } 128 111 } 129 112 130 if (nbSndSrvPools > 1) 131 { 132 myColor = size; 133 MPI_Comm_split(MPI_COMM_WORLD, myColor, rank, &serversInterComm) ; 134 } 135 else 136 { 137 myColor=colors[hashServer] ; 138 MPI_Comm_split(MPI_COMM_WORLD, myColor, rank, &intraComm) ; 139 } 140 141 if (nbSndSrvPools > 1) 142 { 143 int sizeServers; 144 // int rankServers; 145 // MPI_Comm_rank(serversInterComm, &rankServers) ; 146 MPI_Comm_size(serversInterComm, &sizeServers) ; 147 hashAllServers=new unsigned long[sizeServers] ; 148 MPI_Allgather(&hashServer, 1, MPI_LONG, hashAllServers, 1, MPI_LONG, serversInterComm) ; 149 150 for(i=0, c=0; i<sizeServers; i++) 151 { 152 if (colorsServers.find(hashAllServers[i])==colorsServers.end()) 153 { 154 colorsServers[hashAllServers[i]]=c ; 155 // leadersServers[hashAllServers[i]]= leaders[hashServer1] + i ; 156 leadersServers.push_back( leaders[hashServer1] + i ); 157 c++ ; 158 } 159 } 160 myColor=colorsServers[hashServer] ; 161 MPI_Comm_split(serversInterComm, myColor, rank, &intraComm) ; 162 } 163 164 165 if (CXios::serverLevel == 0) 113 MPI_Comm_split(CXios::globalComm, myColor, rank, &intraComm) ; 114 115 if (serverLevel == 0) 166 116 { 167 117 int clientLeader; … … 183 133 } 184 134 } 185 else 186 { 187 if ((CXios::serverLevel == 1)) 135 else if (serverLevel == 1) 136 { 137 int clientLeader, srvPrmLeader, srvSndLeader; 138 for (it=leaders.begin();it!=leaders.end();it++) 188 139 { 189 // Creating interComm with client (interCommLeft) 190 int clientLeader; 191 int srvSndLeader; 192 for(it=leaders.begin();it!=leaders.end();it++) 140 if (it->first != hashServer) 193 141 { 194 if (it->first != hashServer2) 195 { 196 if (it->first != hashServer1) 197 { 198 clientLeader=it->second ; 199 int intraCommSize, intraCommRank ; 200 MPI_Comm_size(intraComm, &intraCommSize) ; 201 MPI_Comm_rank(intraComm, &intraCommRank) ; 202 info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize 203 <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< clientLeader<<endl ; 204 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 205 interCommLeft.push_back(newComm) ; 206 interComm.push_back(newComm) ; 207 } 208 } 209 else 210 { 211 srvSndLeader = it->second; 212 } 213 } 214 215 // Creating interComm with secondary server pool(s) (interCommRight) 216 // if (nbSndSrvPools < 1) 217 if (nbSndSrvPools < 2) 218 { 219 CClient::initializeClientOnServer(rank, intraComm, srvSndLeader); 220 interCommRight.push_back(CClient::getInterComm()); 221 interComm.push_back(CClient::getInterComm()); 142 clientLeader=it->second ; 143 int intraCommSize, intraCommRank ; 144 MPI_Comm_size(intraComm, &intraCommSize) ; 145 MPI_Comm_rank(intraComm, &intraCommRank) ; 146 info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize 147 <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< clientLeader<<endl ; 148 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 149 interCommLeft.push_back(newComm) ; 150 interComm.push_back(newComm) ; 222 151 } 223 152 else 224 { 225 // for(it=leadersServers.begin();it!=leadersServers.end();it++) 226 // { 227 // if (it->first != hashServer) 228 // { 229 // srvSndLeader = it->second; 230 // CClient::initializeClientOnServer(rank, intraComm, srvSndLeader); 231 // interCommRight.push_back(CClient::getInterComm()); 232 // interComm.push_back(CClient::getInterComm()); 233 // } 234 // } 235 236 for(int i = 1; i < leadersServers.size(); ++i) 237 { 238 srvSndLeader = leadersServers[i]; 239 CClient::initializeClientOnServer(rank, intraComm, srvSndLeader); 240 interCommRight.push_back(CClient::getInterComm()); 241 interComm.push_back(CClient::getInterComm()); 242 } 243 } 244 } // primary server 245 246 else // secondary server pool(s) 153 srvPrmLeader = it->second; 154 } 155 156 for (int i = 0; i < nbPools; ++i) 247 157 { 248 int clientLeader; 249 if (nbSndSrvPools < 2) 250 // if (nbSndSrvPools < 1) 251 { 252 for(it=leaders.begin();it!=leaders.end();it++) 253 { 254 if (it->first == hashServer1) 255 { 256 clientLeader=it->second ; 257 int intraCommSize, intraCommRank ; 258 MPI_Comm_size(intraComm, &intraCommSize) ; 259 MPI_Comm_rank(intraComm, &intraCommRank) ; 260 info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize 261 <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< clientLeader<<endl ; 262 263 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 264 interCommLeft.push_back(newComm) ; 265 interComm.push_back(newComm) ; 266 267 break; 268 } 269 } 270 } 271 else 272 { 273 // for(it=leadersServers.begin();it!=leadersServers.end();it++) 274 { 275 // if (it->first == hashServer1) 276 { 277 // clientLeader=it->second ; 278 clientLeader = leadersServers[0]; 279 int intraCommSize, intraCommRank ; 280 MPI_Comm_size(intraComm, &intraCommSize) ; 281 MPI_Comm_rank(intraComm, &intraCommRank) ; 282 info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize 283 <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< clientLeader<<endl ; 284 285 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 286 interCommLeft.push_back(newComm) ; 287 interComm.push_back(newComm) ; 288 } 289 } 290 } 291 } // secondary server 292 } // CXios::serverLevel != 0 293 294 if (nbSndSrvPools > 1) delete [] hashAllServers; 158 srvSndLeader = srvPrmLeader + serverSize - nbPools + i; 159 // CClient::initializeClientOnServer(rank, serversComm, srvSndLeader); 160 CClient::initializeClientOnServer(rank, intraComm, srvSndLeader); 161 interCommRight.push_back(CClient::getInterComm()); 162 interComm.push_back(CClient::getInterComm()); 163 } 164 } // primary server 165 else 166 { 167 int clientLeader; 168 clientLeader = leaders[hashString(CXios::xiosCodeId)]; 169 int intraCommSize, intraCommRank ; 170 MPI_Comm_size(intraComm, &intraCommSize) ; 171 MPI_Comm_rank(intraComm, &intraCommRank) ; 172 info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize 173 <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< clientLeader<<endl ; 174 175 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 176 interCommLeft.push_back(newComm) ; 177 interComm.push_back(newComm) ; 178 } // secondary server 179 295 180 delete [] hashAll ; 296 181 … … 416 301 { 417 302 MPI_Send(&msg,1,MPI_INT,0,0,*itr) ; 418 419 303 // MPI_Comm_free(&(*itr)); 420 304 // interCommRight.erase(itr) ; … … 612 496 contextInterComms.push_back(contextInterComm); 613 497 614 if ( CXios::serverLevel == 1)498 if (serverLevel == 1) 615 499 { 616 500 // CClient::registerContext(contextId, intraComm); 617 CClient::registerContext OnSrvPools(contextId, intraComm);501 CClient::registerContextByClienOfServer(contextId, intraComm); 618 502 } 619 503 … … 657 541 int numDigit = 0; 658 542 int size = 0; 659 int mpiRank;543 int id; 660 544 MPI_Comm_size(CXios::globalComm, &size); 661 545 while (size) … … 665 549 } 666 550 667 if ( nbSndSrvPools <2)668 mpiRank= getRank();551 if (!CXios::usingServer2) 552 id = getRank(); 669 553 else 670 mpiRank = rankSndServers; 671 fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << mpiRank << ext; 554 { 555 if (serverLevel == 1) 556 id = getRank(); 557 else 558 id = poolId; 559 } 560 fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << id << ext; 672 561 fb->open(fileNameClient.str().c_str(), std::ios::out); 673 562 if (!fb->is_open())
Note: See TracChangeset
for help on using the changeset viewer.