Ignore:
Timestamp:
07/31/17 17:59:25 (7 years ago)
Author:
mhnguyen
Message:

Fixing the blocking problem where there are more servers than the number of grid band distribution

+) Correct this problem not only for writing but also for reading
+) Allow "zero-size" domain, axis (i.e: domain, axis with ni = 0, and/or nj=0)

Test
+) On Curie
+) Work in both cases: Read and Write data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/XIOS_DEV_CMIP6/src/node/file.cpp

    r1201 r1232  
    2525      : CObjectTemplate<CFile>(), CFileAttributes() 
    2626      , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 
    27       , allDomainEmpty(false), isOpen(false) 
     27      , isOpen(false), read_client(0), checkRead(false), allZoneEmpty(false) 
    2828   { 
    2929     setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group")); 
     
    3434      : CObjectTemplate<CFile>(id), CFileAttributes() 
    3535      , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 
    36       , allDomainEmpty(false), isOpen(false) 
     36      , isOpen(false), read_client(0), checkRead(false), allZoneEmpty(false) 
    3737    { 
    3838      setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group")); 
     
    207207 
    208208   //! Initialize a file in order to write into it 
    209    void CFile::initFile(void) 
     209   void CFile::initWrite(void) 
    210210   { 
    211211      CContext* context = CContext::getCurrent(); 
     
    228228        } 
    229229      } 
    230       isOpen = false; 
    231  
    232       allDomainEmpty = true; 
     230      isOpen = false;       
    233231 
    234232//      if (!record_offset.isEmpty() && record_offset < 0) 
     
    243241      for (it = this->enabledFields.begin(); it != end; it++) 
    244242      { 
    245          CField* field = *it; 
    246          allDomainEmpty &= !field->grid->doGridHaveDataToWrite(); 
     243         CField* field = *it;          
    247244         std::vector<CAxis*> vecAxis = field->grid->getAxis(); 
    248245         for (size_t i = 0; i < vecAxis.size(); ++i) 
    249246           setAxis.insert(vecAxis[i]->getAxisOutputName()); 
    250 //            setAxis.insert(vecAxis[i]); 
    251247         std::vector<CDomain*> vecDomains = field->grid->getDomains(); 
    252248         for (size_t i = 0; i < vecDomains.size(); ++i) 
    253249           setDomains.insert(vecDomains[i]->getDomainOutputName()); 
    254 //            setDomains.insert(vecDomains[i]); 
    255250 
    256251         field->resetNStep(recordOffset); 
     
    260255 
    261256      // create sub communicator for file 
    262       int color = allDomainEmpty ? 0 : 1; 
    263       MPI_Comm_split(server->intraComm, color, server->intraCommRank, &fileComm); 
    264       if (allDomainEmpty) MPI_Comm_free(&fileComm); 
     257      createSubComFile(); 
    265258 
    266259      // if (time_counter.isEmpty()) time_counter.setValue(time_counter_attr::centered); 
    267260      if (time_counter_name.isEmpty()) time_counter_name = "time_counter"; 
     261    } 
     262 
     263    //! Initialize a file in order to write into it 
     264    void CFile::initRead(void) 
     265    { 
     266      if (checkRead) return; 
     267      createSubComFile(); 
     268      checkRead = true; 
     269    } 
     270 
     271    /*! 
     272      Create a sub communicator in which processes participate in reading/opening file 
     273    */ 
     274    void CFile::createSubComFile() 
     275    { 
     276      CContext* context = CContext::getCurrent(); 
     277      CContextServer* server = context->server; 
     278 
     279      // create sub communicator for file 
     280      allZoneEmpty = true;       
     281      std::vector<CField*>::iterator it, end = this->enabledFields.end(); 
     282      for (it = this->enabledFields.begin(); it != end; it++) 
     283      { 
     284         CField* field = *it; 
     285         bool nullGrid = (0 == field->grid); 
     286         allZoneEmpty &= nullGrid ? false : !field->grid->doGridHaveDataToWrite(); 
     287      } 
     288 
     289      int color = allZoneEmpty ? 0 : 1; 
     290      MPI_Comm_split(server->intraComm, color, server->intraCommRank, &fileComm); 
     291      if (allZoneEmpty) MPI_Comm_free(&fileComm); 
    268292    } 
    269293 
     
    307331        { 
    308332          CTimer::get("Files : open headers").resume(); 
    309           if (!isOpen) openInReadMode(&(context->server->intraComm)); 
     333           
     334          if (!isOpen) openInReadMode(); 
     335 
    310336          CTimer::get("Files : open headers").suspend(); 
    311337        } 
    312338        //checkSplit(); // Really need for reading? 
    313339      } 
     340    } 
     341 
     342    /*! 
     343      Verify if a process participates in an opening-file communicator  
     344      \return true if the process doesn't participate in opening file 
     345    */ 
     346    bool CFile::isEmptyZone() 
     347    { 
     348      return allZoneEmpty; 
    314349    } 
    315350 
     
    376411      CContextServer* server = context->server; 
    377412 
    378       if (!allDomainEmpty) 
     413      if (!allZoneEmpty) 
    379414      { 
    380415         StdString filename = getFileOutputName(); 
     
    558593  \brief Open an existing NetCDF file in read-only mode 
    559594  */ 
    560   void CFile::openInReadMode(MPI_Comm* comm) 
     595  void CFile::openInReadMode() 
    561596  { 
    562597    CContext* context = CContext::getCurrent(); 
    563598    CContextServer* server = context->server; 
    564     MPI_Comm readComm = *comm; 
    565  
    566     if (!allDomainEmpty) 
     599    MPI_Comm readComm = this->fileComm; 
     600 
     601    if (!allZoneEmpty) 
    567602    { 
    568603      StdString filename = getFileOutputName(); 
     
    632667   void CFile::close(void) 
    633668   { 
    634      if (!allDomainEmpty) 
     669     if (!allZoneEmpty) 
    635670       if (isOpen) 
    636671       { 
     
    639674         else 
    640675          this->data_in->closeFile(); 
     676        isOpen = false; 
    641677       } 
    642678      if (fileComm != MPI_COMM_NULL) MPI_Comm_free(&fileComm); 
     
    905941   } 
    906942 
     943   void CFile::setReadContextClient(CContextClient* readContextclient) 
     944   { 
     945     read_client = readContextclient; 
     946   } 
     947 
     948   CContextClient* CFile::getReadContextClient() 
     949   { 
     950     return read_client; 
     951   } 
     952 
    907953   /*! 
    908954   \brief Send a message to create a field on server side 
Note: See TracChangeset for help on using the changeset viewer.