Ignore:
Timestamp:
11/07/16 17:55:55 (7 years ago)
Author:
oabramkina
Message:

My branch

Location:
XIOS/dev/dev_olga
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_olga/src/server.cpp

    r956 r983  
    33#include "cxios.hpp" 
    44#include "server.hpp" 
     5#include "client.hpp" 
    56#include "type.hpp" 
    67#include "context.hpp" 
     
    1920    list<MPI_Comm> CServer::interComm ; 
    2021    std::list<MPI_Comm> CServer::contextInterComms; 
    21     bool CServer::isRoot ; 
     22    bool CServer::isRoot = false ; 
    2223    int CServer::rank = INVALID_RANK; 
    2324    StdOFStream CServer::m_infoStream; 
     
    2728    bool CServer::is_MPI_Initialized ; 
    2829    CEventScheduler* CServer::eventScheduler = 0; 
    29     
     30 
     31//--------------------------------------------------------------- 
     32/*! 
     33 * \fn void CServer::initialize(void) 
     34 * Function creates intra and inter comm for each initialized server pool 
     35 */ 
    3036    void CServer::initialize(void) 
    3137    { 
     
    4551        CTimer::get("XIOS").resume() ; 
    4652 
     53        int nbSrvLevels = 2; 
     54 
    4755        boost::hash<string> hashString ; 
    48  
    49         unsigned long hashServer=hashString(CXios::xiosCodeId) ; 
     56        unsigned long hashServer1 = hashString(CXios::xiosCodeIdPrm); 
     57        unsigned long hashServer2 = hashString(CXios::xiosCodeIdSnd); 
     58        unsigned long hashServer = (CXios::serverLevel < 2)  ? hashServer1 : hashServer2; 
     59 
    5060        unsigned long* hashAll ; 
    5161 
     
    5666        MPI_Comm newComm ; 
    5767 
    58         MPI_Comm_size(CXios::globalComm,&size) ; 
    59         MPI_Comm_rank(CXios::globalComm,&rank); 
     68        MPI_Comm_size(CXios::globalComm, &size) ; 
     69        MPI_Comm_rank(CXios::globalComm, &rank); 
    6070        hashAll=new unsigned long[size] ; 
    61  
    62         MPI_Allgather(&hashServer,1,MPI_LONG,hashAll,1,MPI_LONG,CXios::globalComm) ; 
     71        MPI_Allgather(&hashServer, 1, MPI_LONG, hashAll, 1, MPI_LONG, CXios::globalComm) ; 
    6372 
    6473        map<unsigned long, int> colors ; 
     
    7786 
    7887        myColor=colors[hashServer] ; 
    79         MPI_Comm_split(MPI_COMM_WORLD,myColor,rank,&intraComm) ; 
    80  
    81         int serverLeader=leaders[hashServer] ; 
    82         int clientLeader; 
    83  
    84          serverLeader=leaders[hashServer] ; 
    85          for(it=leaders.begin();it!=leaders.end();it++) 
    86          { 
    87            if (it->first!=hashServer) 
    88            { 
    89              clientLeader=it->second ; 
    90              int intraCommSize, intraCommRank ; 
    91              MPI_Comm_size(intraComm,&intraCommSize) ; 
    92              MPI_Comm_rank(intraComm,&intraCommRank) ; 
    93              info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize 
    94                      <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ; 
    95  
    96              MPI_Intercomm_create(intraComm,0,CXios::globalComm,clientLeader,0,&newComm) ; 
    97              interComm.push_back(newComm) ; 
    98            } 
    99          } 
    100  
    101          delete [] hashAll ; 
     88        MPI_Comm_split(MPI_COMM_WORLD, myColor, rank, &intraComm) ; 
     89 
     90        if (CXios::serverLevel == 0) 
     91        { 
     92          int clientLeader; 
     93          for(it=leaders.begin();it!=leaders.end();it++) 
     94          { 
     95            if (it->first!=hashServer) 
     96            { 
     97              clientLeader=it->second ; 
     98              int intraCommSize, intraCommRank ; 
     99              MPI_Comm_size(intraComm,&intraCommSize) ; 
     100              MPI_Comm_rank(intraComm,&intraCommRank) ; 
     101              info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize 
     102                       <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ; 
     103 
     104               MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 
     105               interComm.push_back(newComm) ; 
     106            } 
     107          } 
     108        } 
     109 
     110        else if ((CXios::serverLevel == 1)) 
     111        { 
     112          int clientLeader; 
     113          int srvSndLeader; 
     114          for(it=leaders.begin();it!=leaders.end();it++) 
     115          { 
     116            if (it->first != hashServer2) 
     117            { 
     118              if (it->first != hashServer1) 
     119              { 
     120                clientLeader=it->second ; 
     121                int intraCommSize, intraCommRank ; 
     122                MPI_Comm_size(intraComm,&intraCommSize) ; 
     123                MPI_Comm_rank(intraComm,&intraCommRank) ; 
     124                info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize 
     125                         <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ; 
     126                MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 
     127                interComm.push_back(newComm) ; 
     128              } 
     129            } 
     130            else 
     131            { 
     132              srvSndLeader = it->second; 
     133            } 
     134          } 
     135 
     136        CClient::initializeClientOnServer(rank, intraComm, srvSndLeader); 
     137        } 
     138 
     139        else // secondary server pool 
     140        { 
     141          int clientLeader; 
     142          for(it=leaders.begin();it!=leaders.end();it++) 
     143          { 
     144            if (it->first == hashServer1) 
     145            { 
     146              // no changes needed here to create one context per process of the secondary server pool 
     147              clientLeader=it->second ; 
     148              int intraCommSize, intraCommRank ; 
     149              MPI_Comm_size(intraComm,&intraCommSize) ; 
     150              MPI_Comm_rank(intraComm,&intraCommRank) ; 
     151              info(50)<<"intercommCreate::server "<<rank<<" intraCommSize : "<<intraCommSize 
     152                       <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ; 
     153 
     154              MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ; 
     155              interComm.push_back(newComm) ; 
     156 
     157              break; 
     158            } 
     159          } 
     160        } 
     161 
     162        delete [] hashAll ; 
     163 
    102164      } 
    103165      // using OASIS 
     
    145207    void CServer::finalize(void) 
    146208    { 
     209      if (CXios::serverLevel == 1) 
     210      { 
     211        CClient::finalize(); 
     212      } 
     213 
    147214      CTimer::get("XIOS").suspend() ; 
    148215      
     
    151218      for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++) 
    152219        MPI_Comm_free(&(*it)); 
     220 
    153221      for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++) 
    154222        MPI_Comm_free(&(*it)); 
     223 
    155224      MPI_Comm_free(&intraComm); 
    156225 
     
    172241       while(!stop) 
    173242       { 
     243 
    174244         if (isRoot) 
    175245         { 
     
    186256         if (finished && contextList.empty()) stop=true ; 
    187257         eventScheduler->checkEvent() ; 
     258 
    188259       } 
    189260       CTimer::get("XIOS server").suspend() ; 
     
    288359     void CServer::recvContextMessage(void* buff,int count) 
    289360     { 
    290        static map<string,contextMessage> recvContextId ; 
     361       static map<string,contextMessage> recvContextId; 
     362 
    291363       map<string,contextMessage>::iterator it ; 
    292364 
     
    362434           MPI_Get_count(&status,MPI_CHAR,&count) ; 
    363435           registerContext(buffer,count) ; 
     436 
    364437           delete [] buffer ; 
    365438           recept=false ; 
     
    373446       CBufferIn buffer(buff, count); 
    374447       buffer >> contextId; 
     448       CContext* context; 
    375449 
    376450       info(20) << "CServer : Register new Context : " << contextId << endl; 
     
    380454               << "Context '" << contextId << "' has already been registred"); 
    381455 
    382        MPI_Comm contextIntercomm; 
    383        MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextIntercomm); 
     456       MPI_Comm contextInterComm; 
     457       MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextInterComm); 
    384458 
    385459       MPI_Comm inter; 
    386        MPI_Intercomm_merge(contextIntercomm,1,&inter); 
     460       MPI_Intercomm_merge(contextInterComm,1,&inter); 
    387461       MPI_Barrier(inter); 
    388462 
    389        CContext* context=CContext::create(contextId); 
     463       context=CContext::create(contextId); 
    390464       contextList[contextId]=context; 
    391        context->initServer(intraComm,contextIntercomm); 
    392  
    393        contextInterComms.push_back(contextIntercomm); 
     465       context->initServer(intraComm,contextInterComm); 
     466       contextInterComms.push_back(contextInterComm); 
     467 
     468       if (CXios::serverLevel == 1) 
     469       { 
     470         CClient::registerContext(contextId, intraComm); 
     471       } 
     472 
    394473       MPI_Comm_free(&inter); 
     474 
    395475     } 
    396476 
     
    399479       bool finished ; 
    400480       map<string,CContext*>::iterator it ; 
     481 
    401482       for(it=contextList.begin();it!=contextList.end();it++) 
    402483       { 
     
    408489         } 
    409490       } 
    410  
    411491     } 
    412492 
Note: See TracChangeset for help on using the changeset viewer.