Ignore:
Timestamp:
09/26/14 14:52:04 (10 years ago)
Author:
mhnguyen
Message:

Implementing print output in seperate files

+) Add an option to write information into standard output or into files,
each of which is created by a process
+) Add a new file for global data (constant, value macro, etc)
+) Do a minor change in how to generate doxygen

Test
+) On Curie, with two modes: only client (connected) and client-server
+) All tests passed, each client prints out its info in a seperate file

File:
1 edited

Legend:

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

    r483 r490  
     1#include "globalScopeData.hpp" 
    12#include "xmlioserver_spl.hpp" 
    23#include "cxios.hpp" 
     
    1314 
    1415namespace xios 
    15 {                       
     16{ 
    1617    MPI_Comm CServer::intraComm ; 
    1718    list<MPI_Comm> CServer::interComm ; 
    1819    bool CServer::isRoot ; 
    19     int CServer::rank ; 
    20     map<string,CContext*> CServer::contextList ;     
     20    int CServer::rank = INVALID_RANK; 
     21    StdOFStream CServer::m_infoStream; 
     22    map<string,CContext*> CServer::contextList ; 
    2123    bool CServer::finished=false ; 
    2224    bool CServer::is_MPI_Initialized ; 
    23      
     25 
    2426    void CServer::initialize(void) 
    2527    { 
     
    2830      if (initialized) is_MPI_Initialized=true ; 
    2931      else is_MPI_Initialized=false ; 
    30              
     32 
    3133      // Not using OASIS 
    3234      if (!CXios::usingOasis) 
    3335      { 
    34          
    35         if (!is_MPI_Initialized)  
     36 
     37        if (!is_MPI_Initialized) 
    3638        { 
    3739          int argc=0; 
     
    4042        } 
    4143        CTimer::get("XIOS").resume() ; 
    42   
    43         boost::hash<string> hashString ;     
    44        
     44 
     45        boost::hash<string> hashString ; 
     46 
    4547        unsigned long hashServer=hashString(CXios::xiosCodeId) ; 
    4648        unsigned long* hashAll ; 
    47        
    48         int rank ; 
     49 
     50//        int rank ; 
    4951        int size ; 
    5052        int myColor ; 
    5153        int i,c ; 
    5254        MPI_Comm newComm ; 
    53        
     55 
    5456        MPI_Comm_size(CXios::globalComm,&size) ; 
    5557        MPI_Comm_rank(CXios::globalComm,&rank); 
    5658        hashAll=new unsigned long[size] ; 
    57       
     59 
    5860        MPI_Allgather(&hashServer,1,MPI_LONG,hashAll,1,MPI_LONG,CXios::globalComm) ; 
    5961 
     
    6163        map<unsigned long, int> leaders ; 
    6264        map<unsigned long, int>::iterator it ; 
    63        
     65 
    6466        for(i=0,c=0;i<size;i++) 
    6567        { 
     
    7173          } 
    7274        } 
    73       
     75 
    7476        myColor=colors[hashServer] ; 
    7577        MPI_Comm_split(MPI_COMM_WORLD,myColor,rank,&intraComm) ; 
     
    7779        int serverLeader=leaders[hashServer] ; 
    7880        int clientLeader; 
    79       
     81 
    8082         serverLeader=leaders[hashServer] ; 
    8183         for(it=leaders.begin();it!=leaders.end();it++) 
     
    8486           { 
    8587             clientLeader=it->second ; 
    86             
     88 
    8789             MPI_Intercomm_create(intraComm,0,CXios::globalComm,clientLeader,0,&newComm) ; 
    8890             interComm.push_back(newComm) ; 
     
    9597      else 
    9698      { 
    97         int rank ,size; 
    98         if (!is_MPI_Initialized) oasis_init(CXios::xiosCodeId) ; 
     99//        int rank ,size; 
     100        int size; 
     101        if (!is_MPI_Initialized) oasis_init(CXios::xiosCodeId); 
     102 
    99103        CTimer::get("XIOS").resume() ; 
    100104        oasis_get_localcomm(intraComm) ; 
     
    102106        MPI_Comm_size(intraComm,&size) ; 
    103107        string codesId=CXios::getin<string>("oasis_codes_id") ; 
    104           
     108 
    105109        vector<string> splitted ; 
    106110        boost::split( splitted, codesId, boost::is_any_of(","), boost::token_compress_on ) ; 
     
    110114        int globalRank ; 
    111115        MPI_Comm_rank(CXios::globalComm,&globalRank); 
    112          
     116 
    113117        for(it=splitted.begin();it!=splitted.end();it++) 
    114118        { 
     
    120124        oasis_enddef() ; 
    121125      } 
    122        
    123       int rank ; 
     126 
     127//      int rank; 
    124128      MPI_Comm_rank(intraComm,&rank) ; 
    125129      if (rank==0) isRoot=true; 
    126       else isRoot=false;  
    127       eventLoop() ; 
    128       finalize() ; 
     130      else isRoot=false; 
     131//      eventLoop() ; 
     132//      finalize() ; 
    129133    } 
    130      
     134 
    131135    void CServer::finalize(void) 
    132136    { 
    133137      CTimer::get("XIOS").suspend() ; 
    134138      if (!is_MPI_Initialized) 
    135       {  
     139      { 
    136140        if (CXios::usingOasis) oasis_finalize(); 
    137141        else MPI_Finalize() ; 
     
    141145      report(0)<<"Performance report : Ratio : "<<CTimer::get("Process events").getCumulatedTime()/CTimer::get("XIOS server").getCumulatedTime()*100.<<"%"<<endl  ; 
    142146    } 
    143      
     147 
    144148     void CServer::eventLoop(void) 
    145149     { 
    146150       bool stop=false ; 
    147         
     151 
    148152       CTimer::get("XIOS server").resume() ; 
    149153       while(!stop) 
     
    159163           if (!finished) listenRootFinalize() ; 
    160164         } 
    161         
     165 
    162166         contextEventLoop() ; 
    163167         if (finished && contextList.empty()) stop=true ; 
     
    165169       CTimer::get("XIOS server").suspend() ; 
    166170     } 
    167       
     171 
    168172     void CServer::listenFinalize(void) 
    169173     { 
     
    171175        int msg ; 
    172176        int flag ; 
    173          
     177 
    174178        for(it=interComm.begin();it!=interComm.end();it++) 
    175179        { 
     
    186190            } 
    187191         } 
    188           
     192 
    189193         if (interComm.empty()) 
    190194         { 
     
    193197           MPI_Request* requests= new MPI_Request[size-1] ; 
    194198           MPI_Status* status= new MPI_Status[size-1] ; 
    195            
     199 
    196200           for(int i=1;i<size;i++) MPI_Isend(&msg,1,MPI_INT,i,4,intraComm,&requests[i-1]) ; 
    197201           MPI_Waitall(size-1,requests,status) ; 
     
    202206         } 
    203207     } 
    204        
    205       
     208 
     209 
    206210     void CServer::listenRootFinalize() 
    207211     { 
     
    209213        MPI_Status status ; 
    210214        int msg ; 
    211          
     215 
    212216        traceOff() ; 
    213217        MPI_Iprobe(0,4,intraComm, &flag, &status) ; 
     
    219223        } 
    220224      } 
    221        
     225 
    222226     void CServer::listenContext(void) 
    223227     { 
    224         
     228 
    225229       MPI_Status status ; 
    226230       int flag ; 
     
    230234       int rank ; 
    231235       int count ; 
    232         
     236 
    233237       if (recept==false) 
    234238       { 
     
    236240         MPI_Iprobe(MPI_ANY_SOURCE,1,CXios::globalComm, &flag, &status) ; 
    237241         traceOn() ; 
    238          if (flag==true)  
     242         if (flag==true) 
    239243         { 
    240244           rank=status.MPI_SOURCE ; 
     
    242246           buffer=new char[count] ; 
    243247           MPI_Irecv(buffer,count,MPI_CHAR,rank,1,CXios::globalComm,&request) ; 
    244            recept=true ;    
     248           recept=true ; 
    245249         } 
    246250       } 
     
    256260           recvContextMessage(buffer,count) ; 
    257261           delete [] buffer ; 
    258            recept=false ;          
    259          } 
    260        } 
    261      } 
    262       
     262           recept=false ; 
     263         } 
     264       } 
     265     } 
     266 
    263267     void CServer::recvContextMessage(void* buff,int count) 
    264268     { 
    265   
    266         
    267269       static map<string,contextMessage> recvContextId ; 
    268270       map<string,contextMessage>::iterator it ; 
    269         
     271 
    270272       CBufferIn buffer(buff,count) ; 
    271273       string id ; 
     
    274276 
    275277       buffer>>id>>nbMessage>>clientLeader ; 
    276                         
     278 
    277279       it=recvContextId.find(id) ; 
    278280       if (it==recvContextId.end()) 
    279        {          
     281       { 
    280282         contextMessage msg={0,0} ; 
    281283         pair<map<string,contextMessage>::iterator,bool> ret ; 
    282284         ret=recvContextId.insert(pair<string,contextMessage>(id,msg)) ; 
    283285         it=ret.first ; 
    284        }   
     286       } 
    285287       it->second.nbRecv+=1 ; 
    286288       it->second.leaderRank+=clientLeader ; 
    287           
     289 
    288290       if (it->second.nbRecv==nbMessage) 
    289        {  
     291       { 
    290292         int size ; 
    291293         MPI_Comm_size(intraComm,&size) ; 
    292294         MPI_Request* requests= new MPI_Request[size-1] ; 
    293295         MPI_Status* status= new MPI_Status[size-1] ; 
    294           
     296 
    295297         for(int i=1;i<size;i++) 
    296298         { 
     
    305307 
    306308       } 
    307      }      
    308       
     309     } 
     310 
    309311     void CServer::listenRootContext(void) 
    310312     { 
    311         
     313 
    312314       MPI_Status status ; 
    313315       int flag ; 
     
    318320       int count ; 
    319321       const int root=0 ; 
    320         
     322 
    321323       if (recept==false) 
    322324       { 
     
    324326         MPI_Iprobe(root,2,intraComm, &flag, &status) ; 
    325327         traceOn() ; 
    326          if (flag==true)  
     328         if (flag==true) 
    327329         { 
    328330           MPI_Get_count(&status,MPI_CHAR,&count) ; 
    329331           buffer=new char[count] ; 
    330332           MPI_Irecv(buffer,count,MPI_CHAR,root,2,intraComm,&request) ; 
    331            recept=true ;    
     333           recept=true ; 
    332334         } 
    333335       } 
     
    340342           registerContext(buffer,count) ; 
    341343           delete [] buffer ; 
    342            recept=false ;          
    343          } 
    344        } 
    345      }  
    346       
    347       
    348       
     344           recept=false ; 
     345         } 
     346       } 
     347     } 
     348 
     349 
     350 
    349351     void CServer::registerContext(void* buff,int count, int leaderRank) 
    350352     { 
    351       
     353 
    352354       string contextId; 
    353355       CBufferIn buffer(buff,count) ; 
     
    356358       MPI_Comm contextIntercomm ; 
    357359       MPI_Intercomm_create(intraComm,0,CXios::globalComm,leaderRank,10+leaderRank,&contextIntercomm) ; 
    358         
     360 
    359361       info(20)<<"CServer : Register new Context : "<<contextId<<endl  ; 
    360362       MPI_Comm inter ; 
    361363       MPI_Intercomm_merge(contextIntercomm,1,&inter) ; 
    362364       MPI_Barrier(inter) ; 
    363        if (contextList.find(contextId)!=contextList.end())  
     365       if (contextList.find(contextId)!=contextList.end()) 
    364366        ERROR("void CServer::registerContext(void* buff,int count, int leaderRank)", 
    365367              <<"Context has already been registred") ; 
    366        
     368 
    367369      CContext* context=CContext::create(contextId) ; 
    368370      contextList[contextId]=context ; 
    369371      context->initServer(intraComm,contextIntercomm) ; 
    370               
    371      }     
    372       
    373       
     372 
     373     } 
     374 
     375 
    374376     void CServer::contextEventLoop(void) 
    375377     { 
    376378       bool finished ; 
    377379       map<string,CContext*>::iterator it ; 
    378        for(it=contextList.begin();it!=contextList.end();it++)  
     380       for(it=contextList.begin();it!=contextList.end();it++) 
    379381       { 
    380382         finished=it->second->eventLoop() ; 
     
    385387         } 
    386388       } 
    387           
    388      } 
    389       
     389 
     390     } 
     391 
     392     //! Get rank of the current process 
     393     int CServer::getRank() 
     394     { 
     395       return rank; 
     396     } 
     397 
     398     /*! 
     399      * \brief Open file stream to write in 
     400      *   Opening a file stream with a specific file name suffix-server+rank 
     401      * \param [in] protype file name 
     402     */ 
     403     void CServer::openInfoStream(const StdString& fileName) 
     404     { 
     405       std::filebuf* fb = m_infoStream.rdbuf(); 
     406       StdStringStream fileNameServer; 
     407       fileNameServer << fileName <<"_server_"<<getRank() << ".txt"; 
     408       fb->open(fileNameServer.str().c_str(), std::ios::out); 
     409       if (!fb->is_open()) 
     410       ERROR("void CServer::openInfoStream(const StdString& fileName)", 
     411            <<endl<< "Can not open <"<<fileNameServer<<"> file to write" ); 
     412 
     413       info.write2File(fb); 
     414     } 
     415 
     416     //! Open stream for standard output 
     417     void CServer::openInfoStream() 
     418     { 
     419       info.write2StdOut(); 
     420     } 
     421 
     422     //! Close opening stream 
     423     void CServer::closeInfoStream() 
     424     { 
     425       if (m_infoStream.is_open()) m_infoStream.close(); 
     426     } 
     427 
    390428} 
Note: See TracChangeset for help on using the changeset viewer.