Changeset 379 for XIOS


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

Location:
XIOS/trunk/src
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/data_output.hpp

    r347 r379  
    88#include "field.hpp" 
    99 
    10 #include <mpi.h> 
    11 #define MPI_INCLUDED 
    12 #include <netcdf.h> 
    1310 
    1411namespace xios 
  • XIOS/trunk/src/node/field.cpp

    r369 r379  
    187187  void CField::writeField(void) 
    188188  { 
    189 //    if (! grid->domain->isEmpty() || getRelFile()->type.getValue()=="one_file") 
    190     if (! grid->domain->isEmpty() || getRelFile()->type == CFile::type_attr::one_file) 
    191     { 
    192       getRelFile()->checkFile(); 
    193       this->incrementNStep(); 
    194       getRelFile()->getDataOutput()->writeFieldData(CField::get(this)); 
    195     } 
     189    if (! getRelFile()->allDomainEmpty ) 
     190      if (! grid->domain->isEmpty() || getRelFile()->type == CFile::type_attr::one_file) 
     191      { 
     192        getRelFile()->checkFile(); 
     193        this->incrementNStep(); 
     194        getRelFile()->getDataOutput()->writeFieldData(CField::get(this)); 
     195      } 
    196196  } 
    197197   //---------------------------------------------------------------- 
     
    411411         const CDuration toffset = this->freq_operation - freq_offset_ - context->getCalendar()->getTimeStep();  
    412412         *this->last_operation   = *this->last_operation - toffset;   
    413          cout<<operation<<endl ; 
    414           
     413           
    415414#define DECLARE_FUNCTOR(MType, mtype)              \ 
    416415   if  (operation.getValue().compare(#mtype) == 0) \ 
  • 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   //---------------------------------------------------------------- 
  • XIOS/trunk/src/node/file.hpp

    r369 r379  
    1010#include "attribute_enum.hpp" 
    1111#include "attribute_enum_impl.hpp" 
     12#include <mpi.h> 
    1213 
    1314 
     
    9394         static ENodeType GetType(void); 
    9495          
    95          bool AllDomainEmpty ; 
     96         bool allDomainEmpty ; 
    9697         CField* addField(const string& id="") ; 
    9798         CFieldGroup* addFieldGroup(const string& id="") ; 
     
    115116         int nbDomain ; 
    116117         bool isOpen ; 
     118         MPI_Comm fileComm ; 
    117119      private : 
    118120 
  • XIOS/trunk/src/output/nc4_data_output.cpp

    r369 r379  
    2727 
    2828      CNc4DataOutput::CNc4DataOutput 
    29          (const StdString & filename, bool exist, MPI_Comm comm_server,bool multifile, bool isCollective) 
     29         (const StdString & filename, bool exist, MPI_Comm comm_file,bool multifile, bool isCollective) 
    3030            : SuperClass() 
    31             , SuperClassWriter(filename, exist, &comm_server,multifile) 
    32             , comm_server(comm_server) 
     31            , SuperClassWriter(filename, exist, &comm_file,multifile) 
     32            , comm_file(comm_file) 
    3333            , filename(filename) 
    3434            , isCollective(isCollective) 
  • XIOS/trunk/src/output/nc4_data_output.hpp

    r369 r379  
    2525               (const StdString & filename, bool exist); 
    2626            CNc4DataOutput 
    27                (const StdString & filename, bool exist, MPI_Comm comm_server, bool multifile, bool isCollective=true); 
     27               (const StdString & filename, bool exist, MPI_Comm comm_file, bool multifile, bool isCollective=true); 
    2828 
    2929            CNc4DataOutput(const CNc4DataOutput & dataoutput);       // Not implemented. 
     
    8888 
    8989            /// Propriétés privées /// 
    90             MPI_Comm comm_server; 
     90            MPI_Comm comm_file; 
    9191            const StdString filename; 
    9292 
  • XIOS/trunk/src/output/onetcdf4.cpp

    r369 r379  
    11#include "onetcdf4.hpp" 
    22#include "group_template.hpp" 
     3#include <mpi.h> 
     4#include "netcdf.hpp" 
    35 
    46namespace xios 
     
    3234            if (comm != NULL) 
    3335            { 
    34                if (!multifile) CheckError(nc_create_par(filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp)); 
     36               if (!multifile) CheckError(xios::nc_create_par(filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp)); 
    3537               else CheckError(nc_create(filename.c_str(), NC_NETCDF4, &this->ncidp)); 
    3638            } 
     
    4143            if (comm != NULL) 
    4244            { 
    43                if (!multifile) CheckError(nc_open_par(filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp)); 
     45               if (!multifile) CheckError(xios::nc_open_par(filename.c_str(), NC_NETCDF4|NC_MPIIO, *comm, MPI_INFO_NULL, &this->ncidp)); 
    4446               else CheckError(nc_open(filename.c_str(), NC_NETCDF4, &this->ncidp)); 
    4547            } 
  • XIOS/trunk/src/output/onetcdf4.hpp

    r369 r379  
    77#include "data_output.hpp" 
    88#include "array_new.hpp" 
    9  
    109#include <mpi.h> 
    11 #define MPI_INCLUDED 
    12 #include <netcdf.h> 
    13 #ifdef NETCDF_PAR_HEADER 
    14 extern "C" { 
    15 #include <netcdf_par.h> 
    16 } 
    17 #endif 
    18  
     10#include "netcdf.hpp" 
    1911 
    2012#ifndef UNLIMITED_DIM 
Note: See TracChangeset for help on using the changeset viewer.