Index: /XIOS/trunk/inputs/iodef.xml
===================================================================
--- /XIOS/trunk/inputs/iodef.xml (revision 522)
+++ /XIOS/trunk/inputs/iodef.xml (revision 523)
@@ -48,5 +48,5 @@
false
50
- true
+ true
Index: /XIOS/trunk/src/client.cpp
===================================================================
--- /XIOS/trunk/src/client.cpp (revision 522)
+++ /XIOS/trunk/src/client.cpp (revision 523)
@@ -21,4 +21,5 @@
int CClient::rank = INVALID_RANK;
StdOFStream CClient::m_infoStream;
+ StdOFStream CClient::m_errorStream;
void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm)
@@ -246,45 +247,83 @@
}
- /*!
- * \brief Open file stream to write in
- * Opening a file stream with a specific file name suffix-client+rank
- * \param [in] protype file name
- */
- void CClient::openInfoStream(const StdString& fileName)
- {
- std::filebuf* fb = m_infoStream.rdbuf();
- StdStringStream fileNameClient;
- int numDigit = 0;
- int size = 0;
- MPI_Comm_size(CXios::globalComm, &size);
- while (size)
- {
- size /= 10;
- ++numDigit;
- }
-
- fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ".out";
- fb->open(fileNameClient.str().c_str(), std::ios::out);
- if (!fb->is_open())
- ERROR("void CClient::openInfoStream(const StdString& fileName)",
- < file to write" );
-
- info.write2File(fb);
- report.write2File(fb);
- }
-
- //! Write out to standard output
- void CClient::openInfoStream()
- {
- info.write2StdOut();
- report.write2StdOut();
- }
-
- //! Close file if it opens
- void CClient::closeInfoStream()
- {
- if (m_infoStream.is_open()) m_infoStream.close();
- }
-
-
+ /*!
+ * Open a file specified by a suffix and an extension and use it for the given file buffer.
+ * The file name will be suffix+rank+extension.
+ *
+ * \param fileName[in] protype file name
+ * \param ext [in] extension of the file
+ * \param fb [in/out] the file buffer
+ */
+ void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)
+ {
+ StdStringStream fileNameClient;
+ int numDigit = 0;
+ int size = 0;
+ MPI_Comm_size(CXios::globalComm, &size);
+ while (size)
+ {
+ size /= 10;
+ ++numDigit;
+ }
+
+ fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext;
+ fb->open(fileNameClient.str().c_str(), std::ios::out);
+ if (!fb->is_open())
+ ERROR("void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)",
+ << std::endl << "Can not open <" << fileNameClient << "> file to write the client log(s).");
+ }
+
+ /*!
+ * \brief Open a file stream to write the info logs
+ * Open a file stream with a specific file name suffix+rank
+ * to write the info logs.
+ * \param fileName [in] protype file name
+ */
+ void CClient::openInfoStream(const StdString& fileName)
+ {
+ std::filebuf* fb = m_infoStream.rdbuf();
+ openStream(fileName, ".out", fb);
+
+ info.write2File(fb);
+ report.write2File(fb);
+ }
+
+ //! Write the info logs to standard output
+ void CClient::openInfoStream()
+ {
+ info.write2StdOut();
+ report.write2StdOut();
+ }
+
+ //! Close the info logs file if it opens
+ void CClient::closeInfoStream()
+ {
+ if (m_infoStream.is_open()) m_infoStream.close();
+ }
+
+ /*!
+ * \brief Open a file stream to write the error log
+ * Open a file stream with a specific file name suffix+rank
+ * to write the error log.
+ * \param fileName [in] protype file name
+ */
+ void CClient::openErrorStream(const StdString& fileName)
+ {
+ std::filebuf* fb = m_errorStream.rdbuf();
+ openStream(fileName, ".err", fb);
+
+ error.write2File(fb);
+ }
+
+ //! Write the error log to standard error output
+ void CClient::openErrorStream()
+ {
+ error.write2StdErr();
+ }
+
+ //! Close the error log file if it opens
+ void CClient::closeErrorStream()
+ {
+ if (m_errorStream.is_open()) m_errorStream.close();
+ }
}
Index: /XIOS/trunk/src/client.hpp
===================================================================
--- /XIOS/trunk/src/client.hpp (revision 522)
+++ /XIOS/trunk/src/client.hpp (revision 523)
@@ -9,30 +9,38 @@
class CClient
{
- public:
+ public:
+ static void initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm);
+ static void finalize(void);
+ static void registerContext(const string& id, MPI_Comm contextComm);
- static void initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) ;
- static void finalize(void) ;
- static void registerContext(const string& id,MPI_Comm contextComm) ;
+ static MPI_Comm intraComm;
+ static MPI_Comm interComm;
+ static int serverLeader;
+ static bool is_MPI_Initialized ;
- static MPI_Comm intraComm ;
- static MPI_Comm interComm ;
- static int serverLeader;
- static bool is_MPI_Initialized ;
-
- public:
+ //! Get rank of the current process
static int getRank();
+ //! Open a file stream to write the info logs
static void openInfoStream(const StdString& fileName);
-
+ //! Write the info logs to standard output
static void openInfoStream();
-
+ //! Close the info logs file if it opens
static void closeInfoStream();
- protected:
- static int rank;
- static StdOFStream m_infoStream;
+ //! Open a file stream to write the error log
+ static void openErrorStream(const StdString& fileName);
+ //! Write the error log to standard error output
+ static void openErrorStream();
+ //! Close the error log file if it opens
+ static void closeErrorStream();
+ protected:
+ static int rank;
+ static StdOFStream m_infoStream;
+ static StdOFStream m_errorStream;
- } ;
+ static void openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb);
+ };
}
Index: /XIOS/trunk/src/cxios.cpp
===================================================================
--- /XIOS/trunk/src/cxios.cpp (revision 522)
+++ /XIOS/trunk/src/cxios.cpp (revision 523)
@@ -25,6 +25,5 @@
double CXios::bufferServerFactorSize=1.0 ;
double CXios::defaultBufferServerFactorSize=1.0 ;
- bool CXios::printInfo2File;
- bool CXios::isServerSide;
+ bool CXios::printLogs2Files;
bool CXios::isOptPerformance = true;
@@ -47,5 +46,5 @@
info.setLevel(getin("info_level",0)) ;
report.setLevel(getin("info_level",50));
- printInfo2File=getin("print_file",false);
+ printLogs2Files=getin("print_file",false);
StdString bufMemory("memory");
@@ -77,11 +76,17 @@
CClient::initialize(codeId,localComm,returnComm) ;
- if (usingServer) isServerSide = isServer=false;
- else isServerSide = isServer=true;
+ if (usingServer) isServer=false;
+ else isServer=true;
- if (printInfo2File)
+ if (printLogs2Files)
+ {
CClient::openInfoStream(clientFile);
+ CClient::openErrorStream(clientFile);
+ }
else
+ {
CClient::openInfoStream();
+ CClient::openErrorStream();
+ }
}
@@ -114,13 +119,17 @@
isServer=false ;
- isServerSide = true;
-
// Initialize all aspects MPI
CServer::initialize();
- if (printInfo2File)
+ if (printLogs2Files)
+ {
CServer::openInfoStream(serverFile);
+ CServer::openErrorStream(serverFile);
+ }
else
+ {
CServer::openInfoStream();
+ CServer::openErrorStream();
+ }
// Enter the loop to listen message from Client
Index: /XIOS/trunk/src/cxios.hpp
===================================================================
--- /XIOS/trunk/src/cxios.hpp (revision 522)
+++ /XIOS/trunk/src/cxios.hpp (revision 523)
@@ -36,5 +36,5 @@
static MPI_Comm globalComm ; //!< Global communicator
- static bool printInfo2File; //!< Printing out information into file
+ static bool printLogs2Files; //!< Printing out logs into files
static bool usingOasis ; //!< Using Oasis
static bool usingServer ; //!< Using server (server mode)
@@ -50,7 +50,4 @@
static void setNotUsingServer();
- //! A silly variable to detect whether one process is in client or server side. Should be removed on refactoring code
- static bool isServerSide;
-
//! Initialize server (if any)
static void initServer();
Index: /XIOS/trunk/src/exception.cpp
===================================================================
--- /XIOS/trunk/src/exception.cpp (revision 522)
+++ /XIOS/trunk/src/exception.cpp (revision 523)
@@ -6,4 +6,5 @@
#include "server.hpp"
#include "cxios.hpp"
+#include "log.hpp"
namespace xios
@@ -34,32 +35,7 @@
#else
{
- int numDigit = 0;
- int size = 0;
- MPI_Comm_size(CXios::globalComm, &size);
- while (size)
- {
- size /= 10;
- ++numDigit;
- }
-
- StdOFStream fileStream;
- StdStringStream fileNameErr;
- std::streambuf* psbuf;
- if (CXios::isServerSide)
- fileNameErr << CXios::serverFile << "_" << std::setfill('0')
- << std::setw(numDigit) << CServer::getRank() << ".err";
- else
- fileNameErr << CXios::clientFile << "_" << std::setfill('0')
- << std::setw(numDigit) << CClient::getRank() << ".err";
-
-
- fileStream.open(fileNameErr.str().c_str(), std::ofstream::out);
- psbuf = fileStream.rdbuf();
- std::cerr.rdbuf(psbuf);
- std::cerr << this->getMessage() << std::endl;
- fileStream.close();
+ error << this->getMessage() << std::endl;
abort();
}
-
#endif
}
Index: /XIOS/trunk/src/log.cpp
===================================================================
--- /XIOS/trunk/src/log.cpp (revision 522)
+++ /XIOS/trunk/src/log.cpp (revision 523)
@@ -5,3 +5,4 @@
CLog info("info") ;
CLog report("report") ;
+ CLog error("error", cerr.rdbuf()) ;
}
Index: /XIOS/trunk/src/log.hpp
===================================================================
--- /XIOS/trunk/src/log.hpp (revision 522)
+++ /XIOS/trunk/src/log.hpp (revision 523)
@@ -13,5 +13,6 @@
{
public :
- CLog(const string& name_) : ostream(cout.rdbuf()),level(0),name(name_), strBuf_(cout.rdbuf()) {}
+ CLog(const string& name_, std::streambuf* sBuff = cout.rdbuf())
+ : ostream(sBuff), level(0), name(name_), strBuf_(sBuff) {}
CLog& operator()(int l)
{
@@ -30,9 +31,13 @@
public:
- //! Write info into a file with its streambuf
+ //! Write log into a file with its streambuf
void write2File(std::streambuf* sBuff) { changeStreamBuff(sBuff); }
- //! Write info into standard output
+ //! Write log into standard output
void write2StdOut() { changeStreamBuff(cout.rdbuf()); }
+
+ //! Write log into standard error output
+ void write2StdErr() { changeStreamBuff(cerr.rdbuf()); }
+
private:
/*!
@@ -43,5 +48,4 @@
void changeStreamBuff(std::streambuf* sBuff) { strBuf_ = sBuff; rdbuf(sBuff); }
- private :
int level ;
string name ;
@@ -51,4 +55,5 @@
extern CLog info;
extern CLog report;
+ extern CLog error;
}
#endif
Index: /XIOS/trunk/src/server.cpp
===================================================================
--- /XIOS/trunk/src/server.cpp (revision 522)
+++ /XIOS/trunk/src/server.cpp (revision 523)
@@ -21,4 +21,5 @@
int CServer::rank = INVALID_RANK;
StdOFStream CServer::m_infoStream;
+ StdOFStream CServer::m_errorStream;
map CServer::contextList ;
bool CServer::finished=false ;
@@ -407,44 +408,83 @@
}
- /*!
- * \brief Open file stream to write in
- * Opening a file stream with a specific file name suffix-server+rank
- * \param [in] protype file name
- */
- void CServer::openInfoStream(const StdString& fileName)
- {
- std::filebuf* fb = m_infoStream.rdbuf();
- StdStringStream fileNameServer;
- int numDigit = 0;
- int size = 0;
- MPI_Comm_size(CXios::globalComm, &size);
- while (size)
- {
- size /= 10;
- ++numDigit;
- }
-
- fileNameServer << fileName <<"_" << std::setfill('0') << std::setw(numDigit) << getRank() << ".out";
- fb->open(fileNameServer.str().c_str(), std::ios::out);
- if (!fb->is_open())
- ERROR("void CServer::openInfoStream(const StdString& fileName)",
- < file to write" );
-
- info.write2File(fb);
- report.write2File(fb);
- }
-
- //! Open stream for standard output
- void CServer::openInfoStream()
- {
- info.write2StdOut();
- report.write2StdOut();
- }
-
- //! Close opening stream
- void CServer::closeInfoStream()
- {
- if (m_infoStream.is_open()) m_infoStream.close();
- }
-
+ /*!
+ * Open a file specified by a suffix and an extension and use it for the given file buffer.
+ * The file name will be suffix+rank+extension.
+ *
+ * \param fileName[in] protype file name
+ * \param ext [in] extension of the file
+ * \param fb [in/out] the file buffer
+ */
+ void CServer::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)
+ {
+ StdStringStream fileNameClient;
+ int numDigit = 0;
+ int size = 0;
+ MPI_Comm_size(CXios::globalComm, &size);
+ while (size)
+ {
+ size /= 10;
+ ++numDigit;
+ }
+
+ fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext;
+ fb->open(fileNameClient.str().c_str(), std::ios::out);
+ if (!fb->is_open())
+ ERROR("void CServer::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)",
+ << std::endl << "Can not open <" << fileNameClient << "> file to write the server log(s).");
+ }
+
+ /*!
+ * \brief Open a file stream to write the info logs
+ * Open a file stream with a specific file name suffix+rank
+ * to write the info logs.
+ * \param fileName [in] protype file name
+ */
+ void CServer::openInfoStream(const StdString& fileName)
+ {
+ std::filebuf* fb = m_infoStream.rdbuf();
+ openStream(fileName, ".out", fb);
+
+ info.write2File(fb);
+ report.write2File(fb);
+ }
+
+ //! Write the info logs to standard output
+ void CServer::openInfoStream()
+ {
+ info.write2StdOut();
+ report.write2StdOut();
+ }
+
+ //! Close the info logs file if it opens
+ void CServer::closeInfoStream()
+ {
+ if (m_infoStream.is_open()) m_infoStream.close();
+ }
+
+ /*!
+ * \brief Open a file stream to write the error log
+ * Open a file stream with a specific file name suffix+rank
+ * to write the error log.
+ * \param fileName [in] protype file name
+ */
+ void CServer::openErrorStream(const StdString& fileName)
+ {
+ std::filebuf* fb = m_errorStream.rdbuf();
+ openStream(fileName, ".err", fb);
+
+ error.write2File(fb);
+ }
+
+ //! Write the error log to standard error output
+ void CServer::openErrorStream()
+ {
+ error.write2StdErr();
+ }
+
+ //! Close the error log file if it opens
+ void CServer::closeErrorStream()
+ {
+ if (m_errorStream.is_open()) m_errorStream.close();
+ }
}
Index: /XIOS/trunk/src/server.hpp
===================================================================
--- /XIOS/trunk/src/server.hpp (revision 522)
+++ /XIOS/trunk/src/server.hpp (revision 523)
@@ -11,50 +11,57 @@
class CServer
{
- public:
+ public:
+ static void initialize(void);
+ static void finalize(void);
+ static void eventLoop(void);
+ static void contextEventLoop(void);
+ static void listenContext(void);
+ static void listenFinalize(void);
+ static void recvContextMessage(void* buff,int count);
+ static void listenRootContext(void);
+ static void listenRootFinalize(void);
+ static void registerContext(void* buff,int count, int leaderRank=0);
- static void initialize(void) ;
- static void finalize(void) ;
- static void eventLoop(void) ;
- static void contextEventLoop(void) ;
- static void listenContext(void) ;
- static void listenFinalize(void) ;
- static void recvContextMessage(void* buff,int count) ;
- static void listenRootContext(void) ;
- static void listenRootFinalize(void) ;
- static void registerContext(void* buff,int count, int leaderRank=0) ;
+ static MPI_Comm intraComm;
+ static list interComm;
+ static CEventScheduler* eventScheduler;
- static MPI_Comm intraComm ;
- static list interComm ;
- static CEventScheduler* eventScheduler ;
+ struct contextMessage
+ {
+ int nbRecv;
+ int leaderRank;
+ };
- struct contextMessage
- {
- int nbRecv ;
- int leaderRank ;
- } ;
+ static bool isRoot;
- static bool isRoot ;
+ static map contextList;
+ static bool finished;
+ static bool is_MPI_Initialized;
- static map contextList ;
- static bool finished ;
- static bool is_MPI_Initialized ;
+ public:
+ //! Get rank of the current process
+ static int getRank();
- public:
- //! Get rank of the current process
- static int getRank();
-
- //! Print Information into a file
+ //! Open a file stream to write the info logs
static void openInfoStream(const StdString& fileName);
-
- //! Print information to standard output
+ //! Write the info logs to standard output
static void openInfoStream();
-
- //! Close Info stream (closing file)
+ //! Close the info logs file if it opens
static void closeInfoStream();
- private:
+ //! Open a file stream to write the error log
+ static void openErrorStream(const StdString& fileName);
+ //! Write the error log to standard error output
+ static void openErrorStream();
+ //! Close the error log file if it opens
+ static void closeErrorStream();
+
+ private:
+ static int rank;
static StdOFStream m_infoStream;
- static int rank ;
- } ;
+ static StdOFStream m_errorStream;
+
+ static void openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb);
+ };
}