Ignore:
Timestamp:
09/26/14 14:52:04 (10 years ago)
Author:
mhnguyen
Message:

Implementing print output in seperate files

+) Add an option to write information into standard output or into files,
each of which is created by a process
+) Add a new file for global data (constant, value macro, etc)
+) Do a minor change in how to generate doxygen

Test
+) On Curie, with two modes: only client (connected) and client-server
+) All tests passed, each client prints out its info in a seperate file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/client.cpp

    r400 r490  
     1#include "globalScopeData.hpp" 
    12#include "xmlioserver_spl.hpp" 
    23#include "cxios.hpp" 
     
    1213 
    1314namespace xios 
    14 {                       
     15{ 
    1516 
    1617    MPI_Comm CClient::intraComm ; 
     
    1819    int CClient::serverLeader ; 
    1920    bool CClient::is_MPI_Initialized ; 
    20      
    21      
     21    int CClient::rank = INVALID_RANK; 
     22    StdOFStream CClient::m_infoStream; 
     23 
    2224    void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) 
    2325    { 
     
    2628      if (initialized) is_MPI_Initialized=true ; 
    2729      else is_MPI_Initialized=false ; 
    28        
     30 
    2931// don't use OASIS 
    3032      if (!CXios::usingOasis) 
     
    3335        if (localComm == MPI_COMM_NULL) 
    3436        { 
    35           if (!is_MPI_Initialized)  
     37          if (!is_MPI_Initialized) 
    3638          { 
    3739            int argc=0; 
     
    4143          CTimer::get("XIOS").resume() ; 
    4244          CTimer::get("XIOS init").resume() ; 
    43           boost::hash<string> hashString ;     
    44      
     45          boost::hash<string> hashString ; 
     46 
    4547          unsigned long hashClient=hashString(codeId) ; 
    4648          unsigned long hashServer=hashString(CXios::xiosCodeId) ; 
    4749          unsigned long* hashAll ; 
    48           int rank ; 
    4950          int size ; 
    5051          int myColor ; 
    5152          int i,c ; 
    5253          MPI_Comm newComm ; 
    53        
     54 
    5455          MPI_Comm_size(CXios::globalComm,&size) ; 
    5556          MPI_Comm_rank(CXios::globalComm,&rank); 
     57 
    5658          hashAll=new unsigned long[size] ; 
    57       
     59 
    5860          MPI_Allgather(&hashClient,1,MPI_LONG,hashAll,1,MPI_LONG,CXios::globalComm) ; 
    5961 
    6062          map<unsigned long, int> colors ; 
    6163          map<unsigned long, int> leaders ; 
    62        
     64 
    6365          for(i=0,c=0;i<size;i++) 
    6466          { 
     
    7072            } 
    7173          } 
    72       
     74 
    7375          myColor=colors[hashClient] ; 
    74        
     76 
    7577          MPI_Comm_split(CXios::globalComm,myColor,rank,&intraComm) ; 
    7678 
    7779          if (CXios::usingServer) 
    78           {      
     80          { 
    7981            int clientLeader=leaders[hashClient] ; 
    8082            serverLeader=leaders[hashServer] ; 
     
    8890        } 
    8991        // localComm argument is given 
    90         else  
     92        else 
    9193        { 
    9294          if (CXios::usingServer) 
    93           {           
     95          { 
    9496            //ERROR("void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm)", << " giving a local communictor is not compatible with using server mode") ; 
    9597          } 
     
    113115        CTimer::get("XIOS").resume() ; 
    114116        CTimer::get("XIOS init").resume() ; 
    115    
    116         if (CXios::usingServer)  
     117 
     118        if (CXios::usingServer) 
    117119        { 
    118120          MPI_Status status ; 
    119           int rank ; 
    120           MPI_Comm_rank(intraComm,&rank) ; 
    121  
     121            MPI_Comm_rank(intraComm,&rank) ; 
    122122          oasis_get_intercomm(interComm,CXios::xiosCodeId) ; 
    123123          if (rank==0) MPI_Recv(&serverLeader,1, MPI_INT, 0, 0, interComm, &status) ; 
    124124          MPI_Bcast(&serverLeader,1,MPI_INT,0,intraComm) ; 
    125             
     125 
    126126        } 
    127127        else MPI_Comm_dup(intraComm,&interComm) ; 
    128128      } 
    129            
     129 
    130130      MPI_Comm_dup(intraComm,&returnComm) ; 
    131131    } 
    132      
    133      
     132 
     133 
    134134    void CClient::registerContext(const string& id,MPI_Comm contextComm) 
    135135    { 
    136136      CContext::setCurrent(id) ; 
    137137      CContext* context=CContext::create(id) ; 
    138          
     138 
    139139      if (!CXios::isServer) 
    140140      { 
     
    143143        int leaderRank ; 
    144144        MPI_Comm contextInterComm ; 
    145        
     145 
    146146        MPI_Comm_size(contextComm,&size) ; 
    147147        MPI_Comm_rank(contextComm,&rank) ; 
    148148        MPI_Comm_rank(CXios::globalComm,&globalRank) ; 
    149149        if (rank!=0) globalRank=0 ; 
    150        
    151      
     150 
     151 
    152152        CMessage msg ; 
    153153        msg<<id<<size<<globalRank ; 
     
    157157        CBufferOut buffer(buff,messageSize) ; 
    158158        buffer<<msg ; 
    159        
     159 
    160160        MPI_Send(buff,buffer.count(),MPI_CHAR,serverLeader,1,CXios::globalComm) ; 
    161161        delete [] buff ; 
    162        
     162 
    163163        MPI_Intercomm_create(contextComm,0,CXios::globalComm,serverLeader,10+globalRank,&contextInterComm) ; 
    164164        info(10)<<"Register new Context : "<<id<<endl ; 
    165   
     165 
    166166        MPI_Comm inter ; 
    167167        MPI_Intercomm_merge(contextInterComm,0,&inter) ; 
     
    178178      } 
    179179    } 
    180      
     180 
    181181    void CClient::finalize(void) 
    182182    { 
     
    185185      if (!CXios::isServer) 
    186186      { 
    187         MPI_Comm_rank(intraComm,&rank) ;   
    188         if (rank==0)  
     187        MPI_Comm_rank(intraComm,&rank) ; 
     188        if (rank==0) 
    189189        { 
    190190          MPI_Send(&msg,1,MPI_INT,0,0,interComm) ; 
    191191        } 
    192192      } 
    193        
     193 
    194194     CTimer::get("XIOS finalize").suspend() ; 
    195195     CTimer::get("XIOS").suspend() ; 
     
    201201      } 
    202202      info(20) << "Client side context is finalized"<<endl ; 
    203       report(0) <<" Performance report : total time spent for XIOS : "<< CTimer::get("XIOS").getCumulatedTime()<<" s"<<endl ;  
     203      report(0) <<" Performance report : total time spent for XIOS : "<< CTimer::get("XIOS").getCumulatedTime()<<" s"<<endl ; 
    204204      report(0)<< " Performance report : time spent for waiting free buffer : "<< CTimer::get("Blocking time").getCumulatedTime()<<" s"<<endl ; 
    205205      report(0)<< " Performance report : Ratio : "<< CTimer::get("Blocking time").getCumulatedTime()/CTimer::get("XIOS").getCumulatedTime()*100.<<" %"<<endl ; 
     
    209209      report(0)<< " Memory report : increasing it by a factor will increase performance, depending of the volume of data wrote in file at each time step of the file"<<endl ; 
    210210   } 
     211 
     212   int CClient::getRank() 
     213   { 
     214     return rank; 
     215   } 
     216 
     217     /*! 
     218      * \brief Open file stream to write in 
     219      *   Opening a file stream with a specific file name suffix-client+rank 
     220      * \param [in] protype file name 
     221     */ 
     222     void CClient::openInfoStream(const StdString& fileName) 
     223     { 
     224       std::filebuf* fb = m_infoStream.rdbuf(); 
     225       StdStringStream fileNameClient; 
     226       fileNameClient << fileName <<"_client_" << getRank() << ".txt"; 
     227       fb->open(fileNameClient.str().c_str(), std::ios::out); 
     228       if (!fb->is_open()) 
     229       ERROR("void CClient::openInfoStream(const StdString& fileName)", 
     230            <<endl<< "Can not open <"<<fileNameClient<<"> file to write" ); 
     231 
     232       info.write2File(fb); 
     233     } 
     234 
     235     //! Write out to standard output 
     236     void CClient::openInfoStream() 
     237     { 
     238       info.write2StdOut(); 
     239     } 
     240 
     241     //! Close file if it opens 
     242     void CClient::closeInfoStream() 
     243     { 
     244       if (m_infoStream.is_open()) m_infoStream.close(); 
     245     } 
     246 
     247 
    211248} 
Note: See TracChangeset for help on using the changeset viewer.