[490] | 1 | #include "globalScopeData.hpp" |
---|
[591] | 2 | #include "xios_spl.hpp" |
---|
[300] | 3 | #include "cxios.hpp" |
---|
[342] | 4 | #include "server.hpp" |
---|
[983] | 5 | #include "client.hpp" |
---|
[300] | 6 | #include "type.hpp" |
---|
| 7 | #include "context.hpp" |
---|
[352] | 8 | #include "object_template.hpp" |
---|
[300] | 9 | #include "oasis_cinterface.hpp" |
---|
| 10 | #include <boost/functional/hash.hpp> |
---|
| 11 | #include <boost/algorithm/string.hpp> |
---|
[382] | 12 | #include "mpi.hpp" |
---|
[347] | 13 | #include "tracer.hpp" |
---|
| 14 | #include "timer.hpp" |
---|
[492] | 15 | #include "event_scheduler.hpp" |
---|
[1587] | 16 | #include "string_tools.hpp" |
---|
[300] | 17 | |
---|
[335] | 18 | namespace xios |
---|
[490] | 19 | { |
---|
[1639] | 20 | MPI_Comm CServer::intraComm ; |
---|
| 21 | std::list<MPI_Comm> CServer::interCommLeft ; |
---|
| 22 | std::list<MPI_Comm> CServer::interCommRight ; |
---|
| 23 | std::list<MPI_Comm> CServer::contextInterComms; |
---|
| 24 | std::list<MPI_Comm> CServer::contextIntraComms; |
---|
[1021] | 25 | int CServer::serverLevel = 0 ; |
---|
[1148] | 26 | int CServer::nbContexts = 0; |
---|
[983] | 27 | bool CServer::isRoot = false ; |
---|
[1077] | 28 | int CServer::rank_ = INVALID_RANK; |
---|
[490] | 29 | StdOFStream CServer::m_infoStream; |
---|
[523] | 30 | StdOFStream CServer::m_errorStream; |
---|
[490] | 31 | map<string,CContext*> CServer::contextList ; |
---|
[1152] | 32 | vector<int> CServer::sndServerGlobalRanks; |
---|
[300] | 33 | bool CServer::finished=false ; |
---|
| 34 | bool CServer::is_MPI_Initialized ; |
---|
[597] | 35 | CEventScheduler* CServer::eventScheduler = 0; |
---|
[983] | 36 | |
---|
| 37 | //--------------------------------------------------------------- |
---|
| 38 | /*! |
---|
| 39 | * \fn void CServer::initialize(void) |
---|
[1054] | 40 | * Creates intraComm for each possible type of servers (classical, primary or secondary). |
---|
[1148] | 41 | * Creates interComm and stores them into the following lists: |
---|
[1054] | 42 | * classical server -- interCommLeft |
---|
| 43 | * primary server -- interCommLeft and interCommRight |
---|
[1148] | 44 | * secondary server -- interCommLeft for each pool. |
---|
[1234] | 45 | * IMPORTANT: CXios::usingServer2 should NOT be used beyond this function. Use CServer::serverLevel instead. |
---|
[983] | 46 | */ |
---|
[300] | 47 | void CServer::initialize(void) |
---|
| 48 | { |
---|
| 49 | int initialized ; |
---|
[1639] | 50 | MPI_Initialized(&initialized) ; |
---|
[300] | 51 | if (initialized) is_MPI_Initialized=true ; |
---|
| 52 | else is_MPI_Initialized=false ; |
---|
[1152] | 53 | int rank ; |
---|
[490] | 54 | |
---|
[300] | 55 | // Not using OASIS |
---|
| 56 | if (!CXios::usingOasis) |
---|
| 57 | { |
---|
[490] | 58 | |
---|
| 59 | if (!is_MPI_Initialized) |
---|
[300] | 60 | { |
---|
[1639] | 61 | MPI_Init(NULL, NULL); |
---|
[300] | 62 | } |
---|
[359] | 63 | CTimer::get("XIOS").resume() ; |
---|
[490] | 64 | |
---|
| 65 | boost::hash<string> hashString ; |
---|
[1021] | 66 | unsigned long hashServer = hashString(CXios::xiosCodeId); |
---|
[490] | 67 | |
---|
[300] | 68 | unsigned long* hashAll ; |
---|
[1152] | 69 | unsigned long* srvLevelAll ; |
---|
[490] | 70 | |
---|
[300] | 71 | int size ; |
---|
| 72 | int myColor ; |
---|
| 73 | int i,c ; |
---|
[1639] | 74 | MPI_Comm newComm; |
---|
[490] | 75 | |
---|
[1639] | 76 | MPI_Comm_size(CXios::globalComm, &size) ; |
---|
| 77 | MPI_Comm_rank(CXios::globalComm, &rank_); |
---|
[1009] | 78 | |
---|
[300] | 79 | hashAll=new unsigned long[size] ; |
---|
[1639] | 80 | MPI_Allgather(&hashServer, 1, MPI_LONG, hashAll, 1, MPI_LONG, CXios::globalComm) ; |
---|
[490] | 81 | |
---|
[1021] | 82 | map<unsigned long, int> colors ; |
---|
[300] | 83 | map<unsigned long, int> leaders ; |
---|
| 84 | map<unsigned long, int>::iterator it ; |
---|
[490] | 85 | |
---|
[1152] | 86 | // (1) Establish client leaders, distribute processes between two server levels |
---|
[1234] | 87 | std::vector<int> srvRanks; |
---|
[300] | 88 | for(i=0,c=0;i<size;i++) |
---|
| 89 | { |
---|
| 90 | if (colors.find(hashAll[i])==colors.end()) |
---|
| 91 | { |
---|
| 92 | colors[hashAll[i]]=c ; |
---|
| 93 | leaders[hashAll[i]]=i ; |
---|
| 94 | c++ ; |
---|
| 95 | } |
---|
[1152] | 96 | if (CXios::usingServer2) |
---|
[1180] | 97 | if (hashAll[i] == hashServer) |
---|
| 98 | srvRanks.push_back(i); |
---|
| 99 | } |
---|
[1234] | 100 | |
---|
| 101 | if (CXios::usingServer2) |
---|
[1180] | 102 | { |
---|
[1234] | 103 | int reqNbProc = srvRanks.size()*CXios::ratioServer2/100.; |
---|
| 104 | if (reqNbProc<1 || reqNbProc==srvRanks.size()) |
---|
[1152] | 105 | { |
---|
[1234] | 106 | error(0)<<"WARNING: void CServer::initialize(void)"<<endl |
---|
| 107 | << "It is impossible to dedicate the requested number of processes = "<<reqNbProc |
---|
| 108 | <<" to secondary server. XIOS will run in the classical server mode."<<endl; |
---|
[1152] | 109 | } |
---|
[1180] | 110 | else |
---|
| 111 | { |
---|
[1519] | 112 | if (CXios::nbPoolsServer2 == 0) CXios::nbPoolsServer2 = reqNbProc; |
---|
[1243] | 113 | int firstSndSrvRank = srvRanks.size()*(100.-CXios::ratioServer2)/100. ; |
---|
| 114 | int poolLeader = firstSndSrvRank; |
---|
| 115 | //*********** (1) Comment out the line below to set one process per pool |
---|
[1519] | 116 | sndServerGlobalRanks.push_back(srvRanks[poolLeader]); |
---|
[1243] | 117 | int nbPools = CXios::nbPoolsServer2; |
---|
| 118 | if ( nbPools > reqNbProc || nbPools < 1) |
---|
| 119 | { |
---|
| 120 | error(0)<<"WARNING: void CServer::initialize(void)"<<endl |
---|
| 121 | << "It is impossible to allocate the requested number of pools = "<<nbPools |
---|
| 122 | <<" on the secondary server. It will be set so that there is one process per pool."<<endl; |
---|
| 123 | nbPools = reqNbProc; |
---|
| 124 | } |
---|
| 125 | int remainder = ((int) (srvRanks.size()*CXios::ratioServer2/100.)) % nbPools; |
---|
| 126 | int procsPerPool = ((int) (srvRanks.size()*CXios::ratioServer2/100.)) / nbPools; |
---|
[1234] | 127 | for (i=0; i<srvRanks.size(); i++) |
---|
| 128 | { |
---|
[1243] | 129 | if (i >= firstSndSrvRank) |
---|
[1234] | 130 | { |
---|
[1243] | 131 | if (rank_ == srvRanks[i]) |
---|
| 132 | { |
---|
| 133 | serverLevel=2; |
---|
| 134 | } |
---|
| 135 | poolLeader += procsPerPool; |
---|
| 136 | if (remainder != 0) |
---|
| 137 | { |
---|
| 138 | ++poolLeader; |
---|
| 139 | --remainder; |
---|
| 140 | } |
---|
| 141 | //*********** (2) Comment out the two lines below to set one process per pool |
---|
[1519] | 142 | if (poolLeader < srvRanks.size()) |
---|
| 143 | sndServerGlobalRanks.push_back(srvRanks[poolLeader]); |
---|
[1243] | 144 | //*********** (3) Uncomment the line below to set one process per pool |
---|
[1519] | 145 | // sndServerGlobalRanks.push_back(srvRanks[i]); |
---|
[1234] | 146 | } |
---|
| 147 | else |
---|
| 148 | { |
---|
| 149 | if (rank_ == srvRanks[i]) serverLevel=1; |
---|
| 150 | } |
---|
| 151 | } |
---|
[1243] | 152 | if (serverLevel==2) |
---|
| 153 | { |
---|
| 154 | info(50)<<"The number of secondary server pools is "<< sndServerGlobalRanks.size() <<endl ; |
---|
| 155 | for (i=0; i<sndServerGlobalRanks.size(); i++) |
---|
| 156 | { |
---|
| 157 | if (rank_>= sndServerGlobalRanks[i]) |
---|
| 158 | { |
---|
| 159 | if ( i == sndServerGlobalRanks.size()-1) |
---|
| 160 | { |
---|
| 161 | myColor = colors.size() + sndServerGlobalRanks[i]; |
---|
| 162 | } |
---|
| 163 | else if (rank_< sndServerGlobalRanks[i+1]) |
---|
| 164 | { |
---|
| 165 | myColor = colors.size() + sndServerGlobalRanks[i]; |
---|
| 166 | break; |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | } |
---|
[1180] | 171 | } |
---|
[300] | 172 | } |
---|
[1243] | 173 | |
---|
[1152] | 174 | // (2) Create intraComm |
---|
[1243] | 175 | if (serverLevel != 2) myColor=colors[hashServer]; |
---|
[1639] | 176 | MPI_Comm_split(CXios::globalComm, myColor, rank_, &intraComm) ; |
---|
[1152] | 177 | |
---|
| 178 | // (3) Create interComm |
---|
[1021] | 179 | if (serverLevel == 0) |
---|
[983] | 180 | { |
---|
| 181 | int clientLeader; |
---|
| 182 | for(it=leaders.begin();it!=leaders.end();it++) |
---|
| 183 | { |
---|
| 184 | if (it->first!=hashServer) |
---|
| 185 | { |
---|
| 186 | clientLeader=it->second ; |
---|
| 187 | int intraCommSize, intraCommRank ; |
---|
[1639] | 188 | MPI_Comm_size(intraComm,&intraCommSize) ; |
---|
| 189 | MPI_Comm_rank(intraComm,&intraCommRank) ; |
---|
[1142] | 190 | info(50)<<"intercommCreate::server (classical mode) "<<rank_<<" intraCommSize : "<<intraCommSize |
---|
[983] | 191 | <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< clientLeader<<endl ; |
---|
[490] | 192 | |
---|
[1639] | 193 | MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; |
---|
[1180] | 194 | interCommLeft.push_back(newComm) ; |
---|
[983] | 195 | } |
---|
| 196 | } |
---|
| 197 | } |
---|
[1021] | 198 | else if (serverLevel == 1) |
---|
[983] | 199 | { |
---|
[1054] | 200 | int clientLeader, srvSndLeader; |
---|
| 201 | int srvPrmLeader ; |
---|
[1152] | 202 | |
---|
[1021] | 203 | for (it=leaders.begin();it!=leaders.end();it++) |
---|
[983] | 204 | { |
---|
[1021] | 205 | if (it->first != hashServer) |
---|
[983] | 206 | { |
---|
[1021] | 207 | clientLeader=it->second ; |
---|
| 208 | int intraCommSize, intraCommRank ; |
---|
[1639] | 209 | MPI_Comm_size(intraComm, &intraCommSize) ; |
---|
| 210 | MPI_Comm_rank(intraComm, &intraCommRank) ; |
---|
[1142] | 211 | info(50)<<"intercommCreate::server (server level 1) "<<rank_<<" intraCommSize : "<<intraCommSize |
---|
[1021] | 212 | <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< clientLeader<<endl ; |
---|
[1639] | 213 | MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; |
---|
[1021] | 214 | interCommLeft.push_back(newComm) ; |
---|
[983] | 215 | } |
---|
[1021] | 216 | } |
---|
[1009] | 217 | |
---|
[1152] | 218 | for (int i = 0; i < sndServerGlobalRanks.size(); ++i) |
---|
[983] | 219 | { |
---|
[1054] | 220 | int intraCommSize, intraCommRank ; |
---|
[1639] | 221 | MPI_Comm_size(intraComm, &intraCommSize) ; |
---|
| 222 | MPI_Comm_rank(intraComm, &intraCommRank) ; |
---|
[1142] | 223 | info(50)<<"intercommCreate::client (server level 1) "<<rank_<<" intraCommSize : "<<intraCommSize |
---|
[1152] | 224 | <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< sndServerGlobalRanks[i]<<endl ; |
---|
[1639] | 225 | MPI_Intercomm_create(intraComm, 0, CXios::globalComm, sndServerGlobalRanks[i], 1, &newComm) ; |
---|
[1054] | 226 | interCommRight.push_back(newComm) ; |
---|
[1021] | 227 | } |
---|
[1168] | 228 | } |
---|
[1021] | 229 | else |
---|
| 230 | { |
---|
| 231 | int clientLeader; |
---|
| 232 | clientLeader = leaders[hashString(CXios::xiosCodeId)]; |
---|
| 233 | int intraCommSize, intraCommRank ; |
---|
[1639] | 234 | MPI_Comm_size(intraComm, &intraCommSize) ; |
---|
| 235 | MPI_Comm_rank(intraComm, &intraCommRank) ; |
---|
[1142] | 236 | info(50)<<"intercommCreate::server (server level 2) "<<rank_<<" intraCommSize : "<<intraCommSize |
---|
[1021] | 237 | <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< clientLeader<<endl ; |
---|
[983] | 238 | |
---|
[1639] | 239 | MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 1, &newComm) ; |
---|
[1021] | 240 | interCommLeft.push_back(newComm) ; |
---|
[1168] | 241 | } |
---|
[983] | 242 | |
---|
| 243 | delete [] hashAll ; |
---|
| 244 | |
---|
[300] | 245 | } |
---|
| 246 | // using OASIS |
---|
| 247 | else |
---|
| 248 | { |
---|
[1152] | 249 | int size; |
---|
[1130] | 250 | int myColor; |
---|
[1234] | 251 | int* srvGlobalRanks; |
---|
[490] | 252 | if (!is_MPI_Initialized) oasis_init(CXios::xiosCodeId); |
---|
| 253 | |
---|
[359] | 254 | CTimer::get("XIOS").resume() ; |
---|
[1639] | 255 | MPI_Comm localComm; |
---|
[655] | 256 | oasis_get_localcomm(localComm); |
---|
[1639] | 257 | MPI_Comm_rank(localComm,&rank_) ; |
---|
[655] | 258 | |
---|
[1234] | 259 | // (1) Create server intraComm |
---|
[1130] | 260 | if (!CXios::usingServer2) |
---|
[1167] | 261 | { |
---|
[1639] | 262 | MPI_Comm_dup(localComm, &intraComm); |
---|
[1167] | 263 | } |
---|
[1130] | 264 | else |
---|
| 265 | { |
---|
[1180] | 266 | int globalRank; |
---|
[1639] | 267 | MPI_Comm_size(localComm,&size) ; |
---|
| 268 | MPI_Comm_rank(CXios::globalComm,&globalRank) ; |
---|
[1234] | 269 | srvGlobalRanks = new int[size] ; |
---|
[1639] | 270 | MPI_Allgather(&globalRank, 1, MPI_INT, srvGlobalRanks, 1, MPI_INT, localComm) ; |
---|
[1152] | 271 | |
---|
[1234] | 272 | int reqNbProc = size*CXios::ratioServer2/100.; |
---|
| 273 | if (reqNbProc < 1 || reqNbProc == size) |
---|
[1130] | 274 | { |
---|
[1234] | 275 | error(0)<<"WARNING: void CServer::initialize(void)"<<endl |
---|
| 276 | << "It is impossible to dedicate the requested number of processes = "<<reqNbProc |
---|
| 277 | <<" to secondary server. XIOS will run in the classical server mode."<<endl; |
---|
[1639] | 278 | MPI_Comm_dup(localComm, &intraComm); |
---|
[1130] | 279 | } |
---|
| 280 | else |
---|
| 281 | { |
---|
[1243] | 282 | int firstSndSrvRank = size*(100.-CXios::ratioServer2)/100. ; |
---|
| 283 | int poolLeader = firstSndSrvRank; |
---|
| 284 | //*********** (1) Comment out the line below to set one process per pool |
---|
| 285 | // sndServerGlobalRanks.push_back(srvGlobalRanks[poolLeader]); |
---|
| 286 | int nbPools = CXios::nbPoolsServer2; |
---|
| 287 | if ( nbPools > reqNbProc || nbPools < 1) |
---|
| 288 | { |
---|
| 289 | error(0)<<"WARNING: void CServer::initialize(void)"<<endl |
---|
| 290 | << "It is impossible to allocate the requested number of pools = "<<nbPools |
---|
| 291 | <<" on the secondary server. It will be set so that there is one process per pool."<<endl; |
---|
| 292 | nbPools = reqNbProc; |
---|
| 293 | } |
---|
| 294 | int remainder = ((int) (size*CXios::ratioServer2/100.)) % nbPools; |
---|
| 295 | int procsPerPool = ((int) (size*CXios::ratioServer2/100.)) / nbPools; |
---|
[1234] | 296 | for (int i=0; i<size; i++) |
---|
| 297 | { |
---|
[1243] | 298 | if (i >= firstSndSrvRank) |
---|
[1234] | 299 | { |
---|
[1243] | 300 | if (globalRank == srvGlobalRanks[i]) |
---|
| 301 | { |
---|
| 302 | serverLevel=2; |
---|
| 303 | } |
---|
| 304 | poolLeader += procsPerPool; |
---|
| 305 | if (remainder != 0) |
---|
| 306 | { |
---|
| 307 | ++poolLeader; |
---|
| 308 | --remainder; |
---|
| 309 | } |
---|
| 310 | //*********** (2) Comment out the two lines below to set one process per pool |
---|
| 311 | // if (poolLeader < size) |
---|
| 312 | // sndServerGlobalRanks.push_back(srvGlobalRanks[poolLeader]); |
---|
| 313 | //*********** (3) Uncomment the line below to set one process per pool |
---|
[1234] | 314 | sndServerGlobalRanks.push_back(srvGlobalRanks[i]); |
---|
| 315 | } |
---|
| 316 | else |
---|
| 317 | { |
---|
| 318 | if (globalRank == srvGlobalRanks[i]) serverLevel=1; |
---|
| 319 | } |
---|
| 320 | } |
---|
[1243] | 321 | if (serverLevel==2) |
---|
| 322 | { |
---|
| 323 | info(50)<<"The number of secondary server pools is "<< sndServerGlobalRanks.size() <<endl ; |
---|
| 324 | for (int i=0; i<sndServerGlobalRanks.size(); i++) |
---|
| 325 | { |
---|
| 326 | if (globalRank>= sndServerGlobalRanks[i]) |
---|
| 327 | { |
---|
| 328 | if (i == sndServerGlobalRanks.size()-1) |
---|
| 329 | { |
---|
| 330 | myColor = sndServerGlobalRanks[i]; |
---|
| 331 | } |
---|
| 332 | else if (globalRank< sndServerGlobalRanks[i+1]) |
---|
| 333 | { |
---|
| 334 | myColor = sndServerGlobalRanks[i]; |
---|
| 335 | break; |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | } |
---|
| 339 | } |
---|
| 340 | if (serverLevel != 2) myColor=0; |
---|
[1639] | 341 | MPI_Comm_split(localComm, myColor, rank_, &intraComm) ; |
---|
[1130] | 342 | } |
---|
[1234] | 343 | } |
---|
[1130] | 344 | |
---|
[300] | 345 | string codesId=CXios::getin<string>("oasis_codes_id") ; |
---|
[1587] | 346 | vector<string> oasisCodeId=splitRegex(codesId,"\\s*,\\s*") ; |
---|
| 347 | |
---|
[300] | 348 | vector<string>::iterator it ; |
---|
| 349 | |
---|
[1639] | 350 | MPI_Comm newComm ; |
---|
[300] | 351 | int globalRank ; |
---|
[1639] | 352 | MPI_Comm_rank(CXios::globalComm,&globalRank); |
---|
[490] | 353 | |
---|
[1234] | 354 | // (2) Create interComms with models |
---|
[1587] | 355 | for(it=oasisCodeId.begin();it!=oasisCodeId.end();it++) |
---|
[300] | 356 | { |
---|
| 357 | oasis_get_intercomm(newComm,*it) ; |
---|
[1234] | 358 | if ( serverLevel == 0 || serverLevel == 1) |
---|
[1150] | 359 | { |
---|
[1130] | 360 | interCommLeft.push_back(newComm) ; |
---|
[1639] | 361 | if (rank_==0) MPI_Send(&globalRank,1,MPI_INT,0,0,newComm) ; |
---|
[1150] | 362 | } |
---|
[1180] | 363 | } |
---|
| 364 | |
---|
[1234] | 365 | // (3) Create interComms between primary and secondary servers |
---|
[1243] | 366 | int intraCommSize, intraCommRank ; |
---|
[1639] | 367 | MPI_Comm_size(intraComm,&intraCommSize) ; |
---|
| 368 | MPI_Comm_rank(intraComm, &intraCommRank) ; |
---|
[1243] | 369 | |
---|
[1180] | 370 | if (serverLevel == 1) |
---|
| 371 | { |
---|
| 372 | for (int i = 0; i < sndServerGlobalRanks.size(); ++i) |
---|
[1130] | 373 | { |
---|
[1180] | 374 | int srvSndLeader = sndServerGlobalRanks[i]; |
---|
[1243] | 375 | info(50)<<"intercommCreate::client (server level 1) "<<globalRank<<" intraCommSize : "<<intraCommSize |
---|
| 376 | <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< srvSndLeader<<endl ; |
---|
[1639] | 377 | MPI_Intercomm_create(intraComm, 0, CXios::globalComm, srvSndLeader, 0, &newComm) ; |
---|
[1180] | 378 | interCommRight.push_back(newComm) ; |
---|
[1130] | 379 | } |
---|
[300] | 380 | } |
---|
[1180] | 381 | else if (serverLevel == 2) |
---|
| 382 | { |
---|
[1244] | 383 | info(50)<<"intercommCreate::server (server level 2)"<<globalRank<<" intraCommSize : "<<intraCommSize |
---|
[1243] | 384 | <<" intraCommRank :"<<intraCommRank<<" clientLeader "<< srvGlobalRanks[0] <<endl ; |
---|
[1639] | 385 | MPI_Intercomm_create(intraComm, 0, CXios::globalComm, srvGlobalRanks[0], 0, &newComm) ; |
---|
[1180] | 386 | interCommLeft.push_back(newComm) ; |
---|
| 387 | } |
---|
[1184] | 388 | if (CXios::usingServer2) delete [] srvGlobalRanks ; |
---|
[1587] | 389 | |
---|
| 390 | bool oasisEnddef=CXios::getin<bool>("call_oasis_enddef",true) ; |
---|
| 391 | if (!oasisEnddef) oasis_enddef() ; |
---|
[300] | 392 | } |
---|
[490] | 393 | |
---|
[1184] | 394 | |
---|
[1639] | 395 | MPI_Comm_rank(intraComm, &rank) ; |
---|
[1152] | 396 | if (rank==0) isRoot=true; |
---|
[490] | 397 | else isRoot=false; |
---|
[492] | 398 | |
---|
| 399 | eventScheduler = new CEventScheduler(intraComm) ; |
---|
[300] | 400 | } |
---|
[490] | 401 | |
---|
[300] | 402 | void CServer::finalize(void) |
---|
| 403 | { |
---|
[361] | 404 | CTimer::get("XIOS").suspend() ; |
---|
[697] | 405 | |
---|
[492] | 406 | delete eventScheduler ; |
---|
[655] | 407 | |
---|
[1639] | 408 | for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++) |
---|
[2029] | 409 | /* MPI_Comm_free(&(*it)) */; // WARNING remove freeing communicator !! --> deadlock raised, to be checked |
---|
[983] | 410 | |
---|
[1639] | 411 | for (std::list<MPI_Comm>::iterator it = contextIntraComms.begin(); it != contextIntraComms.end(); it++) |
---|
| 412 | MPI_Comm_free(&(*it)); |
---|
[1071] | 413 | |
---|
[992] | 414 | // for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++) |
---|
| 415 | // MPI_Comm_free(&(*it)); |
---|
| 416 | |
---|
[1077] | 417 | // for (std::list<MPI_Comm>::iterator it = interCommLeft.begin(); it != interCommLeft.end(); it++) |
---|
| 418 | // MPI_Comm_free(&(*it)); |
---|
[983] | 419 | |
---|
[1639] | 420 | for (std::list<MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++) |
---|
[2029] | 421 | /* MPI_Comm_free(&(*it)) */ ; // WARNING remove freeing communicator !! --> deadlock raised, to be checked |
---|
[992] | 422 | |
---|
[1639] | 423 | MPI_Comm_free(&intraComm); |
---|
[655] | 424 | |
---|
[300] | 425 | if (!is_MPI_Initialized) |
---|
[490] | 426 | { |
---|
[300] | 427 | if (CXios::usingOasis) oasis_finalize(); |
---|
[1639] | 428 | else MPI_Finalize() ; |
---|
[300] | 429 | } |
---|
[347] | 430 | report(0)<<"Performance report : Time spent for XIOS : "<<CTimer::get("XIOS server").getCumulatedTime()<<endl ; |
---|
| 431 | report(0)<<"Performance report : Time spent in processing events : "<<CTimer::get("Process events").getCumulatedTime()<<endl ; |
---|
| 432 | report(0)<<"Performance report : Ratio : "<<CTimer::get("Process events").getCumulatedTime()/CTimer::get("XIOS server").getCumulatedTime()*100.<<"%"<<endl ; |
---|
[1158] | 433 | report(100)<<CTimer::getAllCumulatedTime()<<endl ; |
---|
[300] | 434 | } |
---|
[490] | 435 | |
---|
[300] | 436 | void CServer::eventLoop(void) |
---|
| 437 | { |
---|
| 438 | bool stop=false ; |
---|
[490] | 439 | |
---|
[347] | 440 | CTimer::get("XIOS server").resume() ; |
---|
[300] | 441 | while(!stop) |
---|
| 442 | { |
---|
| 443 | if (isRoot) |
---|
| 444 | { |
---|
| 445 | listenContext(); |
---|
[1148] | 446 | listenRootContext(); |
---|
[1587] | 447 | listenOasisEnddef() ; |
---|
| 448 | listenRootOasisEnddef() ; |
---|
[300] | 449 | if (!finished) listenFinalize() ; |
---|
| 450 | } |
---|
| 451 | else |
---|
| 452 | { |
---|
| 453 | listenRootContext(); |
---|
[1587] | 454 | listenRootOasisEnddef() ; |
---|
[300] | 455 | if (!finished) listenRootFinalize() ; |
---|
| 456 | } |
---|
[490] | 457 | |
---|
[300] | 458 | contextEventLoop() ; |
---|
| 459 | if (finished && contextList.empty()) stop=true ; |
---|
[956] | 460 | eventScheduler->checkEvent() ; |
---|
[300] | 461 | } |
---|
[347] | 462 | CTimer::get("XIOS server").suspend() ; |
---|
[300] | 463 | } |
---|
[490] | 464 | |
---|
[300] | 465 | void CServer::listenFinalize(void) |
---|
| 466 | { |
---|
[1639] | 467 | list<MPI_Comm>::iterator it, itr; |
---|
[300] | 468 | int msg ; |
---|
| 469 | int flag ; |
---|
[490] | 470 | |
---|
[992] | 471 | for(it=interCommLeft.begin();it!=interCommLeft.end();it++) |
---|
[300] | 472 | { |
---|
[1639] | 473 | MPI_Status status ; |
---|
[347] | 474 | traceOff() ; |
---|
[1639] | 475 | MPI_Iprobe(0,0,*it,&flag,&status) ; |
---|
[347] | 476 | traceOn() ; |
---|
[300] | 477 | if (flag==true) |
---|
| 478 | { |
---|
[1639] | 479 | MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ; |
---|
[1054] | 480 | info(20)<<" CServer : Receive client finalize"<<endl ; |
---|
| 481 | // Sending server finalize message to secondary servers (if any) |
---|
| 482 | for(itr=interCommRight.begin();itr!=interCommRight.end();itr++) |
---|
| 483 | { |
---|
[1639] | 484 | MPI_Send(&msg,1,MPI_INT,0,0,*itr) ; |
---|
[1054] | 485 | } |
---|
[2029] | 486 | /* MPI_Comm_free(&(*it)); */ // WARNING remove freeing communicator !! --> deadlock raised, to be checked |
---|
[992] | 487 | interCommLeft.erase(it) ; |
---|
[300] | 488 | break ; |
---|
| 489 | } |
---|
| 490 | } |
---|
[490] | 491 | |
---|
[1054] | 492 | if (interCommLeft.empty()) |
---|
[300] | 493 | { |
---|
| 494 | int i,size ; |
---|
[1639] | 495 | MPI_Comm_size(intraComm,&size) ; |
---|
| 496 | MPI_Request* requests= new MPI_Request[size-1] ; |
---|
| 497 | MPI_Status* status= new MPI_Status[size-1] ; |
---|
[490] | 498 | |
---|
[1639] | 499 | for(int i=1;i<size;i++) MPI_Isend(&msg,1,MPI_INT,i,4,intraComm,&requests[i-1]) ; |
---|
| 500 | MPI_Waitall(size-1,requests,status) ; |
---|
[300] | 501 | |
---|
| 502 | finished=true ; |
---|
| 503 | delete [] requests ; |
---|
| 504 | delete [] status ; |
---|
| 505 | } |
---|
| 506 | } |
---|
[490] | 507 | |
---|
| 508 | |
---|
[300] | 509 | void CServer::listenRootFinalize() |
---|
| 510 | { |
---|
| 511 | int flag ; |
---|
[1639] | 512 | MPI_Status status ; |
---|
[300] | 513 | int msg ; |
---|
[490] | 514 | |
---|
[347] | 515 | traceOff() ; |
---|
[1639] | 516 | MPI_Iprobe(0,4,intraComm, &flag, &status) ; |
---|
[347] | 517 | traceOn() ; |
---|
[300] | 518 | if (flag==true) |
---|
| 519 | { |
---|
[1639] | 520 | MPI_Recv(&msg,1,MPI_INT,0,4,intraComm,&status) ; |
---|
[300] | 521 | finished=true ; |
---|
| 522 | } |
---|
| 523 | } |
---|
[490] | 524 | |
---|
[1587] | 525 | |
---|
| 526 | /*! |
---|
| 527 | * Root process is listening for an order sent by client to call "oasis_enddef". |
---|
| 528 | * The root client of a compound send the order (tag 5). It is probed and received. |
---|
| 529 | * When the order has been received from each coumpound, the server root process ping the order to the root processes of the secondary levels of servers (if any). |
---|
| 530 | * After, it also inform (asynchronous call) other processes of the communicator that the oasis_enddef call must be done |
---|
| 531 | */ |
---|
| 532 | |
---|
| 533 | void CServer::listenOasisEnddef(void) |
---|
| 534 | { |
---|
| 535 | int flag ; |
---|
[1639] | 536 | MPI_Status status ; |
---|
| 537 | list<MPI_Comm>::iterator it; |
---|
[1587] | 538 | int msg ; |
---|
| 539 | static int nbCompound=0 ; |
---|
| 540 | int size ; |
---|
| 541 | static bool sent=false ; |
---|
[1639] | 542 | static MPI_Request* allRequests ; |
---|
| 543 | static MPI_Status* allStatus ; |
---|
[1587] | 544 | |
---|
| 545 | |
---|
| 546 | if (sent) |
---|
| 547 | { |
---|
[1639] | 548 | MPI_Comm_size(intraComm,&size) ; |
---|
| 549 | MPI_Testall(size,allRequests, &flag, allStatus) ; |
---|
[1587] | 550 | if (flag==true) |
---|
| 551 | { |
---|
| 552 | delete [] allRequests ; |
---|
| 553 | delete [] allStatus ; |
---|
| 554 | sent=false ; |
---|
| 555 | } |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | |
---|
| 559 | for(it=interCommLeft.begin();it!=interCommLeft.end();it++) |
---|
| 560 | { |
---|
[1639] | 561 | MPI_Status status ; |
---|
[1587] | 562 | traceOff() ; |
---|
[1639] | 563 | MPI_Iprobe(0,5,*it,&flag,&status) ; // tags oasis_endded = 5 |
---|
[1587] | 564 | traceOn() ; |
---|
| 565 | if (flag==true) |
---|
| 566 | { |
---|
[1639] | 567 | MPI_Recv(&msg,1,MPI_INT,0,5,*it,&status) ; // tags oasis_endded = 5 |
---|
[1587] | 568 | nbCompound++ ; |
---|
| 569 | if (nbCompound==interCommLeft.size()) |
---|
| 570 | { |
---|
[1639] | 571 | for (std::list<MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++) |
---|
[1587] | 572 | { |
---|
[1639] | 573 | MPI_Send(&msg,1,MPI_INT,0,5,*it) ; // tags oasis_endded = 5 |
---|
[1587] | 574 | } |
---|
[1639] | 575 | MPI_Comm_size(intraComm,&size) ; |
---|
| 576 | allRequests= new MPI_Request[size] ; |
---|
| 577 | allStatus= new MPI_Status[size] ; |
---|
| 578 | for(int i=0;i<size;i++) MPI_Isend(&msg,1,MPI_INT,i,5,intraComm,&allRequests[i]) ; // tags oasis_endded = 5 |
---|
[1587] | 579 | sent=true ; |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | } |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | /*! |
---|
| 586 | * Processes probes message from root process if oasis_enddef call must be done. |
---|
| 587 | * When the order is received it is scheduled to be treated in a synchronized way by all server processes of the communicator |
---|
| 588 | */ |
---|
| 589 | void CServer::listenRootOasisEnddef(void) |
---|
| 590 | { |
---|
| 591 | int flag ; |
---|
[1639] | 592 | MPI_Status status ; |
---|
[1587] | 593 | const int root=0 ; |
---|
| 594 | int msg ; |
---|
| 595 | static bool eventSent=false ; |
---|
| 596 | |
---|
| 597 | if (eventSent) |
---|
| 598 | { |
---|
| 599 | boost::hash<string> hashString; |
---|
| 600 | size_t hashId = hashString("oasis_enddef"); |
---|
| 601 | if (eventScheduler->queryEvent(0,hashId)) |
---|
| 602 | { |
---|
| 603 | oasis_enddef() ; |
---|
| 604 | eventSent=false ; |
---|
| 605 | } |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | traceOff() ; |
---|
[1639] | 609 | MPI_Iprobe(root,5,intraComm, &flag, &status) ; |
---|
[1587] | 610 | traceOn() ; |
---|
| 611 | if (flag==true) |
---|
| 612 | { |
---|
[1639] | 613 | MPI_Recv(&msg,1,MPI_INT,root,5,intraComm,&status) ; // tags oasis_endded = 5 |
---|
[1587] | 614 | boost::hash<string> hashString; |
---|
| 615 | size_t hashId = hashString("oasis_enddef"); |
---|
| 616 | eventScheduler->registerEvent(0,hashId); |
---|
| 617 | eventSent=true ; |
---|
| 618 | } |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | |
---|
| 622 | |
---|
| 623 | |
---|
| 624 | |
---|
[300] | 625 | void CServer::listenContext(void) |
---|
| 626 | { |
---|
[490] | 627 | |
---|
[1639] | 628 | MPI_Status status ; |
---|
[300] | 629 | int flag ; |
---|
[1158] | 630 | static char* buffer ; |
---|
[1639] | 631 | static MPI_Request request ; |
---|
[300] | 632 | static bool recept=false ; |
---|
| 633 | int rank ; |
---|
| 634 | int count ; |
---|
[490] | 635 | |
---|
[300] | 636 | if (recept==false) |
---|
| 637 | { |
---|
[347] | 638 | traceOff() ; |
---|
[1639] | 639 | MPI_Iprobe(MPI_ANY_SOURCE,1,CXios::globalComm, &flag, &status) ; |
---|
[347] | 640 | traceOn() ; |
---|
[490] | 641 | if (flag==true) |
---|
[300] | 642 | { |
---|
| 643 | rank=status.MPI_SOURCE ; |
---|
[1639] | 644 | MPI_Get_count(&status,MPI_CHAR,&count) ; |
---|
[300] | 645 | buffer=new char[count] ; |
---|
[1639] | 646 | MPI_Irecv((void*)buffer,count,MPI_CHAR,rank,1,CXios::globalComm,&request) ; |
---|
[490] | 647 | recept=true ; |
---|
[300] | 648 | } |
---|
| 649 | } |
---|
| 650 | else |
---|
| 651 | { |
---|
[347] | 652 | traceOff() ; |
---|
[1639] | 653 | MPI_Test(&request,&flag,&status) ; |
---|
[347] | 654 | traceOn() ; |
---|
[300] | 655 | if (flag==true) |
---|
| 656 | { |
---|
| 657 | rank=status.MPI_SOURCE ; |
---|
[1639] | 658 | MPI_Get_count(&status,MPI_CHAR,&count) ; |
---|
[1158] | 659 | recvContextMessage((void*)buffer,count) ; |
---|
| 660 | delete [] buffer ; |
---|
[490] | 661 | recept=false ; |
---|
[300] | 662 | } |
---|
| 663 | } |
---|
| 664 | } |
---|
[490] | 665 | |
---|
[300] | 666 | void CServer::recvContextMessage(void* buff,int count) |
---|
| 667 | { |
---|
[983] | 668 | static map<string,contextMessage> recvContextId; |
---|
[300] | 669 | map<string,contextMessage>::iterator it ; |
---|
| 670 | CBufferIn buffer(buff,count) ; |
---|
| 671 | string id ; |
---|
| 672 | int clientLeader ; |
---|
| 673 | int nbMessage ; |
---|
| 674 | |
---|
| 675 | buffer>>id>>nbMessage>>clientLeader ; |
---|
[490] | 676 | |
---|
[300] | 677 | it=recvContextId.find(id) ; |
---|
| 678 | if (it==recvContextId.end()) |
---|
[490] | 679 | { |
---|
[300] | 680 | contextMessage msg={0,0} ; |
---|
| 681 | pair<map<string,contextMessage>::iterator,bool> ret ; |
---|
| 682 | ret=recvContextId.insert(pair<string,contextMessage>(id,msg)) ; |
---|
| 683 | it=ret.first ; |
---|
[490] | 684 | } |
---|
[300] | 685 | it->second.nbRecv+=1 ; |
---|
| 686 | it->second.leaderRank+=clientLeader ; |
---|
[490] | 687 | |
---|
[300] | 688 | if (it->second.nbRecv==nbMessage) |
---|
[490] | 689 | { |
---|
[300] | 690 | int size ; |
---|
[1639] | 691 | MPI_Comm_size(intraComm,&size) ; |
---|
[1148] | 692 | // MPI_Request* requests= new MPI_Request[size-1] ; |
---|
| 693 | // MPI_Status* status= new MPI_Status[size-1] ; |
---|
[1639] | 694 | MPI_Request* requests= new MPI_Request[size] ; |
---|
| 695 | MPI_Status* status= new MPI_Status[size] ; |
---|
[490] | 696 | |
---|
[1148] | 697 | CMessage msg ; |
---|
| 698 | msg<<id<<it->second.leaderRank; |
---|
| 699 | int messageSize=msg.size() ; |
---|
| 700 | void * sendBuff = new char[messageSize] ; |
---|
| 701 | CBufferOut sendBuffer(sendBuff,messageSize) ; |
---|
| 702 | sendBuffer<<msg ; |
---|
| 703 | |
---|
| 704 | // Include root itself in order not to have a divergence |
---|
| 705 | for(int i=0; i<size; i++) |
---|
[300] | 706 | { |
---|
[1639] | 707 | MPI_Isend(sendBuff,sendBuffer.count(),MPI_CHAR,i,2,intraComm,&requests[i]) ; |
---|
[300] | 708 | } |
---|
| 709 | |
---|
| 710 | recvContextId.erase(it) ; |
---|
| 711 | delete [] requests ; |
---|
| 712 | delete [] status ; |
---|
| 713 | |
---|
| 714 | } |
---|
[490] | 715 | } |
---|
| 716 | |
---|
[300] | 717 | void CServer::listenRootContext(void) |
---|
| 718 | { |
---|
[1639] | 719 | MPI_Status status ; |
---|
[300] | 720 | int flag ; |
---|
[1270] | 721 | static std::vector<void*> buffers; |
---|
[1639] | 722 | static std::vector<MPI_Request> requests ; |
---|
[1270] | 723 | static std::vector<int> counts ; |
---|
[1271] | 724 | static std::vector<bool> isEventRegistered ; |
---|
[1323] | 725 | static std::vector<bool> isEventQueued ; |
---|
[1639] | 726 | MPI_Request request; |
---|
[1270] | 727 | |
---|
[300] | 728 | int rank ; |
---|
| 729 | const int root=0 ; |
---|
[1148] | 730 | boost::hash<string> hashString; |
---|
| 731 | size_t hashId = hashString("RegisterContext"); |
---|
[490] | 732 | |
---|
[1270] | 733 | // (1) Receive context id from the root, save it into a buffer |
---|
[1271] | 734 | traceOff() ; |
---|
[1639] | 735 | MPI_Iprobe(root,2,intraComm, &flag, &status) ; |
---|
[1271] | 736 | traceOn() ; |
---|
| 737 | if (flag==true) |
---|
[300] | 738 | { |
---|
[1271] | 739 | counts.push_back(0); |
---|
[1639] | 740 | MPI_Get_count(&status,MPI_CHAR,&(counts.back())) ; |
---|
[1271] | 741 | buffers.push_back(new char[counts.back()]) ; |
---|
| 742 | requests.push_back(request); |
---|
[1639] | 743 | MPI_Irecv((void*)(buffers.back()),counts.back(),MPI_CHAR,root,2,intraComm,&(requests.back())) ; |
---|
[1271] | 744 | isEventRegistered.push_back(false); |
---|
[1323] | 745 | isEventQueued.push_back(false); |
---|
[1271] | 746 | nbContexts++; |
---|
[300] | 747 | } |
---|
[1271] | 748 | |
---|
| 749 | for (int ctxNb = 0; ctxNb < nbContexts; ctxNb++ ) |
---|
[300] | 750 | { |
---|
[1271] | 751 | // (2) If context id is received, register an event |
---|
[1639] | 752 | MPI_Test(&requests[ctxNb],&flag,&status) ; |
---|
[1271] | 753 | if (flag==true && !isEventRegistered[ctxNb]) |
---|
[300] | 754 | { |
---|
[1271] | 755 | eventScheduler->registerEvent(ctxNb,hashId); |
---|
| 756 | isEventRegistered[ctxNb] = true; |
---|
[300] | 757 | } |
---|
[1271] | 758 | // (3) If event has been scheduled, call register context |
---|
[1323] | 759 | if (eventScheduler->queryEvent(ctxNb,hashId) && !isEventQueued[ctxNb]) |
---|
[1271] | 760 | { |
---|
| 761 | registerContext(buffers[ctxNb],counts[ctxNb]) ; |
---|
[1323] | 762 | isEventQueued[ctxNb] = true; |
---|
[1271] | 763 | delete [] buffers[ctxNb] ; |
---|
| 764 | } |
---|
[300] | 765 | } |
---|
[1271] | 766 | |
---|
[490] | 767 | } |
---|
| 768 | |
---|
[655] | 769 | void CServer::registerContext(void* buff, int count, int leaderRank) |
---|
[300] | 770 | { |
---|
| 771 | string contextId; |
---|
[655] | 772 | CBufferIn buffer(buff, count); |
---|
[1148] | 773 | // buffer >> contextId; |
---|
| 774 | buffer >> contextId>>leaderRank; |
---|
[983] | 775 | CContext* context; |
---|
[300] | 776 | |
---|
[680] | 777 | info(20) << "CServer : Register new Context : " << contextId << endl; |
---|
[490] | 778 | |
---|
[680] | 779 | if (contextList.find(contextId) != contextList.end()) |
---|
| 780 | ERROR("void CServer::registerContext(void* buff, int count, int leaderRank)", |
---|
| 781 | << "Context '" << contextId << "' has already been registred"); |
---|
[490] | 782 | |
---|
[983] | 783 | context=CContext::create(contextId); |
---|
[655] | 784 | contextList[contextId]=context; |
---|
| 785 | |
---|
[1148] | 786 | // Primary or classical server: create communication channel with a client |
---|
| 787 | // (1) create interComm (with a client) |
---|
| 788 | // (2) initialize client and server (contextClient and contextServer) |
---|
[1639] | 789 | MPI_Comm inter; |
---|
[1054] | 790 | if (serverLevel < 2) |
---|
| 791 | { |
---|
[1639] | 792 | MPI_Comm contextInterComm; |
---|
| 793 | MPI_Intercomm_create(intraComm, 0, CXios::globalComm, leaderRank, 10+leaderRank, &contextInterComm); |
---|
| 794 | MPI_Intercomm_merge(contextInterComm,1,&inter); |
---|
| 795 | MPI_Barrier(inter); |
---|
| 796 | MPI_Comm_free(&inter); |
---|
[1054] | 797 | context->initServer(intraComm,contextInterComm); |
---|
| 798 | contextInterComms.push_back(contextInterComm); |
---|
[1071] | 799 | |
---|
[1054] | 800 | } |
---|
[1148] | 801 | // Secondary server: create communication channel with a primary server |
---|
| 802 | // (1) duplicate interComm with a primary server |
---|
| 803 | // (2) initialize client and server (contextClient and contextServer) |
---|
| 804 | // Remark: in the case of the secondary server there is no need to create an interComm calling MPI_Intercomm_create, |
---|
| 805 | // because interComm of CContext is defined on the same processes as the interComm of CServer. |
---|
| 806 | // So just duplicate it. |
---|
[1054] | 807 | else if (serverLevel == 2) |
---|
| 808 | { |
---|
[1639] | 809 | MPI_Comm_dup(interCommLeft.front(), &inter); |
---|
[1071] | 810 | contextInterComms.push_back(inter); |
---|
| 811 | context->initServer(intraComm, contextInterComms.back()); |
---|
[1054] | 812 | } |
---|
| 813 | |
---|
[1148] | 814 | // Primary server: |
---|
| 815 | // (1) send create context message to secondary servers |
---|
| 816 | // (2) initialize communication channels with secondary servers (create contextClient and contextServer) |
---|
[1021] | 817 | if (serverLevel == 1) |
---|
[983] | 818 | { |
---|
[1054] | 819 | int i = 0, size; |
---|
[1639] | 820 | MPI_Comm_size(intraComm, &size) ; |
---|
| 821 | for (std::list<MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++, ++i) |
---|
[1054] | 822 | { |
---|
| 823 | StdString str = contextId +"_server_" + boost::lexical_cast<string>(i); |
---|
[1352] | 824 | CMessage msg; |
---|
| 825 | int messageSize; |
---|
[1077] | 826 | msg<<str<<size<<rank_ ; |
---|
[1054] | 827 | messageSize = msg.size() ; |
---|
| 828 | buff = new char[messageSize] ; |
---|
| 829 | CBufferOut buffer(buff,messageSize) ; |
---|
| 830 | buffer<<msg ; |
---|
[1639] | 831 | MPI_Send(buff, buffer.count(), MPI_CHAR, sndServerGlobalRanks[i], 1, CXios::globalComm) ; |
---|
| 832 | MPI_Comm_dup(*it, &inter); |
---|
[1071] | 833 | contextInterComms.push_back(inter); |
---|
[1639] | 834 | MPI_Comm_dup(intraComm, &inter); |
---|
[1071] | 835 | contextIntraComms.push_back(inter); |
---|
| 836 | context->initClient(contextIntraComms.back(), contextInterComms.back()) ; |
---|
[1054] | 837 | delete [] buff ; |
---|
| 838 | } |
---|
[983] | 839 | } |
---|
[490] | 840 | } |
---|
| 841 | |
---|
[1377] | 842 | void CServer::contextEventLoop(bool enableEventsProcessing /*= true*/) |
---|
[300] | 843 | { |
---|
[1130] | 844 | bool isFinalized ; |
---|
[300] | 845 | map<string,CContext*>::iterator it ; |
---|
[983] | 846 | |
---|
[490] | 847 | for(it=contextList.begin();it!=contextList.end();it++) |
---|
[300] | 848 | { |
---|
[1130] | 849 | isFinalized=it->second->isFinalized(); |
---|
| 850 | if (isFinalized) |
---|
[300] | 851 | { |
---|
| 852 | contextList.erase(it) ; |
---|
| 853 | break ; |
---|
| 854 | } |
---|
[1054] | 855 | else |
---|
[1377] | 856 | it->second->checkBuffersAndListen(enableEventsProcessing); |
---|
[300] | 857 | } |
---|
| 858 | } |
---|
[490] | 859 | |
---|
[1148] | 860 | //! Get rank of the current process in the intraComm |
---|
[490] | 861 | int CServer::getRank() |
---|
| 862 | { |
---|
[1167] | 863 | int rank; |
---|
[1639] | 864 | MPI_Comm_rank(intraComm,&rank); |
---|
[1167] | 865 | return rank; |
---|
[490] | 866 | } |
---|
| 867 | |
---|
[1168] | 868 | vector<int>& CServer::getSecondaryServerGlobalRanks() |
---|
| 869 | { |
---|
| 870 | return sndServerGlobalRanks; |
---|
| 871 | } |
---|
| 872 | |
---|
[523] | 873 | /*! |
---|
| 874 | * Open a file specified by a suffix and an extension and use it for the given file buffer. |
---|
| 875 | * The file name will be suffix+rank+extension. |
---|
| 876 | * |
---|
| 877 | * \param fileName[in] protype file name |
---|
| 878 | * \param ext [in] extension of the file |
---|
| 879 | * \param fb [in/out] the file buffer |
---|
| 880 | */ |
---|
| 881 | void CServer::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb) |
---|
| 882 | { |
---|
| 883 | StdStringStream fileNameClient; |
---|
| 884 | int numDigit = 0; |
---|
| 885 | int size = 0; |
---|
[1021] | 886 | int id; |
---|
[1639] | 887 | MPI_Comm_size(CXios::globalComm, &size); |
---|
[523] | 888 | while (size) |
---|
| 889 | { |
---|
| 890 | size /= 10; |
---|
| 891 | ++numDigit; |
---|
| 892 | } |
---|
[1167] | 893 | id = rank_; //getRank(); |
---|
[497] | 894 | |
---|
[1021] | 895 | fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << id << ext; |
---|
[523] | 896 | fb->open(fileNameClient.str().c_str(), std::ios::out); |
---|
| 897 | if (!fb->is_open()) |
---|
| 898 | ERROR("void CServer::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)", |
---|
[1542] | 899 | << std::endl << "Can not open <" << fileNameClient.str() << "> file to write the server log(s)."); |
---|
[523] | 900 | } |
---|
[490] | 901 | |
---|
[523] | 902 | /*! |
---|
| 903 | * \brief Open a file stream to write the info logs |
---|
| 904 | * Open a file stream with a specific file name suffix+rank |
---|
| 905 | * to write the info logs. |
---|
| 906 | * \param fileName [in] protype file name |
---|
| 907 | */ |
---|
| 908 | void CServer::openInfoStream(const StdString& fileName) |
---|
| 909 | { |
---|
| 910 | std::filebuf* fb = m_infoStream.rdbuf(); |
---|
| 911 | openStream(fileName, ".out", fb); |
---|
[490] | 912 | |
---|
[523] | 913 | info.write2File(fb); |
---|
| 914 | report.write2File(fb); |
---|
| 915 | } |
---|
[490] | 916 | |
---|
[523] | 917 | //! Write the info logs to standard output |
---|
| 918 | void CServer::openInfoStream() |
---|
| 919 | { |
---|
| 920 | info.write2StdOut(); |
---|
| 921 | report.write2StdOut(); |
---|
| 922 | } |
---|
[490] | 923 | |
---|
[523] | 924 | //! Close the info logs file if it opens |
---|
| 925 | void CServer::closeInfoStream() |
---|
| 926 | { |
---|
| 927 | if (m_infoStream.is_open()) m_infoStream.close(); |
---|
| 928 | } |
---|
| 929 | |
---|
| 930 | /*! |
---|
| 931 | * \brief Open a file stream to write the error log |
---|
| 932 | * Open a file stream with a specific file name suffix+rank |
---|
| 933 | * to write the error log. |
---|
| 934 | * \param fileName [in] protype file name |
---|
| 935 | */ |
---|
| 936 | void CServer::openErrorStream(const StdString& fileName) |
---|
| 937 | { |
---|
| 938 | std::filebuf* fb = m_errorStream.rdbuf(); |
---|
| 939 | openStream(fileName, ".err", fb); |
---|
| 940 | |
---|
| 941 | error.write2File(fb); |
---|
| 942 | } |
---|
| 943 | |
---|
| 944 | //! Write the error log to standard error output |
---|
| 945 | void CServer::openErrorStream() |
---|
| 946 | { |
---|
| 947 | error.write2StdErr(); |
---|
| 948 | } |
---|
| 949 | |
---|
| 950 | //! Close the error log file if it opens |
---|
| 951 | void CServer::closeErrorStream() |
---|
| 952 | { |
---|
| 953 | if (m_errorStream.is_open()) m_errorStream.close(); |
---|
| 954 | } |
---|
[300] | 955 | } |
---|