Ignore:
Timestamp:
10/22/12 13:47:08 (12 years ago)
Author:
ymipsl
Message:
  • zoom can be output in single file without need to patch the netcdf library
  • sequential version of netcdf4 are now managed. Can be used to output in multiple_file mode

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/file.cpp

    r375 r379  
    1515#include "xmlioserver_spl.hpp" 
    1616#include "context_client.hpp" 
     17#include <mpi.h> 
    1718 
    1819namespace xios { 
     
    2223   CFile::CFile(void) 
    2324      : CObjectTemplate<CFile>(), CFileAttributes() 
    24       , vFieldGroup(), data_out(), enabledFields() 
     25      , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 
    2526   { setVirtualFieldGroup() ;} 
    2627 
    2728   CFile::CFile(const StdString & id) 
    2829      : CObjectTemplate<CFile>(id), CFileAttributes() 
    29       , vFieldGroup(), data_out(), enabledFields() 
     30      , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 
    3031   { setVirtualFieldGroup() ;} 
    3132 
     
    146147      CContext* context = CContext::getCurrent() ; 
    147148      CDate& currentDate=context->calendar->getCurrentDate() ; 
    148        
     149      CContextServer* server=context->server ; 
     150             
    149151      if (! sync_freq.isEmpty()) syncFreq = CDuration::FromString(sync_freq.getValue()); 
    150152      if (! split_freq.isEmpty()) splitFreq = CDuration::FromString(split_freq.getValue()); 
     
    153155      lastSplit=new CDate(currentDate) ; 
    154156      isOpen=false ; 
     157 
     158      allDomainEmpty=true ; 
     159      set<CDomain*> setDomain ; 
     160 
     161      std::vector<CField*>::iterator it, end = this->enabledFields.end(); 
     162      for (it = this->enabledFields.begin() ;it != end; it++) 
     163      { 
     164         CField* field = *it; 
     165         allDomainEmpty&=field->grid->domain->isEmpty() ; 
     166         setDomain.insert(field->grid->domain) ; 
     167      } 
     168      nbDomain=setDomain.size() ; 
     169 
     170      // create sub communicator for file   
     171      int color=allDomainEmpty?0:1 ; 
     172      MPI_Comm_split(server->intraComm,color,server->intraCommRank,&fileComm) ; 
     173      if (allDomainEmpty) MPI_Comm_free(&fileComm) ; 
     174      // 
     175       
    155176    } 
    156177     
     
    202223   { 
    203224      CContext* context = CContext::getCurrent() ; 
    204       CDate& currentDate=context->calendar->getCurrentDate() ; 
    205        
    206       std::vector<CField*>::iterator it, end = this->enabledFields.end(); 
    207  
    208       AllDomainEmpty=true ; 
    209       set<CDomain*> setDomain ; 
    210       for (it = this->enabledFields.begin() ;it != end; it++) 
    211       { 
    212          CField* field = *it; 
    213          AllDomainEmpty&=field->grid->domain->isEmpty() ; 
    214          setDomain.insert(field->grid->domain) ; 
    215       } 
    216       nbDomain=setDomain.size() ; 
    217  
    218       if (!AllDomainEmpty ||  type == type_attr::one_file) 
     225      CContextServer* server=context->server ; 
     226      
     227      if (!allDomainEmpty) 
    219228      { 
    220229         StdString filename = (!name.isEmpty()) ?   name.getValue() : getId(); 
    221230         StdOStringStream oss; 
    222 //         if (! output_dir.isEmpty()) oss << output_dir.getValue(); 
    223231         oss << filename; 
    224232         if (!name_suffix.isEmpty()) oss << name_suffix.getValue(); 
    225 //         if (!split_freq.isEmpty()) oss<<"-["<<currentDate.toString()<<"]" ; 
    226233         if (!split_freq.isEmpty()) oss<<"_"<<lastSplit->getStryyyymmdd()<<"-"<< (*lastSplit+(splitFreq-1*Second)).getStryyyymmdd(); 
    227234         bool multifile=true ; 
     
    230237           if (type==type_attr::one_file) multifile=false ; 
    231238           else if (type==type_attr::multiple_file) multifile=true ; 
    232            else ERROR("void Context::createDataOutput(void)", 
    233                       "incorrect file <type> attribut : must be <multi_file> or <one_file>, " 
    234                       <<"having : <"<<type.getValue()<<">") ; 
     239 
    235240         }  
    236           
    237          CContextServer* server=context->server ; 
    238  
     241#ifndef USING_NETCDF_PAR 
     242         if (!multifile) 
     243         { 
     244            info(0)<<"!!! Warning -> Using non parallel version of netcdf, switching in multiple_file mode for file : "<<filename<<" ..."<<endl ; 
     245            multifile=true ; 
     246          } 
     247#endif 
    239248         if (multifile)  
    240249         { 
     250            int commSize, commRank ; 
     251            MPI_Comm_size(fileComm,&commSize) ; 
     252            MPI_Comm_rank(fileComm,&commRank) ; 
     253             
    241254            if (server->intraCommSize > 1)  
    242255            { 
    243256              oss << "_"  ; 
    244               int width=0 ; int n=server->intraCommSize-1 ; 
     257              int width=0 ; int n=commSize-1 ; 
    245258              while(n != 0) { n=n/10 ; width++ ;} 
    246259              oss.width(width) ; 
    247260              oss.fill('0') ; 
    248               oss<<right<< server->intraCommRank; 
     261              oss<<right<< commRank; 
    249262            } 
    250263         } 
     
    264277           } 
    265278         } 
    266          data_out=shared_ptr<CDataOutput>(new CNc4DataOutput(oss.str(), false,server->intraComm,multifile, isCollective)); 
     279         data_out=shared_ptr<CDataOutput>(new CNc4DataOutput(oss.str(), false, fileComm, multifile, isCollective)); 
    267280         isOpen=true ; 
    268281 
    269282         data_out->writeFile(CFile::get(this)); 
     283         std::vector<CField*>::iterator it, end = this->enabledFields.end(); 
    270284         for (it = this->enabledFields.begin() ;it != end; it++) 
    271285         { 
     
    288302     delete lastSync ; 
    289303     delete lastSplit ; 
    290      if (!AllDomainEmpty ||  type==type_attr::one_file) 
     304     if (!allDomainEmpty) 
    291305       if (isOpen)  
    292306       { 
    293307         this->data_out->closeFile(); 
    294308       } 
     309      if (fileComm != MPI_COMM_NULL) MPI_Comm_free(&fileComm) ; 
    295310   } 
    296311   //---------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.