Ignore:
Timestamp:
01/10/17 14:36:29 (7 years ago)
Author:
oabramkina
Message:

Intermeadiate version for merging with new server functionalities.

File:
1 edited

Legend:

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

    r1009 r1021  
    2222    list<MPI_Comm> CServer::interComm ; 
    2323    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; 
    2628    bool CServer::isRoot = false ; 
    2729    int CServer::rank = INVALID_RANK; 
    28     int CServer::rankSndServers = 0; 
    2930    StdOFStream CServer::m_infoStream; 
    3031    StdOFStream CServer::m_errorStream; 
     
    3738/*! 
    3839 * \fn void CServer::initialize(void) 
    39  * Function creates intra and inter comm for each initialized server pool 
     40 * Creates intraComm and interComm for a server pool (primary or secondary). 
    4041 */ 
    4142    void CServer::initialize(void) 
     
    4647      else is_MPI_Initialized=false ; 
    4748 
    48  
    4949      // Not using OASIS 
    5050      if (!CXios::usingOasis) 
     
    5858 
    5959        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); 
    6364 
    6465        unsigned long* hashAll ; 
    65         unsigned long* hashAllServers ; 
     66//        unsigned long* hashAllServers ; 
    6667 
    6768//        int rank ; 
     
    6970        int myColor ; 
    7071        int i,c ; 
    71         MPI_Comm newComm, serversInterComm; 
     72        MPI_Comm newComm, serversComm; 
    7273 
    7374        MPI_Comm_size(CXios::globalComm, &size) ; 
     
    7778        MPI_Allgather(&hashServer, 1, MPI_LONG, hashAll, 1, MPI_LONG, CXios::globalComm) ; 
    7879 
    79         map<unsigned long, int> colors, colorsServers ; 
     80        map<unsigned long, int> colors ; 
    8081        map<unsigned long, int> leaders ; 
    8182        map<unsigned long, int>::iterator it ; 
    82 //        map<unsigned long, int> leadersServers ; 
    83         vector<int> leadersServers; 
    8483 
    8584        for(i=0,c=0;i<size;i++) 
     
    9392        } 
    9493 
    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) ) 
    101102          { 
    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; 
    127110          } 
    128111        } 
    129112 
    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) 
    166116        { 
    167117          int clientLeader; 
     
    183133          } 
    184134        } 
    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++) 
    188139          { 
    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) 
    193141            { 
    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) ; 
    222151            } 
    223152            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) 
    247157          { 
    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 
    295180        delete [] hashAll ; 
    296181 
     
    416301             { 
    417302               MPI_Send(&msg,1,MPI_INT,0,0,*itr) ; 
    418  
    419303//               MPI_Comm_free(&(*itr)); 
    420304//               interCommRight.erase(itr) ; 
     
    612496       contextInterComms.push_back(contextInterComm); 
    613497 
    614        if (CXios::serverLevel == 1) 
     498       if (serverLevel == 1) 
    615499       { 
    616500//         CClient::registerContext(contextId, intraComm); 
    617          CClient::registerContextOnSrvPools(contextId, intraComm); 
     501         CClient::registerContextByClienOfServer(contextId, intraComm); 
    618502       } 
    619503 
     
    657541      int numDigit = 0; 
    658542      int size = 0; 
    659       int mpiRank; 
     543      int id; 
    660544      MPI_Comm_size(CXios::globalComm, &size); 
    661545      while (size) 
     
    665549      } 
    666550 
    667       if (nbSndSrvPools < 2) 
    668         mpiRank = getRank(); 
     551      if (!CXios::usingServer2) 
     552        id = getRank(); 
    669553      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; 
    672561      fb->open(fileNameClient.str().c_str(), std::ios::out); 
    673562      if (!fb->is_open()) 
Note: See TracChangeset for help on using the changeset viewer.