Ignore:
Timestamp:
11/15/17 12:14:34 (7 years ago)
Author:
yushan
Message:

dev_omp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/branch_openmp/src/client.cpp

    r1205 r1328  
    1111#include "timer.hpp" 
    1212#include "buffer_client.hpp" 
    13 #include "log.hpp" 
    14  
     13using namespace ep_lib; 
    1514 
    1615namespace xios 
    1716{ 
    18     extern int test_omp_rank; 
    19     #pragma omp threadprivate(test_omp_rank) 
    2017 
    2118    MPI_Comm CClient::intraComm ; 
    2219    MPI_Comm CClient::interComm ; 
     20    //std::list<MPI_Comm> CClient::contextInterComms; 
    2321    std::list<MPI_Comm> *CClient::contextInterComms_ptr = 0; 
    2422    int CClient::serverLeader ; 
     
    2826    StdOFStream CClient::m_errorStream; 
    2927 
    30     StdOFStream CClient::array_infoStream[16]; 
    31  
    32     void CClient::initialize(const string& codeId, MPI_Comm& localComm, MPI_Comm& returnComm) 
     28    void CClient::initialize(const string& codeId,MPI_Comm& localComm,MPI_Comm& returnComm) 
    3329    { 
    3430      int initialized ; 
     
    4137      { 
    4238// localComm doesn't given 
    43  
    4439        if (localComm == MPI_COMM_NULL) 
    4540        { 
    4641          if (!is_MPI_Initialized) 
    4742          { 
    48             //MPI_Init(NULL, NULL); 
    49             int return_level; 
    50             MPI_Init_thread(NULL, NULL, 3, &return_level); 
    51             assert(return_level == 3); 
     43            MPI_Init(NULL, NULL); 
    5244          } 
    5345          CTimer::get("XIOS").resume() ; 
     
    6153          int myColor ; 
    6254          int i,c ; 
    63  
    64           MPI_Comm_size(CXios::globalComm,&size); 
     55          MPI_Comm newComm ; 
     56 
     57          MPI_Comm_size(CXios::globalComm,&size) ; 
    6558          MPI_Comm_rank(CXios::globalComm,&rank); 
    66         
    6759 
    6860          hashAll=new unsigned long[size] ; 
     
    10698            MPI_Comm_size(intraComm,&intraCommSize) ; 
    10799            MPI_Comm_rank(intraComm,&intraCommRank) ; 
    108              
    109             #pragma omp critical(_output) 
    110             { 
    111               info(10)<<"intercommCreate::client "<<test_omp_rank<< " "<< &test_omp_rank <<" intraCommSize : "<<intraCommSize 
    112                  <<" intraCommRank :"<<intraCommRank<<"  serverLeader "<< serverLeader 
    113                  <<" globalComm : "<< &(CXios::globalComm) << endl ;   
    114             } 
    115  
    116              
    117             //test_sendrecv(CXios::globalComm); 
     100            info(50)<<"intercommCreate::client "<<rank<<" intraCommSize : "<<intraCommSize 
     101                 <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< serverLeader<<endl ; 
    118102            MPI_Intercomm_create(intraComm,0,CXios::globalComm,serverLeader,0,&interComm) ; 
    119  
    120103          } 
    121104          else 
     
    140123      } 
    141124      // using OASIS 
    142       else 
     125/*      else 
    143126      { 
    144127        // localComm doesn't given 
     
    165148        else MPI_Comm_dup(intraComm,&interComm) ; 
    166149      } 
    167  
     150*/ 
    168151      MPI_Comm_dup(intraComm,&returnComm) ; 
    169  
    170152    } 
    171153 
     
    174156    { 
    175157      CContext::setCurrent(id) ; 
    176       CContext* context = CContext::create(id); 
    177  
    178       int tmp_rank; 
    179       MPI_Comm_rank(contextComm,&tmp_rank) ; 
    180        
     158      CContext* context=CContext::create(id); 
    181159      StdString idServer(id); 
    182160      idServer += "_server"; 
     
    185163      { 
    186164        int size,rank,globalRank ; 
    187         //size_t message_size ; 
    188         //int leaderRank ; 
     165        size_t message_size ; 
     166        int leaderRank ; 
    189167        MPI_Comm contextInterComm ; 
    190168 
     
    197175        CMessage msg ; 
    198176        msg<<idServer<<size<<globalRank ; 
    199  
     177//        msg<<id<<size<<globalRank ; 
    200178 
    201179        int messageSize=msg.size() ; 
     
    208186 
    209187        MPI_Intercomm_create(contextComm,0,CXios::globalComm,serverLeader,10+globalRank,&contextInterComm) ; 
    210          
    211         #pragma omp critical(_output) 
    212         info(10)<<" RANK "<< tmp_rank<<" Register new Context : "<<id<<endl ; 
    213  
     188        info(10)<<"Register new Context : "<<id<<endl ; 
    214189 
    215190        MPI_Comm inter ; 
     
    217192        MPI_Barrier(inter) ; 
    218193 
    219          
    220194        context->initClient(contextComm,contextInterComm) ; 
    221195 
    222          
     196        //contextInterComms.push_back(contextInterComm); 
    223197        if(contextInterComms_ptr == NULL) contextInterComms_ptr = new std::list<MPI_Comm>; 
    224198        contextInterComms_ptr->push_back(contextInterComm); 
    225          
    226199        MPI_Comm_free(&inter); 
    227200      } 
     
    240213        // Finally, we should return current context to context client 
    241214        CContext::setCurrent(id); 
    242          
     215 
     216        //contextInterComms.push_back(contextInterComm); 
    243217        if(contextInterComms_ptr == NULL) contextInterComms_ptr = new std::list<MPI_Comm>; 
    244218        contextInterComms_ptr->push_back(contextInterComm); 
    245  
    246219      } 
    247220    } 
     
    253226 
    254227      MPI_Comm_rank(intraComm,&rank) ; 
    255  
     228  
    256229      if (!CXios::isServer) 
    257230      { 
     
    263236      } 
    264237 
    265       for (std::list<MPI_Comm>::iterator it = contextInterComms_ptr->begin(); it != contextInterComms_ptr->end(); ++it) 
     238      //for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++) 
     239      for (std::list<MPI_Comm>::iterator it = contextInterComms_ptr->begin(); it != contextInterComms_ptr->end(); it++) 
    266240        MPI_Comm_free(&(*it)); 
    267        
    268241      MPI_Comm_free(&interComm); 
    269242      MPI_Comm_free(&intraComm); 
     
    274247      if (!is_MPI_Initialized) 
    275248      { 
    276         if (CXios::usingOasis) oasis_finalize(); 
    277         else MPI_Finalize(); 
     249        //if (CXios::usingOasis) oasis_finalize(); 
     250        //else 
     251        MPI_Finalize() ; 
    278252      } 
    279253       
    280       #pragma omp critical (_output) 
    281       info(20) << "Client "<<rank<<" : Client side context is finalized "<< endl ; 
    282  
    283    /*#pragma omp critical (_output) 
    284    { 
     254      info(20) << "Client side context is finalized"<<endl ; 
    285255      report(0) <<" Performance report : Whole time from XIOS init and finalize: "<< CTimer::get("XIOS init/finalize").getCumulatedTime()<<" s"<<endl ; 
    286256      report(0) <<" Performance report : total time spent for XIOS : "<< CTimer::get("XIOS").getCumulatedTime()<<" s"<<endl ; 
     
    292262      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 ; 
    293263      report(100)<<CTimer::getAllCumulatedTime()<<endl ; 
    294    }*/ 
    295     
    296264   } 
    297265 
     
    322290 
    323291      fileNameClient << fileName << "_" << std::setfill('0') << std::setw(numDigit) << getRank() << ext; 
    324        
    325292      fb->open(fileNameClient.str().c_str(), std::ios::out); 
    326293      if (!fb->is_open()) 
    327294        ERROR("void CClient::openStream(const StdString& fileName, const StdString& ext, std::filebuf* fb)", 
    328             << std::endl << "Can not open <" << fileNameClient << "> file to write the client log(s)."); 
     295              << std::endl << "Can not open <" << fileNameClient << "> file to write the client log(s)."); 
    329296    } 
    330297 
     
    337304    void CClient::openInfoStream(const StdString& fileName) 
    338305    { 
    339       //std::filebuf* fb = m_infoStream.rdbuf(); 
    340  
    341       info_FB[omp_get_thread_num()] = array_infoStream[omp_get_thread_num()].rdbuf(); 
    342            
    343       openStream(fileName, ".out", info_FB[omp_get_thread_num()]); 
    344  
    345       info.write2File(info_FB[omp_get_thread_num()]); 
    346       report.write2File(info_FB[omp_get_thread_num()]); 
    347        
     306      std::filebuf* fb = m_infoStream.rdbuf(); 
     307      openStream(fileName, ".out", fb); 
     308 
     309      info.write2File(fb); 
     310      report.write2File(fb); 
    348311    } 
    349312 
Note: See TracChangeset for help on using the changeset viewer.