Changeset 548 for XIOS/branchs


Ignore:
Timestamp:
01/23/15 16:18:43 (6 years ago)
Author:
rlacroix
Message:

Backport r523 into the stable branch.

Improve the message error handling by mimicking the behavior of the info/report logs.

Output the error messages to the standart error message until the context is correctly initialized. Then, output the error messages to a file if the user has set "print_file" parameter to "true".

  • Fix: Errors that occured before MPI was initialized (e.g. during the config file parsing) caused a MPI error on top of the original error.
  • Fix: The error file could sometimes be misnamed if the error happened before the context was completely known.
Location:
XIOS/branchs/xios-1.0/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • XIOS/branchs/xios-1.0/src/client.cpp

    r507 r548  
    2121    int CClient::rank = INVALID_RANK; 
    2222    StdOFStream CClient::m_infoStream; 
     23    StdOFStream CClient::m_errorStream; 
    2324 
    2425    void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) 
     
    233234   } 
    234235 
    235      /*! 
    236       * \brief Open file stream to write in 
    237       *   Opening a file stream with a specific file name suffix-client+rank 
    238       * \param [in] protype file name 
    239      */ 
    240      void CClient::openInfoStream(const StdString& fileName) 
    241      { 
    242        std::filebuf* fb = m_infoStream.rdbuf(); 
    243        StdStringStream fileNameClient; 
    244        int numDigit = 0; 
    245        int size = 0; 
    246        MPI_Comm_size(CXios::globalComm, &size); 
    247        while (size) 
    248        { 
    249          size /= 10; 
    250          ++numDigit; 
    251        } 
    252  
    253        fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ".out"; 
    254        fb->open(fileNameClient.str().c_str(), std::ios::out); 
    255        if (!fb->is_open()) 
    256        ERROR("void CClient::openInfoStream(const StdString& fileName)", 
    257             <<endl<< "Can not open <"<<fileNameClient<<"> file to write" ); 
    258  
    259        info.write2File(fb); 
    260        report.write2File(fb); 
    261      } 
    262  
    263      //! Write out to standard output 
    264      void CClient::openInfoStream() 
    265      { 
    266        info.write2StdOut(); 
    267        report.write2StdOut(); 
    268      } 
    269  
    270      //! Close file if it opens 
    271      void CClient::closeInfoStream() 
    272      { 
    273        if (m_infoStream.is_open()) m_infoStream.close(); 
    274      } 
    275  
    276  
     236    /*! 
     237    * Open a file specified by a suffix and an extension and use it for the given file buffer. 
     238    * The file name will be suffix+rank+extension. 
     239    *  
     240    * \param fileName[in] protype file name 
     241    * \param ext [in] extension of the file 
     242    * \param fb [in/out] the file buffer 
     243    */ 
     244    void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb) 
     245    { 
     246      StdStringStream fileNameClient; 
     247      int numDigit = 0; 
     248      int size = 0; 
     249      MPI_Comm_size(CXios::globalComm, &size); 
     250      while (size) 
     251      { 
     252        size /= 10; 
     253        ++numDigit; 
     254      } 
     255 
     256      fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext; 
     257      fb->open(fileNameClient.str().c_str(), std::ios::out); 
     258      if (!fb->is_open()) 
     259        ERROR("void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)", 
     260              << std::endl << "Can not open <" << fileNameClient << "> file to write the client log(s)."); 
     261    } 
     262 
     263    /*! 
     264    * \brief Open a file stream to write the info logs 
     265    * Open a file stream with a specific file name suffix+rank 
     266    * to write the info logs. 
     267    * \param fileName [in] protype file name 
     268    */ 
     269    void CClient::openInfoStream(const StdString& fileName) 
     270    { 
     271      std::filebuf* fb = m_infoStream.rdbuf(); 
     272      openStream(fileName, ".out", fb); 
     273 
     274      info.write2File(fb); 
     275      report.write2File(fb); 
     276    } 
     277 
     278    //! Write the info logs to standard output 
     279    void CClient::openInfoStream() 
     280    { 
     281      info.write2StdOut(); 
     282      report.write2StdOut(); 
     283    } 
     284 
     285    //! Close the info logs file if it opens 
     286    void CClient::closeInfoStream() 
     287    { 
     288      if (m_infoStream.is_open()) m_infoStream.close(); 
     289    } 
     290 
     291    /*! 
     292    * \brief Open a file stream to write the error log 
     293    * Open a file stream with a specific file name suffix+rank 
     294    * to write the error log. 
     295    * \param fileName [in] protype file name 
     296    */ 
     297    void CClient::openErrorStream(const StdString& fileName) 
     298    { 
     299      std::filebuf* fb = m_errorStream.rdbuf(); 
     300      openStream(fileName, ".err", fb); 
     301 
     302      error.write2File(fb); 
     303    } 
     304 
     305    //! Write the error log to standard error output 
     306    void CClient::openErrorStream() 
     307    { 
     308      error.write2StdErr(); 
     309    } 
     310 
     311    //! Close the error log file if it opens 
     312    void CClient::closeErrorStream() 
     313    { 
     314      if (m_errorStream.is_open()) m_errorStream.close(); 
     315    } 
    277316} 
  • XIOS/branchs/xios-1.0/src/client.hpp

    r501 r548  
    99    class CClient 
    1010    { 
    11        public: 
     11      public: 
     12        static void initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm); 
     13        static void finalize(void); 
     14        static void registerContext(const string& id, MPI_Comm contextComm); 
    1215 
    13        static void initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) ; 
    14        static void finalize(void) ; 
    15        static void registerContext(const string& id,MPI_Comm contextComm) ; 
     16        static MPI_Comm intraComm; 
     17        static MPI_Comm interComm; 
     18        static int serverLeader; 
     19        static bool is_MPI_Initialized ; 
    1620 
    17        static MPI_Comm intraComm ; 
    18        static MPI_Comm interComm ; 
    19        static int serverLeader; 
    20        static bool is_MPI_Initialized ; 
    21  
    22        public: 
     21        //! Get rank of the current process 
    2322        static int getRank(); 
    2423 
     24        //! Open a file stream to write the info logs 
    2525        static void openInfoStream(const StdString& fileName); 
    26  
     26        //! Write the info logs to standard output 
    2727        static void openInfoStream(); 
    28  
     28        //! Close the info logs file if it opens 
    2929        static void closeInfoStream(); 
    3030 
    31        protected: 
    32        static int rank; 
    33        static StdOFStream m_infoStream; 
     31        //! Open a file stream to write the error log 
     32        static void openErrorStream(const StdString& fileName); 
     33        //! Write the error log to standard error output 
     34        static void openErrorStream(); 
     35        //! Close the error log file if it opens 
     36        static void closeErrorStream(); 
    3437 
     38      protected: 
     39        static int rank; 
     40        static StdOFStream m_infoStream; 
     41        static StdOFStream m_errorStream; 
    3542 
    36     } ; 
     43        static void openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb); 
     44    }; 
    3745} 
    3846 
  • XIOS/branchs/xios-1.0/src/cxios.cpp

    r507 r548  
    2727  size_t CXios::defaultBufferSize=1024*1024*100 ; // 100Mo 
    2828  double CXios::defaultBufferServerFactorSize=2 ; 
    29   bool CXios::printInfo2File; 
    30   bool CXios::isServerSide; 
     29  bool CXios::printLogs2Files; 
    3130 
    3231 
     
    3837    usingServer=getin<bool>("using_server",false) ; 
    3938    info.setLevel(getin<int>("info_level",0)) ; 
    40     printInfo2File=getin<bool>("print_file",false); 
     39    printLogs2Files=getin<bool>("print_file",false); 
    4140    bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ; 
    4241    bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ; 
     
    5453    CClient::initialize(codeId,localComm,returnComm) ; 
    5554 
    56     if (usingServer) isServerSide = isServer=false; 
    57     else isServerSide = isServer=true; 
     55    if (usingServer) isServer=false; 
     56    else isServer=true; 
    5857 
    59     if (printInfo2File) 
     58    if (printLogs2Files) 
     59    { 
    6060      CClient::openInfoStream(clientFile); 
     61      CClient::openErrorStream(clientFile); 
     62    } 
    6163    else 
     64    { 
    6265      CClient::openInfoStream(); 
     66      CClient::openErrorStream(); 
     67    } 
    6368  } 
    6469 
     
    8287    isServer=false ; 
    8388 
    84     isServerSide = true; 
    85  
    8689    // Initialize all aspects MPI 
    8790    CServer::initialize(); 
    8891 
    89     if (printInfo2File) 
     92    if (printLogs2Files) 
     93    { 
    9094      CServer::openInfoStream(serverFile); 
     95      CServer::openErrorStream(serverFile); 
     96    } 
    9197    else 
     98    { 
    9299      CServer::openInfoStream(); 
     100      CServer::openErrorStream(); 
     101    } 
    93102 
    94103    // Enter the loop to listen message from Client 
  • XIOS/branchs/xios-1.0/src/cxios.hpp

    r501 r548  
    3535     static MPI_Comm globalComm ; 
    3636 
    37      static bool printInfo2File; 
     37     static bool printLogs2Files; //!< Printing out logs into files 
    3838     static bool usingOasis ; 
    3939     static bool usingServer ; 
     
    4949     //! Setting xios NOT to use server mode 
    5050     static void setNotUsingServer(); 
    51  
    52       //! A silly variable to detect whether one process is in client or server side. Should be removed on refactoring code 
    53      static bool isServerSide; 
    5451 
    5552  } ; 
  • XIOS/branchs/xios-1.0/src/exception.cpp

    r501 r548  
    66#include "server.hpp" 
    77#include "cxios.hpp" 
     8#include "log.hpp" 
    89 
    910namespace xios 
     
    3435#else 
    3536     { 
    36       int numDigit = 0; 
    37       int size = 0; 
    38       MPI_Comm_size(CXios::globalComm, &size); 
    39       while (size) 
    40       { 
    41         size /= 10; 
    42         ++numDigit; 
    43       } 
    44  
    45       StdOFStream fileStream; 
    46       StdStringStream fileNameErr; 
    47       std::streambuf* psbuf; 
    48       if (CXios::isServerSide) 
    49         fileNameErr << CXios::serverFile << "_" << std::setfill('0') 
    50                     << std::setw(numDigit) << CServer::getRank() << ".err"; 
    51       else 
    52         fileNameErr << CXios::clientFile << "_" << std::setfill('0') 
    53                     << std::setw(numDigit) << CClient::getRank() << ".err"; 
    54  
    55  
    56       fileStream.open(fileNameErr.str().c_str(), std::ofstream::out); 
    57       psbuf = fileStream.rdbuf(); 
    58       std::cerr.rdbuf(psbuf); 
    59       std::cerr << this->getMessage() << std::endl; 
    60       fileStream.close(); 
     37      error << this->getMessage() << std::endl; 
    6138      abort(); 
    6239      } 
    63  
    6440#endif 
    6541   } 
  • XIOS/branchs/xios-1.0/src/log.cpp

    r501 r548  
    55  CLog info("info") ; 
    66  CLog report("report") ; 
     7  CLog error("error", cerr.rdbuf()) ; 
    78} 
  • XIOS/branchs/xios-1.0/src/log.hpp

    r501 r548  
    1313  { 
    1414    public : 
    15     CLog(const string& name_) : ostream(cout.rdbuf()),level(0),name(name_), strBuf_(cout.rdbuf()) {} 
     15    CLog(const string& name_, std::streambuf* sBuff = cout.rdbuf()) 
     16      : ostream(sBuff), level(0), name(name_), strBuf_(sBuff) {} 
    1617    CLog& operator()(int l) 
    1718    { 
     
    3031 
    3132  public: 
    32     //! Write info into a file with its streambuf 
     33    //! Write log into a file with its streambuf 
    3334    void write2File(std::streambuf* sBuff) { changeStreamBuff(sBuff); } 
    3435 
    35     //! Write info into standard output 
     36    //! Write log into standard output 
    3637    void write2StdOut() { changeStreamBuff(cout.rdbuf()); } 
     38 
     39    //! Write log into standard error output 
     40    void write2StdErr() { changeStreamBuff(cerr.rdbuf()); } 
     41 
    3742  private: 
    3843    /*! 
     
    4348    void changeStreamBuff(std::streambuf* sBuff) { strBuf_ = sBuff; rdbuf(sBuff); } 
    4449 
    45     private : 
    4650    int level ; 
    4751    string name ; 
     
    5155  extern CLog info; 
    5256  extern CLog report; 
     57  extern CLog error; 
    5358} 
    5459#endif 
  • XIOS/branchs/xios-1.0/src/server.cpp

    r501 r548  
    2121    int CServer::rank = INVALID_RANK; 
    2222    StdOFStream CServer::m_infoStream; 
     23    StdOFStream CServer::m_errorStream; 
    2324    map<string,CContext*> CServer::contextList ; 
    2425    bool CServer::finished=false ; 
     
    407408     } 
    408409 
    409      /*! 
    410       * \brief Open file stream to write in 
    411       *   Opening a file stream with a specific file name suffix-server+rank 
    412       * \param [in] protype file name 
    413      */ 
    414      void CServer::openInfoStream(const StdString& fileName) 
    415      { 
    416        std::filebuf* fb = m_infoStream.rdbuf(); 
    417        StdStringStream fileNameServer; 
    418        int numDigit = 0; 
    419        int size = 0; 
    420        MPI_Comm_size(CXios::globalComm, &size); 
    421        while (size) 
    422        { 
    423          size /= 10; 
    424          ++numDigit; 
    425        } 
    426  
    427        fileNameServer << fileName <<"_" << std::setfill('0') << std::setw(numDigit) << getRank() << ".out"; 
    428        fb->open(fileNameServer.str().c_str(), std::ios::out); 
    429        if (!fb->is_open()) 
    430        ERROR("void CServer::openInfoStream(const StdString& fileName)", 
    431             <<endl<< "Can not open <"<<fileNameServer<<"> file to write" ); 
    432  
    433        info.write2File(fb); 
    434        report.write2File(fb); 
    435      } 
    436  
    437      //! Open stream for standard output 
    438      void CServer::openInfoStream() 
    439      { 
    440        info.write2StdOut(); 
    441        report.write2StdOut(); 
    442      } 
    443  
    444      //! Close opening stream 
    445      void CServer::closeInfoStream() 
    446      { 
    447        if (m_infoStream.is_open()) m_infoStream.close(); 
    448      } 
    449  
     410    /*! 
     411    * Open a file specified by a suffix and an extension and use it for the given file buffer. 
     412    * The file name will be suffix+rank+extension. 
     413    *  
     414    * \param fileName[in] protype file name 
     415    * \param ext [in] extension of the file 
     416    * \param fb [in/out] the file buffer 
     417    */ 
     418    void CServer::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb) 
     419    { 
     420      StdStringStream fileNameClient; 
     421      int numDigit = 0; 
     422      int size = 0; 
     423      MPI_Comm_size(CXios::globalComm, &size); 
     424      while (size) 
     425      { 
     426        size /= 10; 
     427        ++numDigit; 
     428      } 
     429 
     430      fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext; 
     431      fb->open(fileNameClient.str().c_str(), std::ios::out); 
     432      if (!fb->is_open()) 
     433        ERROR("void CServer::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)", 
     434              << std::endl << "Can not open <" << fileNameClient << "> file to write the server log(s)."); 
     435    } 
     436 
     437    /*! 
     438    * \brief Open a file stream to write the info logs 
     439    * Open a file stream with a specific file name suffix+rank 
     440    * to write the info logs. 
     441    * \param fileName [in] protype file name 
     442    */ 
     443    void CServer::openInfoStream(const StdString& fileName) 
     444    { 
     445      std::filebuf* fb = m_infoStream.rdbuf(); 
     446      openStream(fileName, ".out", fb); 
     447 
     448      info.write2File(fb); 
     449      report.write2File(fb); 
     450    } 
     451 
     452    //! Write the info logs to standard output 
     453    void CServer::openInfoStream() 
     454    { 
     455      info.write2StdOut(); 
     456      report.write2StdOut(); 
     457    } 
     458 
     459    //! Close the info logs file if it opens 
     460    void CServer::closeInfoStream() 
     461    { 
     462      if (m_infoStream.is_open()) m_infoStream.close(); 
     463    } 
     464 
     465    /*! 
     466    * \brief Open a file stream to write the error log 
     467    * Open a file stream with a specific file name suffix+rank 
     468    * to write the error log. 
     469    * \param fileName [in] protype file name 
     470    */ 
     471    void CServer::openErrorStream(const StdString& fileName) 
     472    { 
     473      std::filebuf* fb = m_errorStream.rdbuf(); 
     474      openStream(fileName, ".err", fb); 
     475 
     476      error.write2File(fb); 
     477    } 
     478 
     479    //! Write the error log to standard error output 
     480    void CServer::openErrorStream() 
     481    { 
     482      error.write2StdErr(); 
     483    } 
     484 
     485    //! Close the error log file if it opens 
     486    void CServer::closeErrorStream() 
     487    { 
     488      if (m_errorStream.is_open()) m_errorStream.close(); 
     489    } 
    450490} 
  • XIOS/branchs/xios-1.0/src/server.hpp

    r501 r548  
    1111    class CServer 
    1212    { 
    13        public: 
     13      public: 
     14        static void initialize(void); 
     15        static void finalize(void); 
     16        static void eventLoop(void); 
     17        static void contextEventLoop(void); 
     18        static void listenContext(void); 
     19        static void listenFinalize(void); 
     20        static void recvContextMessage(void* buff,int count); 
     21        static void listenRootContext(void); 
     22        static void listenRootFinalize(void); 
     23        static void registerContext(void* buff,int count, int leaderRank=0); 
    1424 
    15        static void initialize(void) ; 
    16        static void finalize(void) ; 
    17        static void eventLoop(void) ; 
    18        static void contextEventLoop(void) ; 
    19        static void listenContext(void) ; 
    20        static void listenFinalize(void) ; 
    21        static void recvContextMessage(void* buff,int count) ; 
    22        static void listenRootContext(void) ; 
    23        static void listenRootFinalize(void) ; 
    24        static void registerContext(void* buff,int count, int leaderRank=0) ; 
     25        static MPI_Comm intraComm; 
     26        static list<MPI_Comm> interComm; 
     27        static CEventScheduler* eventScheduler; 
    2528 
    26        static MPI_Comm intraComm ; 
    27        static list<MPI_Comm> interComm ; 
    28        static CEventScheduler* eventScheduler ; 
     29        struct contextMessage 
     30        { 
     31          int nbRecv; 
     32          int leaderRank; 
     33        }; 
    2934 
    30        struct contextMessage 
    31        { 
    32          int nbRecv ; 
    33          int leaderRank ; 
    34        } ; 
     35        static bool isRoot; 
    3536 
    36        static bool isRoot ; 
     37        static map<string,CContext*> contextList; 
     38        static bool finished; 
     39        static bool is_MPI_Initialized; 
    3740 
    38        static map<string,CContext*> contextList ; 
    39        static bool finished ; 
    40        static bool is_MPI_Initialized ; 
     41      public: 
     42        //! Get rank of the current process 
     43        static int getRank(); 
    4144 
    42        public: 
    43          //! Get rank of the current process 
    44          static int getRank(); 
    45  
    46         //! Print Information into a file 
     45        //! Open a file stream to write the info logs 
    4746        static void openInfoStream(const StdString& fileName); 
    48  
    49         //! Print information to standard output 
     47        //! Write the info logs to standard output 
    5048        static void openInfoStream(); 
    51  
    52         //! Close Info stream (closing file) 
     49        //! Close the info logs file if it opens 
    5350        static void closeInfoStream(); 
    5451 
    55        private: 
     52        //! Open a file stream to write the error log 
     53        static void openErrorStream(const StdString& fileName); 
     54        //! Write the error log to standard error output 
     55        static void openErrorStream(); 
     56        //! Close the error log file if it opens 
     57        static void closeErrorStream(); 
     58 
     59      private: 
     60        static int rank; 
    5661        static StdOFStream m_infoStream; 
    57         static int rank ; 
    58     } ; 
     62        static StdOFStream m_errorStream; 
     63 
     64        static void openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb); 
     65    }; 
    5966} 
    6067 
Note: See TracChangeset for help on using the changeset viewer.