Ignore:
Timestamp:
07/24/15 16:40:07 (9 years ago)
Author:
rlacroix
Message:

Properly release all MPI resources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/server.cpp

    r597 r655  
    1818    MPI_Comm CServer::intraComm ; 
    1919    list<MPI_Comm> CServer::interComm ; 
     20    std::list<MPI_Comm> CServer::contextInterComms; 
    2021    bool CServer::isRoot ; 
    2122    int CServer::rank = INVALID_RANK; 
     
    110111 
    111112        CTimer::get("XIOS").resume() ; 
    112         oasis_get_localcomm(intraComm) ; 
     113        MPI_Comm localComm; 
     114        oasis_get_localcomm(localComm); 
     115        MPI_Comm_dup(localComm, &intraComm); 
     116 
    113117        MPI_Comm_rank(intraComm,&rank) ; 
    114118        MPI_Comm_size(intraComm,&size) ; 
     
    144148    { 
    145149      CTimer::get("XIOS").suspend() ; 
    146        
     150 
    147151      delete eventScheduler ; 
    148        
     152 
     153      for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++) 
     154        MPI_Comm_free(&(*it)); 
     155      for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++) 
     156        MPI_Comm_free(&(*it)); 
     157      MPI_Comm_free(&intraComm); 
     158 
    149159      if (!is_MPI_Initialized) 
    150160      { 
     
    198208              MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ; 
    199209              info(20)<<" CServer : Receive client finalize"<<endl ; 
     210              MPI_Comm_free(&(*it)); 
    200211              interComm.erase(it) ; 
    201212              break ; 
     
    361372 
    362373 
    363      void CServer::registerContext(void* buff,int count, int leaderRank) 
    364      { 
    365  
     374     void CServer::registerContext(void* buff, int count, int leaderRank) 
     375     { 
    366376       string contextId; 
    367        CBufferIn buffer(buff,count) ; 
    368  
    369        buffer>>contextId ; 
    370        MPI_Comm contextIntercomm ; 
    371        MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextIntercomm) ; 
    372  
    373        info(20)<<"CServer : Register new Context : "<<contextId<<endl  ; 
    374        MPI_Comm inter ; 
    375        MPI_Intercomm_merge(contextIntercomm,1,&inter) ; 
    376        MPI_Barrier(inter) ; 
     377       CBufferIn buffer(buff, count); 
     378       buffer >> contextId; 
     379 
     380       info(20)<<"CServer : Register new Context : "<<contextId<<endl; 
     381 
    377382       if (contextList.find(contextId)!=contextList.end()) 
    378383        ERROR("void CServer::registerContext(void* buff,int count, int leaderRank)", 
    379               <<"Context has already been registred") ; 
    380  
    381       CContext* context=CContext::create(contextId) ; 
    382       contextList[contextId]=context ; 
    383       context->initServer(intraComm,contextIntercomm) ; 
    384  
     384              << "Context has already been registred"); 
     385 
     386       MPI_Comm contextIntercomm; 
     387       MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextIntercomm); 
     388 
     389       MPI_Comm inter; 
     390       MPI_Intercomm_merge(contextIntercomm,1,&inter); 
     391       MPI_Barrier(inter); 
     392 
     393       CContext* context=CContext::create(contextId); 
     394       contextList[contextId]=context; 
     395       context->initServer(intraComm,contextIntercomm); 
     396 
     397       contextInterComms.push_back(contextIntercomm); 
     398       MPI_Comm_free(&inter); 
    385399     } 
    386400 
Note: See TracChangeset for help on using the changeset viewer.