Changeset 379 for XIOS/trunk/src/node/file.cpp
- Timestamp:
- 10/22/12 13:47:08 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/file.cpp
r375 r379 15 15 #include "xmlioserver_spl.hpp" 16 16 #include "context_client.hpp" 17 #include <mpi.h> 17 18 18 19 namespace xios { … … 22 23 CFile::CFile(void) 23 24 : CObjectTemplate<CFile>(), CFileAttributes() 24 , vFieldGroup(), data_out(), enabledFields() 25 , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 25 26 { setVirtualFieldGroup() ;} 26 27 27 28 CFile::CFile(const StdString & id) 28 29 : CObjectTemplate<CFile>(id), CFileAttributes() 29 , vFieldGroup(), data_out(), enabledFields() 30 , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 30 31 { setVirtualFieldGroup() ;} 31 32 … … 146 147 CContext* context = CContext::getCurrent() ; 147 148 CDate& currentDate=context->calendar->getCurrentDate() ; 148 149 CContextServer* server=context->server ; 150 149 151 if (! sync_freq.isEmpty()) syncFreq = CDuration::FromString(sync_freq.getValue()); 150 152 if (! split_freq.isEmpty()) splitFreq = CDuration::FromString(split_freq.getValue()); … … 153 155 lastSplit=new CDate(currentDate) ; 154 156 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 155 176 } 156 177 … … 202 223 { 203 224 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) 219 228 { 220 229 StdString filename = (!name.isEmpty()) ? name.getValue() : getId(); 221 230 StdOStringStream oss; 222 // if (! output_dir.isEmpty()) oss << output_dir.getValue();223 231 oss << filename; 224 232 if (!name_suffix.isEmpty()) oss << name_suffix.getValue(); 225 // if (!split_freq.isEmpty()) oss<<"-["<<currentDate.toString()<<"]" ;226 233 if (!split_freq.isEmpty()) oss<<"_"<<lastSplit->getStryyyymmdd()<<"-"<< (*lastSplit+(splitFreq-1*Second)).getStryyyymmdd(); 227 234 bool multifile=true ; … … 230 237 if (type==type_attr::one_file) multifile=false ; 231 238 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 235 240 } 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 239 248 if (multifile) 240 249 { 250 int commSize, commRank ; 251 MPI_Comm_size(fileComm,&commSize) ; 252 MPI_Comm_rank(fileComm,&commRank) ; 253 241 254 if (server->intraCommSize > 1) 242 255 { 243 256 oss << "_" ; 244 int width=0 ; int n= server->intraCommSize-1 ;257 int width=0 ; int n=commSize-1 ; 245 258 while(n != 0) { n=n/10 ; width++ ;} 246 259 oss.width(width) ; 247 260 oss.fill('0') ; 248 oss<<right<< server->intraCommRank;261 oss<<right<< commRank; 249 262 } 250 263 } … … 264 277 } 265 278 } 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)); 267 280 isOpen=true ; 268 281 269 282 data_out->writeFile(CFile::get(this)); 283 std::vector<CField*>::iterator it, end = this->enabledFields.end(); 270 284 for (it = this->enabledFields.begin() ;it != end; it++) 271 285 { … … 288 302 delete lastSync ; 289 303 delete lastSplit ; 290 if (! AllDomainEmpty || type==type_attr::one_file)304 if (!allDomainEmpty) 291 305 if (isOpen) 292 306 { 293 307 this->data_out->closeFile(); 294 308 } 309 if (fileComm != MPI_COMM_NULL) MPI_Comm_free(&fileComm) ; 295 310 } 296 311 //----------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.