Changeset 490 for XIOS


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

Location:
XIOS/trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/Doxyfile

    r300 r490  
    169169# an explicit \brief command for a brief description.) 
    170170 
    171 QT_AUTOBRIEF           = NO 
     171QT_AUTOBRIEF           = YES 
    172172 
    173173# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen  
  • XIOS/trunk/inputs/COMPLETE/iodef.xml

    r486 r490  
    1515        <variable_group id="parameters" > 
    1616          <variable id="using_server" type="boolean">false</variable> 
    17           <variable id="info_level" type="int">1</variable> 
     17          <variable id="info_level" type="int">100</variable> 
     18          <variable id="info_output_file" type="boolean">true</variable> 
    1819        </variable_group> 
    1920      </variable_definition> 
  • XIOS/trunk/src/client.cpp

    r400 r490  
     1#include "globalScopeData.hpp" 
    12#include "xmlioserver_spl.hpp" 
    23#include "cxios.hpp" 
     
    1213 
    1314namespace xios 
    14 {                       
     15{ 
    1516 
    1617    MPI_Comm CClient::intraComm ; 
     
    1819    int CClient::serverLeader ; 
    1920    bool CClient::is_MPI_Initialized ; 
    20      
    21      
     21    int CClient::rank = INVALID_RANK; 
     22    StdOFStream CClient::m_infoStream; 
     23 
    2224    void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) 
    2325    { 
     
    2628      if (initialized) is_MPI_Initialized=true ; 
    2729      else is_MPI_Initialized=false ; 
    28        
     30 
    2931// don't use OASIS 
    3032      if (!CXios::usingOasis) 
     
    3335        if (localComm == MPI_COMM_NULL) 
    3436        { 
    35           if (!is_MPI_Initialized)  
     37          if (!is_MPI_Initialized) 
    3638          { 
    3739            int argc=0; 
     
    4143          CTimer::get("XIOS").resume() ; 
    4244          CTimer::get("XIOS init").resume() ; 
    43           boost::hash<string> hashString ;     
    44      
     45          boost::hash<string> hashString ; 
     46 
    4547          unsigned long hashClient=hashString(codeId) ; 
    4648          unsigned long hashServer=hashString(CXios::xiosCodeId) ; 
    4749          unsigned long* hashAll ; 
    48           int rank ; 
    4950          int size ; 
    5051          int myColor ; 
    5152          int i,c ; 
    5253          MPI_Comm newComm ; 
    53        
     54 
    5455          MPI_Comm_size(CXios::globalComm,&size) ; 
    5556          MPI_Comm_rank(CXios::globalComm,&rank); 
     57 
    5658          hashAll=new unsigned long[size] ; 
    57       
     59 
    5860          MPI_Allgather(&hashClient,1,MPI_LONG,hashAll,1,MPI_LONG,CXios::globalComm) ; 
    5961 
    6062          map<unsigned long, int> colors ; 
    6163          map<unsigned long, int> leaders ; 
    62        
     64 
    6365          for(i=0,c=0;i<size;i++) 
    6466          { 
     
    7072            } 
    7173          } 
    72       
     74 
    7375          myColor=colors[hashClient] ; 
    74        
     76 
    7577          MPI_Comm_split(CXios::globalComm,myColor,rank,&intraComm) ; 
    7678 
    7779          if (CXios::usingServer) 
    78           {      
     80          { 
    7981            int clientLeader=leaders[hashClient] ; 
    8082            serverLeader=leaders[hashServer] ; 
     
    8890        } 
    8991        // localComm argument is given 
    90         else  
     92        else 
    9193        { 
    9294          if (CXios::usingServer) 
    93           {           
     95          { 
    9496            //ERROR("void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm)", << " giving a local communictor is not compatible with using server mode") ; 
    9597          } 
     
    113115        CTimer::get("XIOS").resume() ; 
    114116        CTimer::get("XIOS init").resume() ; 
    115    
    116         if (CXios::usingServer)  
     117 
     118        if (CXios::usingServer) 
    117119        { 
    118120          MPI_Status status ; 
    119           int rank ; 
    120           MPI_Comm_rank(intraComm,&rank) ; 
    121  
     121            MPI_Comm_rank(intraComm,&rank) ; 
    122122          oasis_get_intercomm(interComm,CXios::xiosCodeId) ; 
    123123          if (rank==0) MPI_Recv(&serverLeader,1, MPI_INT, 0, 0, interComm, &status) ; 
    124124          MPI_Bcast(&serverLeader,1,MPI_INT,0,intraComm) ; 
    125             
     125 
    126126        } 
    127127        else MPI_Comm_dup(intraComm,&interComm) ; 
    128128      } 
    129            
     129 
    130130      MPI_Comm_dup(intraComm,&returnComm) ; 
    131131    } 
    132      
    133      
     132 
     133 
    134134    void CClient::registerContext(const string& id,MPI_Comm contextComm) 
    135135    { 
    136136      CContext::setCurrent(id) ; 
    137137      CContext* context=CContext::create(id) ; 
    138          
     138 
    139139      if (!CXios::isServer) 
    140140      { 
     
    143143        int leaderRank ; 
    144144        MPI_Comm contextInterComm ; 
    145        
     145 
    146146        MPI_Comm_size(contextComm,&size) ; 
    147147        MPI_Comm_rank(contextComm,&rank) ; 
    148148        MPI_Comm_rank(CXios::globalComm,&globalRank) ; 
    149149        if (rank!=0) globalRank=0 ; 
    150        
    151      
     150 
     151 
    152152        CMessage msg ; 
    153153        msg<<id<<size<<globalRank ; 
     
    157157        CBufferOut buffer(buff,messageSize) ; 
    158158        buffer<<msg ; 
    159        
     159 
    160160        MPI_Send(buff,buffer.count(),MPI_CHAR,serverLeader,1,CXios::globalComm) ; 
    161161        delete [] buff ; 
    162        
     162 
    163163        MPI_Intercomm_create(contextComm,0,CXios::globalComm,serverLeader,10+globalRank,&contextInterComm) ; 
    164164        info(10)<<"Register new Context : "<<id<<endl ; 
    165   
     165 
    166166        MPI_Comm inter ; 
    167167        MPI_Intercomm_merge(contextInterComm,0,&inter) ; 
     
    178178      } 
    179179    } 
    180      
     180 
    181181    void CClient::finalize(void) 
    182182    { 
     
    185185      if (!CXios::isServer) 
    186186      { 
    187         MPI_Comm_rank(intraComm,&rank) ;   
    188         if (rank==0)  
     187        MPI_Comm_rank(intraComm,&rank) ; 
     188        if (rank==0) 
    189189        { 
    190190          MPI_Send(&msg,1,MPI_INT,0,0,interComm) ; 
    191191        } 
    192192      } 
    193        
     193 
    194194     CTimer::get("XIOS finalize").suspend() ; 
    195195     CTimer::get("XIOS").suspend() ; 
     
    201201      } 
    202202      info(20) << "Client side context is finalized"<<endl ; 
    203       report(0) <<" Performance report : total time spent for XIOS : "<< CTimer::get("XIOS").getCumulatedTime()<<" s"<<endl ;  
     203      report(0) <<" Performance report : total time spent for XIOS : "<< CTimer::get("XIOS").getCumulatedTime()<<" s"<<endl ; 
    204204      report(0)<< " Performance report : time spent for waiting free buffer : "<< CTimer::get("Blocking time").getCumulatedTime()<<" s"<<endl ; 
    205205      report(0)<< " Performance report : Ratio : "<< CTimer::get("Blocking time").getCumulatedTime()/CTimer::get("XIOS").getCumulatedTime()*100.<<" %"<<endl ; 
     
    209209      report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ; 
    210210   } 
     211 
     212   int CClient::getRank() 
     213   { 
     214     return rank; 
     215   } 
     216 
     217     /*! 
     218      * \brief Open file stream to write in 
     219      *   Opening a file stream with a specific file name suffix-client+rank 
     220      * \param [in] protype file name 
     221     */ 
     222     void CClient::openInfoStream(const StdString& fileName) 
     223     { 
     224       std::filebuf* fb = m_infoStream.rdbuf(); 
     225       StdStringStream fileNameClient; 
     226       fileNameClient << fileName <<"_client_" << getRank() << ".txt"; 
     227       fb->open(fileNameClient.str().c_str(), std::ios::out); 
     228       if (!fb->is_open()) 
     229       ERROR("void CClient::openInfoStream(const StdString& fileName)", 
     230            <<endl<< "Can not open <"<<fileNameClient<<"> file to write" ); 
     231 
     232       info.write2File(fb); 
     233     } 
     234 
     235     //! Write out to standard output 
     236     void CClient::openInfoStream() 
     237     { 
     238       info.write2StdOut(); 
     239     } 
     240 
     241     //! Close file if it opens 
     242     void CClient::closeInfoStream() 
     243     { 
     244       if (m_infoStream.is_open()) m_infoStream.close(); 
     245     } 
     246 
     247 
    211248} 
  • XIOS/trunk/src/client.hpp

    r382 r490  
    66 
    77namespace xios 
    8 {                       
     8{ 
    99    class CClient 
    1010    { 
    1111       public: 
    12         
     12 
    1313       static void initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) ; 
    1414       static void finalize(void) ; 
     
    1919       static int serverLeader; 
    2020       static bool is_MPI_Initialized ; 
     21 
     22       public: 
     23        static int getRank(); 
     24 
     25        static void openInfoStream(const StdString& fileName); 
     26 
     27        static void openInfoStream(); 
     28 
     29        static void closeInfoStream(); 
     30 
     31       protected: 
     32       static int rank; 
     33       static StdOFStream m_infoStream; 
     34 
     35 
    2136    } ; 
    2237} 
  • XIOS/trunk/src/cxios.cpp

    r401 r490  
    1515  string CXios::rootFile="./iodef.xml" ; 
    1616  string CXios::xiosCodeId="xios.x" ; 
    17    
     17  string CXios::infoFile="./info_output"; 
     18 
    1819  bool CXios::isClient ; 
    1920  bool CXios::isServer ; 
    2021  MPI_Comm CXios::globalComm ; 
    2122  bool CXios::usingOasis ; 
    22   bool CXios::usingServer ;    
     23  bool CXios::usingServer ; 
    2324  size_t CXios::bufferSize ; 
    2425  double CXios::bufferServerFactorSize=2 ; 
    2526  size_t CXios::defaultBufferSize=1024*1024*100 ; // 100Mo 
    2627  double CXios::defaultBufferServerFactorSize=2 ; 
    27    
     28  bool CXios::printInfo2File; 
     29 
     30 
    2831  void CXios::initialize() 
    2932  { 
     
    3336    usingOasis=getin<bool>("using_oasis",false) ; 
    3437    info.setLevel(getin<int>("info_level",0)) ; 
     38    printInfo2File=getin<bool>("info_output_file",false); 
    3539    bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ; 
    3640    bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ; 
     
    4145  void CXios::initClientSide(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) 
    4246  { 
    43       
     47 
    4448    initialize() ; 
    45      
     49 
    4650    isClient=true; 
    4751    if (usingServer) isServer=false; 
    4852    else isServer=true ; 
    49      
     53 
    5054    CClient::initialize(codeId,localComm,returnComm) ; 
    5155 
    52   }    
     56    if (printInfo2File) 
     57      CClient::openInfoStream(infoFile); 
     58    else 
     59      CClient::openInfoStream(); 
     60  } 
    5361 
    5462  void CXios::clientFinalize(void) 
    5563  { 
    56      CClient::finalize() ;  
     64     CClient::finalize() ; 
     65     CClient::closeInfoStream(); 
     66 
    5767#ifdef XIOS_MEMTRACK 
    5868     MemTrack::TrackListMemoryUsage() ; 
    59      MemTrack::TrackDumpBlocks();   
     69     MemTrack::TrackDumpBlocks(); 
    6070#endif 
    61   }    
    62    
    63    
     71  } 
     72 
     73 
    6474  void CXios::initServerSide(void) 
    6575  { 
     
    7080    isServer=false ; 
    7181 
    72     CServer::initialize() ; 
    73   }  
    74    
     82    //! Initialize all aspect MPI 
     83    CServer::initialize(); 
     84 
     85    if (printInfo2File) 
     86      CServer::openInfoStream(infoFile); 
     87    else 
     88      CServer::openInfoStream(); 
     89 
     90    //! Enter the loop to listen message from Client 
     91    CServer::eventLoop(); 
     92 
     93    //! Finalize 
     94    CServer::finalize(); 
     95    CServer::closeInfoStream(); 
     96  } 
     97 
    7598  void CXios::parseFile(const string& filename) 
    7699  { 
    77     xml::CXMLParser::ParseFile(filename);  
     100    xml::CXMLParser::ParseFile(filename); 
    78101  } 
    79    
    80  
    81102} 
  • XIOS/trunk/src/cxios.hpp

    r382 r490  
    1010  { 
    1111     public: 
    12       
     12 
    1313     static string rootFile ; 
    1414     static string xiosCodeId ; 
    15       
     15     static string infoFile; 
     16 
    1617     static void initialize(void) ; 
    17        
    18     
     18 
     19 
    1920     static void initClientSide(const string & codeId, MPI_Comm& localComm, MPI_Comm& returnComm) ; 
    2021     static void initServerSide(void) ; 
    2122     static void clientFinalize(void) ; 
    2223     static void parseFile(const string& filename) ; 
    23     
     24 
    2425     template <typename T> 
    2526     static T getin(const string& id,const T& defaultValue) ; 
    26       
     27 
    2728     template <typename T> 
    2829     static T getin(const string& id) ; 
     30 
     31//     static void openFileInfo(const StdString& fileName); 
     32//     static void closeFileInfo(); 
    2933 
    3034     static bool isClient ; 
    3135     static bool isServer ; 
    3236 
    33      static MPI_Comm globalComm ;  
    34       
     37     static MPI_Comm globalComm ; 
     38 
     39     static bool printInfo2File; 
    3540     static bool usingOasis ; 
    36      static bool usingServer ;    
     41     static bool usingServer ; 
    3742     static size_t bufferSize ; 
    3843     static size_t defaultBufferSize ; 
    3944     static double bufferServerFactorSize ; 
    4045     static double defaultBufferServerFactorSize ; 
    41          
     46 
     47     private: 
     48//     static StdOFStream infoFileStream_; 
     49 
    4250  } ; 
    4351 
  • XIOS/trunk/src/log.hpp

    r380 r490  
    1313  { 
    1414    public : 
    15     CLog(const string& name_) : ostream(cout.rdbuf()),level(0),name(name_) {} 
    16     CLog& operator()(int l)  
    17     {   
    18       if (l<=level)  
     15    CLog(const string& name_) : ostream(cout.rdbuf()),level(0),name(name_), strBuf_(cout.rdbuf()) {} 
     16    CLog& operator()(int l) 
     17    { 
     18      if (l<=level) 
    1919      { 
    20         rdbuf(cout.rdbuf()) ; 
     20//        rdbuf(cout.rdbuf()) ; 
     21        rdbuf(strBuf_); 
    2122        *this<<"-> "<<name<<" : " ; 
    2223      } 
     
    2425      return *this; 
    2526    } 
    26     void setLevel(int l) {level=l; }  
     27    void setLevel(int l) {level=l; } 
    2728    int getLevel() {return level ;} 
    2829    bool isActive(void) { if (rdbuf()==NULL) return true ; else return false ;} 
    2930    bool isActive(int l) {if (l<=level) return true ; else return false ; } 
    3031 
     32  public: 
     33    //! Write info into a file with its streambuf 
     34    void write2File(std::streambuf* sBuff) { changeStreamBuff(sBuff); } 
     35 
     36    //! Write info into standard output 
     37    void write2StdOut() { changeStreamBuff(cout.rdbuf()); } 
     38  private: 
     39    /*! 
     40     * \brief Change current streambuf (by default std::cout) to new one 
     41     * This function associates a new streambuf to the current log object 
     42     * \param [in] pointer to new streambuf 
     43    */ 
     44    void changeStreamBuff(std::streambuf* sBuff) { strBuf_ = sBuff; rdbuf(sBuff); } 
     45 
    3146    private : 
    3247    int level ; 
    3348    string name ; 
     49    std::streambuf* strBuf_; 
    3450  }; 
    3551 
  • 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} 
  • XIOS/trunk/src/server.hpp

    r382 r490  
    1111    { 
    1212       public: 
    13         
     13 
    1414       static void initialize(void) ; 
    1515       static void finalize(void) ; 
     
    2222       static void listenRootFinalize(void) ; 
    2323       static void registerContext(void* buff,int count, int leaderRank=0) ; 
    24         
     24 
    2525       static MPI_Comm intraComm ; 
    2626       static list<MPI_Comm> interComm ; 
     
    3131         int leaderRank ; 
    3232       } ; 
    33         
    34       static bool isRoot ; 
    35       static int rank ; 
    36       static map<string,CContext*> contextList ; 
    37       static bool finished ; 
    38       static bool is_MPI_Initialized ; 
     33 
     34       static bool isRoot ; 
     35 
     36       static map<string,CContext*> contextList ; 
     37       static bool finished ; 
     38       static bool is_MPI_Initialized ; 
     39 
     40       public: 
     41         //! Get rank of the current process 
     42         static int getRank(); 
     43 
     44        //! Print Information into a file 
     45        static void openInfoStream(const StdString& fileName); 
     46 
     47        //! Print information to standard output 
     48        static void openInfoStream(); 
     49 
     50        //! Close Info stream (closing file) 
     51        static void closeInfoStream(); 
     52 
     53       private: 
     54        static StdOFStream m_infoStream; 
     55        static int rank ; 
    3956    } ; 
    4057} 
  • XIOS/trunk/src/xmlioserver_spl.hpp

    r335 r490  
    3939typedef std::ostringstream StdOStringStream; 
    4040typedef std::istringstream StdIStringStream; 
     41typedef std::stringstream  StdStringStream; 
    4142typedef std::ofstream      StdOFStream; 
    4243typedef std::ifstream      StdIFStream; 
Note: See TracChangeset for help on using the changeset viewer.