Changeset 548 for XIOS/branchs
- Timestamp:
- 01/23/15 16:18:43 (10 years ago)
- Location:
- XIOS/branchs/xios-1.0/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/branchs/xios-1.0/src/client.cpp
r507 r548 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) … … 233 234 } 234 235 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 } 277 316 } -
XIOS/branchs/xios-1.0/src/client.hpp
r501 r548 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/branchs/xios-1.0/src/cxios.cpp
r507 r548 27 27 size_t CXios::defaultBufferSize=1024*1024*100 ; // 100Mo 28 28 double CXios::defaultBufferServerFactorSize=2 ; 29 bool CXios::printInfo2File; 30 bool CXios::isServerSide; 29 bool CXios::printLogs2Files; 31 30 32 31 … … 38 37 usingServer=getin<bool>("using_server",false) ; 39 38 info.setLevel(getin<int>("info_level",0)) ; 40 print Info2File=getin<bool>("print_file",false);39 printLogs2Files=getin<bool>("print_file",false); 41 40 bufferSize=getin<size_t>("buffer_size",defaultBufferSize) ; 42 41 bufferServerFactorSize=getin<double>("buffer_server_factor_size",defaultBufferServerFactorSize) ; … … 54 53 CClient::initialize(codeId,localComm,returnComm) ; 55 54 56 if (usingServer) isServer Side = isServer=false;57 else isServer Side = isServer=true;55 if (usingServer) isServer=false; 56 else isServer=true; 58 57 59 if (printInfo2File) 58 if (printLogs2Files) 59 { 60 60 CClient::openInfoStream(clientFile); 61 CClient::openErrorStream(clientFile); 62 } 61 63 else 64 { 62 65 CClient::openInfoStream(); 66 CClient::openErrorStream(); 67 } 63 68 } 64 69 … … 82 87 isServer=false ; 83 88 84 isServerSide = true;85 86 89 // Initialize all aspects MPI 87 90 CServer::initialize(); 88 91 89 if (printInfo2File) 92 if (printLogs2Files) 93 { 90 94 CServer::openInfoStream(serverFile); 95 CServer::openErrorStream(serverFile); 96 } 91 97 else 98 { 92 99 CServer::openInfoStream(); 100 CServer::openErrorStream(); 101 } 93 102 94 103 // Enter the loop to listen message from Client -
XIOS/branchs/xios-1.0/src/cxios.hpp
r501 r548 35 35 static MPI_Comm globalComm ; 36 36 37 static bool print Info2File;37 static bool printLogs2Files; //!< Printing out logs into files 38 38 static bool usingOasis ; 39 39 static bool usingServer ; … … 49 49 //! Setting xios NOT to use server mode 50 50 static void setNotUsingServer(); 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 51 55 52 } ; -
XIOS/branchs/xios-1.0/src/exception.cpp
r501 r548 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/branchs/xios-1.0/src/log.cpp
r501 r548 5 5 CLog info("info") ; 6 6 CLog report("report") ; 7 CLog error("error", cerr.rdbuf()) ; 7 8 } -
XIOS/branchs/xios-1.0/src/log.hpp
r501 r548 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/branchs/xios-1.0/src/server.cpp
r501 r548 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/branchs/xios-1.0/src/server.hpp
r501 r548 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.