Changeset 1037 for XIOS/dev/branch_yushan/src/server.cpp
- Timestamp:
- 01/25/17 16:25:17 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_yushan/src/server.cpp
r1032 r1037 9 9 #include <boost/functional/hash.hpp> 10 10 #include <boost/algorithm/string.hpp> 11 #include "mpi.hpp"11 //#include "mpi.hpp" 12 12 #include "tracer.hpp" 13 13 #include "timer.hpp" … … 26 26 bool CServer::finished=false ; 27 27 bool CServer::is_MPI_Initialized ; 28 29 28 30 CEventScheduler* CServer::eventScheduler = 0; 29 31 30 32 void CServer::initialize(void) 31 33 { 32 int initialized ;33 MPI_Initialized(&initialized) ;34 if (initialized) is_MPI_Initialized=true ;35 else is_MPI_Initialized=false ;36 37 34 // Not using OASIS 38 35 if (!CXios::usingOasis) 39 36 { 40 37 41 if (!is_MPI_Initialized)42 {43 MPI_Init(NULL, NULL);44 }45 38 CTimer::get("XIOS").resume() ; 46 39 … … 50 43 unsigned long* hashAll ; 51 44 52 // int rank ; 45 53 46 int size ; 54 47 int myColor ; … … 77 70 78 71 myColor=colors[hashServer] ; 79 MPI_Comm_split(MPI_COMM_WORLD,myColor,rank,&intraComm) ; 80 72 73 74 MPI_Comm_split(CXios::globalComm,myColor,rank,&intraComm) ; 75 76 81 77 int serverLeader=leaders[hashServer] ; 82 78 int clientLeader; … … 96 92 MPI_Intercomm_create(intraComm,0,CXios::globalComm,clientLeader,0,&newComm) ; 97 93 interComm.push_back(newComm) ; 94 printf("after inter create, interComm.size = %lu\n", interComm.size()); 98 95 } 99 96 } … … 104 101 else 105 102 { 106 // int rank ,size;107 103 int size; 108 104 if (!is_MPI_Initialized) oasis_init(CXios::xiosCodeId); … … 148 144 149 145 delete eventScheduler ; 146 147 150 148 151 149 for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++) 152 150 MPI_Comm_free(&(*it)); 151 153 152 for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++) 154 153 MPI_Comm_free(&(*it)); 154 155 155 MPI_Comm_free(&intraComm); 156 156 … … 158 158 { 159 159 if (CXios::usingOasis) oasis_finalize(); 160 else MPI_Finalize() ;160 else {MPI_Finalize() ; printf("CServer::finalize called MPI_finalize\n");} 161 161 } 162 163 162 164 report(0)<<"Performance report : Time spent for XIOS : "<<CTimer::get("XIOS server").getCumulatedTime()<<endl ; 163 165 report(0)<<"Performance report : Time spent in processing events : "<<CTimer::get("Process events").getCumulatedTime()<<endl ; … … 174 176 if (isRoot) 175 177 { 176 listenContext(); 177 if (!finished) listenFinalize() ; 178 listenContext(); 179 if (!finished) listenFinalize() ; 178 180 } 179 181 else 180 182 { 181 listenRootContext(); 182 if (!finished) listenRootFinalize() ; 183 } 184 183 listenRootContext(); 184 if (!finished) 185 { 186 listenRootFinalize() ; 187 } 188 } 189 185 190 contextEventLoop() ; 186 191 if (finished && contextList.empty()) stop=true ; 192 187 193 eventScheduler->checkEvent() ; 188 194 } 195 196 189 197 CTimer::get("XIOS server").suspend() ; 190 198 } … … 195 203 int msg ; 196 204 int flag ; 205 197 206 198 207 for(it=interComm.begin();it!=interComm.end();it++) … … 205 214 { 206 215 MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ; 216 printf(" CServer : Receive client finalize\n"); 207 217 info(20)<<" CServer : Receive client finalize"<<endl ; 218 208 219 MPI_Comm_free(&(*it)); 209 220 interComm.erase(it) ; … … 234 245 MPI_Status status ; 235 246 int msg ; 236 247 237 248 traceOff() ; 238 249 MPI_Iprobe(0,4,intraComm, &flag, &status) ; … … 249 260 250 261 MPI_Status status ; 251 int flag ;252 static char* buffer ;262 int flag = false ; 263 static void* buffer ; 253 264 static MPI_Request request ; 254 265 static bool recept=false ; 255 266 int rank ; 256 int count ; 267 int count ; 257 268 258 269 if (recept==false) 259 { 270 { 260 271 traceOff() ; 261 272 MPI_Iprobe(MPI_ANY_SOURCE,1,CXios::globalComm, &flag, &status) ; 262 273 traceOn() ; 274 263 275 if (flag==true) 264 276 { 277 #ifdef _usingMPI 265 278 rank=status.MPI_SOURCE ; 279 #elif _usingEP 280 rank= status.ep_src ; 281 #endif 266 282 MPI_Get_count(&status,MPI_CHAR,&count) ; 267 283 buffer=new char[count] ; 268 MPI_Irecv( (void*)buffer,count,MPI_CHAR,rank,1,CXios::globalComm,&request) ;284 MPI_Irecv(buffer,count,MPI_CHAR,rank,1,CXios::globalComm,&request) ; 269 285 recept=true ; 270 286 } 287 271 288 } 272 289 else … … 277 294 if (flag==true) 278 295 { 296 #ifdef _usingMPI 279 297 rank=status.MPI_SOURCE ; 298 #elif _usingEP 299 rank= status.ep_src ; 300 #endif 280 301 MPI_Get_count(&status,MPI_CHAR,&count) ; 281 recvContextMessage((void*)buffer,count) ; 302 recvContextMessage(buffer,count) ; 303 printf("listerContext register context OK, interComm size = %lu\n", interComm.size()); 304 282 305 delete [] buffer ; 283 306 recept=false ; … … 322 345 MPI_Waitall(size-1,requests,status) ; 323 346 registerContext(buff,count,it->second.leaderRank) ; 347 printf("recvContextMessage register context OK\n"); 324 348 325 349 recvContextId.erase(it) ; … … 335 359 MPI_Status status ; 336 360 int flag ; 337 static char* buffer ;361 static void* buffer ; 338 362 static MPI_Request request ; 339 363 static bool recept=false ; … … 341 365 int count ; 342 366 const int root=0 ; 367 343 368 344 369 if (recept==false) … … 351 376 MPI_Get_count(&status,MPI_CHAR,&count) ; 352 377 buffer=new char[count] ; 353 MPI_Irecv( (void*)buffer,count,MPI_CHAR,root,2,intraComm,&request) ;378 MPI_Irecv(buffer,count,MPI_CHAR,root,2,intraComm,&request) ; 354 379 recept=true ; 355 380 } … … 361 386 { 362 387 MPI_Get_count(&status,MPI_CHAR,&count) ; 363 registerContext((void*)buffer,count) ; 388 registerContext(buffer,count) ; 389 printf("listenRootContext register context OK, interComm size = %lu\n", interComm.size()); 364 390 delete [] buffer ; 365 391 recept=false ; … … 381 407 382 408 MPI_Comm contextIntercomm; 409 383 410 MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextIntercomm); 384 411 … … 386 413 MPI_Intercomm_merge(contextIntercomm,1,&inter); 387 414 MPI_Barrier(inter); 415 388 416 389 417 CContext* context=CContext::create(contextId); 390 418 contextList[contextId]=context; 391 419 context->initServer(intraComm,contextIntercomm); 420 421 392 422 393 423 contextInterComms.push_back(contextIntercomm); 424 425 394 426 MPI_Comm_free(&inter); 427 428 printf(" **** server: register context OK\n"); 395 429 } 396 430
Note: See TracChangeset
for help on using the changeset viewer.