Ignore:
Timestamp:
01/25/17 16:25:17 (7 years ago)
Author:
yushan
Message:

initialize the branch

File:
1 edited

Legend:

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

    r1032 r1037  
    99#include <boost/functional/hash.hpp> 
    1010#include <boost/algorithm/string.hpp> 
    11 #include "mpi.hpp" 
     11//#include "mpi.hpp" 
    1212#include "tracer.hpp" 
    1313#include "timer.hpp" 
     
    2626    bool CServer::finished=false ; 
    2727    bool CServer::is_MPI_Initialized ; 
     28 
     29     
    2830    CEventScheduler* CServer::eventScheduler = 0; 
    2931    
    3032    void CServer::initialize(void) 
    3133    { 
    32       int initialized ; 
    33       MPI_Initialized(&initialized) ; 
    34       if (initialized) is_MPI_Initialized=true ; 
    35       else is_MPI_Initialized=false ; 
    36  
    3734      // Not using OASIS 
    3835      if (!CXios::usingOasis) 
    3936      { 
    4037 
    41         if (!is_MPI_Initialized) 
    42         { 
    43           MPI_Init(NULL, NULL); 
    44         } 
    4538        CTimer::get("XIOS").resume() ; 
    4639 
     
    5043        unsigned long* hashAll ; 
    5144 
    52 //        int rank ; 
     45 
    5346        int size ; 
    5447        int myColor ; 
     
    7770 
    7871        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         
    8177        int serverLeader=leaders[hashServer] ; 
    8278        int clientLeader; 
     
    9692             MPI_Intercomm_create(intraComm,0,CXios::globalComm,clientLeader,0,&newComm) ; 
    9793             interComm.push_back(newComm) ; 
     94             printf("after inter create, interComm.size = %lu\n", interComm.size()); 
    9895           } 
    9996         } 
     
    104101      else 
    105102      { 
    106 //        int rank ,size; 
    107103        int size; 
    108104        if (!is_MPI_Initialized) oasis_init(CXios::xiosCodeId); 
     
    148144      
    149145      delete eventScheduler ; 
     146       
     147       
    150148 
    151149      for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++) 
    152150        MPI_Comm_free(&(*it)); 
     151 
    153152      for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++) 
    154153        MPI_Comm_free(&(*it)); 
     154 
    155155      MPI_Comm_free(&intraComm); 
    156156 
     
    158158      { 
    159159        if (CXios::usingOasis) oasis_finalize(); 
    160         else MPI_Finalize() ; 
     160        else  {MPI_Finalize() ; printf("CServer::finalize called MPI_finalize\n");} 
    161161      } 
     162 
     163       
    162164      report(0)<<"Performance report : Time spent for XIOS : "<<CTimer::get("XIOS server").getCumulatedTime()<<endl  ; 
    163165      report(0)<<"Performance report : Time spent in processing events : "<<CTimer::get("Process events").getCumulatedTime()<<endl  ; 
     
    174176         if (isRoot) 
    175177         { 
    176            listenContext(); 
    177            if (!finished) listenFinalize() ; 
     178           listenContext();  
     179           if (!finished) listenFinalize() ;  
    178180         } 
    179181         else 
    180182         { 
    181            listenRootContext(); 
    182            if (!finished) listenRootFinalize() ; 
    183          } 
    184  
     183           listenRootContext();  
     184           if (!finished)  
     185           { 
     186             listenRootFinalize() ;  
     187           } 
     188         } 
     189          
    185190         contextEventLoop() ; 
    186191         if (finished && contextList.empty()) stop=true ; 
     192          
    187193         eventScheduler->checkEvent() ; 
    188194       } 
     195        
     196        
    189197       CTimer::get("XIOS server").suspend() ; 
    190198     } 
     
    195203        int msg ; 
    196204        int flag ; 
     205         
    197206 
    198207        for(it=interComm.begin();it!=interComm.end();it++) 
     
    205214           { 
    206215              MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ; 
     216              printf(" CServer : Receive client finalize\n"); 
    207217              info(20)<<" CServer : Receive client finalize"<<endl ; 
     218 
    208219              MPI_Comm_free(&(*it)); 
    209220              interComm.erase(it) ; 
     
    234245        MPI_Status status ; 
    235246        int msg ; 
    236  
     247         
    237248        traceOff() ; 
    238249        MPI_Iprobe(0,4,intraComm, &flag, &status) ; 
     
    249260 
    250261       MPI_Status status ; 
    251        int flag ; 
    252        static char* buffer ; 
     262       int flag = false ; 
     263       static void* buffer ; 
    253264       static MPI_Request request ; 
    254265       static bool recept=false ; 
    255266       int rank ; 
    256        int count ; 
     267       int count ;  
    257268 
    258269       if (recept==false) 
    259        { 
     270       {       
    260271         traceOff() ; 
    261272         MPI_Iprobe(MPI_ANY_SOURCE,1,CXios::globalComm, &flag, &status) ; 
    262273         traceOn() ; 
     274          
    263275         if (flag==true) 
    264276         { 
     277           #ifdef _usingMPI 
    265278           rank=status.MPI_SOURCE ; 
     279           #elif _usingEP 
     280           rank= status.ep_src ; 
     281           #endif 
    266282           MPI_Get_count(&status,MPI_CHAR,&count) ; 
    267283           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) ; 
    269285           recept=true ; 
    270286         } 
     287           
    271288       } 
    272289       else 
     
    277294         if (flag==true) 
    278295         { 
     296           #ifdef _usingMPI 
    279297           rank=status.MPI_SOURCE ; 
     298           #elif _usingEP 
     299           rank= status.ep_src ; 
     300           #endif 
    280301           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            
    282305           delete [] buffer ; 
    283306           recept=false ; 
     
    322345         MPI_Waitall(size-1,requests,status) ; 
    323346         registerContext(buff,count,it->second.leaderRank) ; 
     347         printf("recvContextMessage register context OK\n"); 
    324348 
    325349         recvContextId.erase(it) ; 
     
    335359       MPI_Status status ; 
    336360       int flag ; 
    337        static char* buffer ; 
     361       static void* buffer ; 
    338362       static MPI_Request request ; 
    339363       static bool recept=false ; 
     
    341365       int count ; 
    342366       const int root=0 ; 
     367        
    343368 
    344369       if (recept==false) 
     
    351376           MPI_Get_count(&status,MPI_CHAR,&count) ; 
    352377           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) ; 
    354379           recept=true ; 
    355380         } 
     
    361386         { 
    362387           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()); 
    364390           delete [] buffer ; 
    365391           recept=false ; 
     
    381407 
    382408       MPI_Comm contextIntercomm; 
     409        
    383410       MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextIntercomm); 
    384411 
     
    386413       MPI_Intercomm_merge(contextIntercomm,1,&inter); 
    387414       MPI_Barrier(inter); 
     415        
    388416 
    389417       CContext* context=CContext::create(contextId); 
    390418       contextList[contextId]=context; 
    391419       context->initServer(intraComm,contextIntercomm); 
     420        
     421        
    392422 
    393423       contextInterComms.push_back(contextIntercomm); 
     424        
     425        
    394426       MPI_Comm_free(&inter); 
     427        
     428       printf(" ****   server: register context OK\n"); 
    395429     } 
    396430 
Note: See TracChangeset for help on using the changeset viewer.