Changeset 523
- Timestamp:
- 12/01/14 16:21:48 (10 years ago)
- Location:
- XIOS/trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/inputs/iodef.xml
r512 r523 48 48 <variable id="using_server" type="boolean">false</variable> 49 49 <variable id="info_level" type="int">50</variable> 50 50 <variable id="print_file" type="boolean">true</variable> 51 51 </variable_group> 52 52 </variable_definition> -
XIOS/trunk/src/client.cpp
r511 r523 21 21 int CClient::rank = INVALID_RANK; 22 22 StdOFStream CClient::m_infoStream; 23 StdOFStream CClient::m_errorStream; 23 24 24 25 void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) … … 246 247 } 247 248 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 } 290 329 } -
XIOS/trunk/src/client.hpp
r501 r523 9 9 class CClient 10 10 { 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); 12 15 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 ; 16 20 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 23 22 static int getRank(); 24 23 24 //! Open a file stream to write the info logs 25 25 static void openInfoStream(const StdString& fileName); 26 26 //! Write the info logs to standard output 27 27 static void openInfoStream(); 28 28 //! Close the info logs file if it opens 29 29 static void closeInfoStream(); 30 30 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(); 34 37 38 protected: 39 static int rank; 40 static StdOFStream m_infoStream; 41 static StdOFStream m_errorStream; 35 42 36 } ; 43 static void openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb); 44 }; 37 45 } 38 46 -
XIOS/trunk/src/cxios.cpp
r512 r523 25 25 double CXios::bufferServerFactorSize=1.0 ; 26 26 double CXios::defaultBufferServerFactorSize=1.0 ; 27 bool CXios::printInfo2File; 28 bool CXios::isServerSide; 27 bool CXios::printLogs2Files; 29 28 bool CXios::isOptPerformance = true; 30 29 … … 47 46 info.setLevel(getin<int>("info_level",0)) ; 48 47 report.setLevel(getin<int>("info_level",50)); 49 print Info2File=getin<bool>("print_file",false);48 printLogs2Files=getin<bool>("print_file",false); 50 49 51 50 StdString bufMemory("memory"); … … 77 76 CClient::initialize(codeId,localComm,returnComm) ; 78 77 79 if (usingServer) isServer Side = isServer=false;80 else isServer Side = isServer=true;78 if (usingServer) isServer=false; 79 else isServer=true; 81 80 82 if (printInfo2File) 81 if (printLogs2Files) 82 { 83 83 CClient::openInfoStream(clientFile); 84 CClient::openErrorStream(clientFile); 85 } 84 86 else 87 { 85 88 CClient::openInfoStream(); 89 CClient::openErrorStream(); 90 } 86 91 } 87 92 … … 114 119 isServer=false ; 115 120 116 isServerSide = true;117 118 121 // Initialize all aspects MPI 119 122 CServer::initialize(); 120 123 121 if (printInfo2File) 124 if (printLogs2Files) 125 { 122 126 CServer::openInfoStream(serverFile); 127 CServer::openErrorStream(serverFile); 128 } 123 129 else 130 { 124 131 CServer::openInfoStream(); 132 CServer::openErrorStream(); 133 } 125 134 126 135 // Enter the loop to listen message from Client -
XIOS/trunk/src/cxios.hpp
r512 r523 36 36 static MPI_Comm globalComm ; //!< Global communicator 37 37 38 static bool print Info2File; //!< Printing out information into file38 static bool printLogs2Files; //!< Printing out logs into files 39 39 static bool usingOasis ; //!< Using Oasis 40 40 static bool usingServer ; //!< Using server (server mode) … … 50 50 static void setNotUsingServer(); 51 51 52 //! A silly variable to detect whether one process is in client or server side. Should be removed on refactoring code53 static bool isServerSide;54 55 52 //! Initialize server (if any) 56 53 static void initServer(); -
XIOS/trunk/src/exception.cpp
r501 r523 6 6 #include "server.hpp" 7 7 #include "cxios.hpp" 8 #include "log.hpp" 8 9 9 10 namespace xios … … 34 35 #else 35 36 { 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; 61 38 abort(); 62 39 } 63 64 40 #endif 65 41 } -
XIOS/trunk/src/log.cpp
r501 r523 5 5 CLog info("info") ; 6 6 CLog report("report") ; 7 CLog error("error", cerr.rdbuf()) ; 7 8 } -
XIOS/trunk/src/log.hpp
r501 r523 13 13 { 14 14 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) {} 16 17 CLog& operator()(int l) 17 18 { … … 30 31 31 32 public: 32 //! Write infointo a file with its streambuf33 //! Write log into a file with its streambuf 33 34 void write2File(std::streambuf* sBuff) { changeStreamBuff(sBuff); } 34 35 35 //! Write infointo standard output36 //! Write log into standard output 36 37 void write2StdOut() { changeStreamBuff(cout.rdbuf()); } 38 39 //! Write log into standard error output 40 void write2StdErr() { changeStreamBuff(cerr.rdbuf()); } 41 37 42 private: 38 43 /*! … … 43 48 void changeStreamBuff(std::streambuf* sBuff) { strBuf_ = sBuff; rdbuf(sBuff); } 44 49 45 private :46 50 int level ; 47 51 string name ; … … 51 55 extern CLog info; 52 56 extern CLog report; 57 extern CLog error; 53 58 } 54 59 #endif -
XIOS/trunk/src/server.cpp
r501 r523 21 21 int CServer::rank = INVALID_RANK; 22 22 StdOFStream CServer::m_infoStream; 23 StdOFStream CServer::m_errorStream; 23 24 map<string,CContext*> CServer::contextList ; 24 25 bool CServer::finished=false ; … … 407 408 } 408 409 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 } 450 490 } -
XIOS/trunk/src/server.hpp
r501 r523 11 11 class CServer 12 12 { 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); 14 24 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; 25 28 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 }; 29 34 30 struct contextMessage 31 { 32 int nbRecv ; 33 int leaderRank ; 34 } ; 35 static bool isRoot; 35 36 36 static bool isRoot ; 37 static map<string,CContext*> contextList; 38 static bool finished; 39 static bool is_MPI_Initialized; 37 40 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(); 41 44 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 47 46 static void openInfoStream(const StdString& fileName); 48 49 //! Print information to standard output 47 //! Write the info logs to standard output 50 48 static void openInfoStream(); 51 52 //! Close Info stream (closing file) 49 //! Close the info logs file if it opens 53 50 static void closeInfoStream(); 54 51 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; 56 61 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 }; 59 66 } 60 67
Note: See TracChangeset
for help on using the changeset viewer.