Changeset 523


Ignore:
Timestamp:
12/01/14 16:21:48 (6 years ago)
Author:
rlacroix
Message:

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/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/inputs/iodef.xml

    r512 r523  
    4848          <variable id="using_server" type="boolean">false</variable> 
    4949          <variable id="info_level" type="int">50</variable> 
    50           <variable id="print_file" type="boolean">true</variable> 
     50          <variable id="print_file" type="boolean">true</variable> 
    5151        </variable_group> 
    5252      </variable_definition> 
  • XIOS/trunk/src/client.cpp

    r511 r523  
    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) 
     
    246247   } 
    247248 
    248      /*! 
    249       * \brief Open file stream to write in 
    250       *   Opening a file stream with a specific file name suffix-client+rank 
    251       * \param [in] protype file name 
    252      */ 
    253      void CClient::openInfoStream(const StdString& fileName) 
    254      { 
    255        std::filebuf* fb = m_infoStream.rdbuf(); 
    256        StdStringStream fileNameClient; 
    257        int numDigit = 0; 
    258        int size = 0; 
    259        MPI_Comm_size(CXios::globalComm, &size); 
    260        while (size) 
    261        { 
    262          size /= 10; 
    263          ++numDigit; 
    264        } 
    265  
    266        fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ".out"; 
    267        fb->open(fileNameClient.str().c_str(), std::ios::out); 
    268        if (!fb->is_open()) 
    269        ERROR("void CClient::openInfoStream(const StdString& fileName)", 
    270             <<endl<< "Can not open <"<<fileNameClient<<"> file to write" ); 
    271  
    272        info.write2File(fb); 
    273        report.write2File(fb); 
    274      } 
    275  
    276      //! Write out to standard output 
    277      void CClient::openInfoStream() 
    278      { 
    279        info.write2StdOut(); 
    280        report.write2StdOut(); 
    281      } 
    282  
    283      //! Close file if it opens 
    284      void CClient::closeInfoStream() 
    285      { 
    286        if (m_infoStream.is_open()) m_infoStream.close(); 
    287      } 
    288  
    289  
     249    /*! 
     250    * Open a file specified by a suffix and an extension and use it for the given file buffer. 
     251    * The file name will be suffix+rank+extension. 
     252    *  
     253    * \param fileName[in] protype file name 
     254    * \param ext [in] extension of the file 
     255    * \param fb [in/out] the file buffer 
     256    */ 
     257    void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb) 
     258    { 
     259      StdStringStream fileNameClient; 
     260      int numDigit = 0; 
     261      int size = 0; 
     262      MPI_Comm_size(CXios::globalComm, &size); 
     263      while (size) 
     264      { 
     265        size /= 10; 
     266        ++numDigit; 
     267      } 
     268 
     269      fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext; 
     270      fb->open(fileNameClient.str().c_str(), std::ios::out); 
     271      if (!fb->is_open()) 
     272        ERROR("void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)", 
     273              << std::endl << "Can not open <" << fileNameClient << "> file to write the client log(s)."); 
     274    } 
     275 
     276    /*! 
     277    * \brief Open a file stream to write the info logs 
     278    * Open a file stream with a specific file name suffix+rank 
     279    * to write the info logs. 
     280    * \param fileName [in] protype file name 
     281    */ 
     282    void CClient::openInfoStream(const StdString& fileName) 
     283    { 
     284      std::filebuf* fb = m_infoStream.rdbuf(); 
     285      openStream(fileName, ".out", fb); 
     286 
     287      info.write2File(fb); 
     288      report.write2File(fb); 
     289    } 
     290 
     291    //! Write the info logs to standard output 
     292    void CClient::openInfoStream() 
     293    { 
     294      info.write2StdOut(); 
     295      report.write2StdOut(); 
     296    } 
     297 
     298    //! Close the info logs file if it opens 
     299    void CClient::closeInfoStream() 
     300    { 
     301      if (m_infoStream.is_open()) m_infoStream.close(); 
     302    } 
     303 
     304    /*! 
     305    * \brief Open a file stream to write the error log 
     306    * Open a file stream with a specific file name suffix+rank 
     307    * to write the error log. 
     308    * \param fileName [in] protype file name 
     309    */ 
     310    void CClient::openErrorStream(const StdString& fileName) 
     311    { 
     312      std::filebuf* fb = m_errorStream.rdbuf(); 
     313      openStream(fileName, ".err", fb); 
     314 
     315      error.write2File(fb); 
     316    } 
     317 
     318    //! Write the error log to standard error output 
     319    void CClient::openErrorStream() 
     320    { 
     321      error.write2StdErr(); 
     322    } 
     323 
     324    //! Close the error log file if it opens 
     325    void CClient::closeErrorStream() 
     326    { 
     327      if (m_errorStream.is_open()) m_errorStream.close(); 
     328    } 
    290329} 
  • XIOS/trunk/src/client.hpp

    r501 r523  
    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/trunk/src/cxios.cpp

    r512 r523  
    2525  double CXios::bufferServerFactorSize=1.0 ; 
    2626  double CXios::defaultBufferServerFactorSize=1.0 ; 
    27   bool CXios::printInfo2File; 
    28   bool CXios::isServerSide; 
     27  bool CXios::printLogs2Files; 
    2928  bool CXios::isOptPerformance = true; 
    3029 
     
    4746    info.setLevel(getin<int>("info_level",0)) ; 
    4847    report.setLevel(getin<int>("info_level",50)); 
    49     printInfo2File=getin<bool>("print_file",false); 
     48    printLogs2Files=getin<bool>("print_file",false); 
    5049 
    5150    StdString bufMemory("memory"); 
     
    7776    CClient::initialize(codeId,localComm,returnComm) ; 
    7877 
    79     if (usingServer) isServerSide = isServer=false; 
    80     else isServerSide = isServer=true; 
     78    if (usingServer) isServer=false; 
     79    else isServer=true; 
    8180 
    82     if (printInfo2File) 
     81    if (printLogs2Files) 
     82    { 
    8383      CClient::openInfoStream(clientFile); 
     84      CClient::openErrorStream(clientFile); 
     85    } 
    8486    else 
     87    { 
    8588      CClient::openInfoStream(); 
     89      CClient::openErrorStream(); 
     90    } 
    8691  } 
    8792 
     
    114119    isServer=false ; 
    115120 
    116     isServerSide = true; 
    117  
    118121    // Initialize all aspects MPI 
    119122    CServer::initialize(); 
    120123 
    121     if (printInfo2File) 
     124    if (printLogs2Files) 
     125    { 
    122126      CServer::openInfoStream(serverFile); 
     127      CServer::openErrorStream(serverFile); 
     128    } 
    123129    else 
     130    { 
    124131      CServer::openInfoStream(); 
     132      CServer::openErrorStream(); 
     133    } 
    125134 
    126135    // Enter the loop to listen message from Client 
  • XIOS/trunk/src/cxios.hpp

    r512 r523  
    3636     static MPI_Comm globalComm ; //!< Global communicator 
    3737 
    38      static bool printInfo2File; //!< Printing out information into file 
     38     static bool printLogs2Files; //!< Printing out logs into files 
    3939     static bool usingOasis ; //!< Using Oasis 
    4040     static bool usingServer ; //!< Using server (server mode) 
     
    5050     static void setNotUsingServer(); 
    5151 
    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; 
    54  
    5552     //! Initialize server (if any) 
    5653     static  void initServer(); 
  • XIOS/trunk/src/exception.cpp

    r501 r523  
    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/trunk/src/log.cpp

    r501 r523  
    55  CLog info("info") ; 
    66  CLog report("report") ; 
     7  CLog error("error", cerr.rdbuf()) ; 
    78} 
  • XIOS/trunk/src/log.hpp

    r501 r523  
    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/trunk/src/server.cpp

    r501 r523  
    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/trunk/src/server.hpp

    r501 r523  
    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.