Changeset 651 for XIOS/trunk/src/node/file.cpp
- Timestamp:
- 07/24/15 16:40:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/node/file.cpp
r645 r651 25 25 , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 26 26 { 27 setVirtualFieldGroup() 28 setVirtualVariableGroup() 27 setVirtualFieldGroup(); 28 setVirtualVariableGroup(); 29 29 } 30 30 … … 33 33 , vFieldGroup(), data_out(), enabledFields(), fileComm(MPI_COMM_NULL) 34 34 { 35 setVirtualFieldGroup() 36 setVirtualVariableGroup() 35 setVirtualFieldGroup(); 36 setVirtualVariableGroup(); 37 37 } 38 38 … … 129 129 std::vector<CField*> newEnabledFields; 130 130 131 for ( it = this->enabledFields.begin() 131 for ( it = this->enabledFields.begin(); it != this->enabledFields.end(); it++ ) 132 132 { 133 133 if (!(*it)->enabled.isEmpty()) // Si l'attribut 'enabled' est défini ... … … 138 138 else // Si l'attribut 'enabled' n'est pas défini ... 139 139 { 140 if (!default_enabled) continue 140 if (!default_enabled) continue; 141 141 // { it--; this->enabledFields.erase(it+1); continue; } 142 142 } … … 144 144 if (!(*it)->level.isEmpty()) // Si l'attribut 'level' est défini ... 145 145 { 146 if ((*it)->level.getValue() > _outputlevel) continue 146 if ((*it)->level.getValue() > _outputlevel) continue; 147 147 // { it--; this->enabledFields.erase(it+1); continue; } 148 148 } 149 149 else // Si l'attribut 'level' n'est pas défini ... 150 150 { 151 if (default_level > _outputlevel) continue 151 if (default_level > _outputlevel) continue; 152 152 // { it--; this->enabledFields.erase(it+1); continue; } 153 153 } 154 154 155 // CField* field_tmp=(*it).get() 156 // shared_ptr<CField> sptfield=*it 157 // field_tmp->refObject.push_back(sptfield) 158 newEnabledFields.push_back(*it) 155 // CField* field_tmp=(*it).get(); 156 // shared_ptr<CField> sptfield=*it; 157 // field_tmp->refObject.push_back(sptfield); 158 newEnabledFields.push_back(*it); 159 159 // Le champ est finalement actif, on y ajoute sa propre reference. 160 160 // (*it)->refObject.push_back(*it); … … 164 164 // A faire, ajouter les references intermediaires... 165 165 } 166 enabledFields =newEnabledFields;166 enabledFields = newEnabledFields; 167 167 168 168 return (this->enabledFields); … … 198 198 bool CFile::isSyncTime(void) 199 199 { 200 CContext* context = CContext::getCurrent() 201 const CDate& currentDate = context->calendar->getCurrentDate() 200 CContext* context = CContext::getCurrent(); 201 const CDate& currentDate = context->calendar->getCurrentDate(); 202 202 if (!sync_freq.isEmpty()) 203 203 { 204 if ( *lastSync + sync_freq.getValue() < currentDate)204 if (lastSync + sync_freq.getValue() < currentDate) 205 205 { 206 *lastSync=currentDate;207 return true 206 lastSync = currentDate; 207 return true; 208 208 } 209 209 } 210 return false 210 return false; 211 211 } 212 212 … … 214 214 void CFile::initFile(void) 215 215 { 216 CContext* context = CContext::getCurrent() 217 const CDate& currentDate = context->calendar->getCurrentDate() 218 CContextServer* server =context->server;219 220 lastSync =new CDate(currentDate);221 lastSplit =new CDate(currentDate);222 isOpen =false;223 224 allDomainEmpty =true;216 CContext* context = CContext::getCurrent(); 217 const CDate& currentDate = context->calendar->getCurrentDate(); 218 CContextServer* server = context->server; 219 220 lastSync = currentDate; 221 lastSplit = currentDate; 222 isOpen = false; 223 224 allDomainEmpty = true; 225 225 226 226 set<CAxis*> setAxis; … … 243 243 244 244 // create sub communicator for file 245 int color=allDomainEmpty?0:1 ; 246 MPI_Comm_split(server->intraComm,color,server->intraCommRank,&fileComm) ; 247 if (allDomainEmpty) MPI_Comm_free(&fileComm) ; 248 // 249 245 int color = allDomainEmpty ? 0 : 1; 246 MPI_Comm_split(server->intraComm, color, server->intraCommRank, &fileComm); 247 if (allDomainEmpty) MPI_Comm_free(&fileComm); 250 248 } 251 249 … … 273 271 bool CFile::checkSync(void) 274 272 { 275 CContext* context = CContext::getCurrent() 276 const CDate& currentDate = context->calendar->getCurrentDate() 273 CContext* context = CContext::getCurrent(); 274 const CDate& currentDate = context->calendar->getCurrentDate(); 277 275 if (!sync_freq.isEmpty()) 278 276 { 279 if ( *lastSync + sync_freq.getValue() <= currentDate)277 if (lastSync + sync_freq.getValue() <= currentDate) 280 278 { 281 *lastSync=currentDate;282 data_out->syncFile() 283 return true 279 lastSync = currentDate; 280 data_out->syncFile(); 281 return true; 284 282 } 285 283 } 286 return false 284 return false; 287 285 } 288 286 … … 295 293 bool CFile::checkSplit(void) 296 294 { 297 CContext* context = CContext::getCurrent() 298 const CDate& currentDate = context->calendar->getCurrentDate() 295 CContext* context = CContext::getCurrent(); 296 const CDate& currentDate = context->calendar->getCurrentDate(); 299 297 if (!split_freq.isEmpty()) 300 298 { 301 if (currentDate > *lastSplit + split_freq.getValue())299 if (currentDate > lastSplit + split_freq.getValue()) 302 300 { 303 *lastSplit = *lastSplit + split_freq.getValue();301 lastSplit = lastSplit + split_freq.getValue(); 304 302 std::vector<CField*>::iterator it, end = this->enabledFields.end(); 305 303 for (it = this->enabledFields.begin(); it != end; it++) … … 309 307 } 310 308 if (mode.isEmpty() || mode.getValue() == mode_attr::write) 311 createHeader() 309 createHeader(); 312 310 else 313 311 openInReadMode(); 314 return true 312 return true; 315 313 } 316 314 } 317 return false 315 return false; 318 316 } 319 317 … … 324 322 void CFile::createHeader(void) 325 323 { 326 CContext* context = CContext::getCurrent() 327 CContextServer* server =context->server;324 CContext* context = CContext::getCurrent(); 325 CContextServer* server = context->server; 328 326 329 327 if (!allDomainEmpty) … … 336 334 if (!split_freq.isEmpty()) 337 335 { 338 string splitFormat 336 string splitFormat; 339 337 if (split_freq_format.isEmpty()) 340 338 { … … 346 344 else splitFormat = "%y"; 347 345 } 348 else splitFormat =split_freq_format;349 oss << "_" << lastSplit ->getStr(splitFormat)350 << "-" << ( *lastSplit + split_freq.getValue() - 1 * Second).getStr(splitFormat);346 else splitFormat = split_freq_format; 347 oss << "_" << lastSplit.getStr(splitFormat) 348 << "-" << (lastSplit + split_freq.getValue() - 1 * Second).getStr(splitFormat); 351 349 } 352 350 … … 355 353 bool useClassicFormat = !format.isEmpty() && format == format_attr::netcdf4_classic; 356 354 357 bool multifile =true;355 bool multifile = true; 358 356 if (!type.isEmpty()) 359 357 { 360 if (type ==type_attr::one_file) multifile=false;361 else if (type ==type_attr::multiple_file) multifile=true;358 if (type == type_attr::one_file) multifile = false; 359 else if (type == type_attr::multiple_file) multifile = true; 362 360 363 361 } … … 365 363 if (!multifile) 366 364 { 367 info(0) <<"!!! Warning -> Using non parallel version of netcdf, switching in multiple_file mode for file : "<<filename<<" ..."<<endl;368 multifile =true;365 info(0) << "!!! Warning -> Using non parallel version of netcdf, switching in multiple_file mode for file : " << filename << " ..." << endl; 366 multifile = true; 369 367 } 370 368 #endif 371 369 if (multifile) 372 370 { 373 int commSize, commRank 374 MPI_Comm_size(fileComm, &commSize);375 MPI_Comm_rank(fileComm, &commRank);371 int commSize, commRank; 372 MPI_Comm_size(fileComm, &commSize); 373 MPI_Comm_rank(fileComm, &commRank); 376 374 377 375 if (server->intraCommSize > 1) 378 376 { 379 oss << "_" 380 int width=0 ; int n=commSize-1;381 while (n != 0) { n=n/10 ; width++;}377 oss << "_" ; 378 int width=0; int n = commSize-1; 379 while (n != 0) { n = n / 10; width++;} 382 380 if (!min_digits.isEmpty()) 383 if (width <min_digits) width=min_digits;384 oss.width(width) 385 oss.fill('0') 386 oss <<right<< commRank;381 if (width < min_digits) width = min_digits; 382 oss.width(width); 383 oss.fill('0'); 384 oss << right << commRank; 387 385 } 388 386 } … … 416 414 } 417 415 418 vector<CVariable*> listVars = getAllVariables() 416 vector<CVariable*> listVars = getAllVariables(); 419 417 for (vector<CVariable*>::iterator it = listVars.begin(); it != listVars.end(); it++) 420 418 this->data_out->writeAttribute(*it); … … 431 429 { 432 430 CContext* context = CContext::getCurrent(); 433 CContextServer* server =context->server;431 CContextServer* server = context->server; 434 432 435 433 if (!allDomainEmpty) … … 452 450 else splitFormat = "%y"; 453 451 } 454 else splitFormat =split_freq_format;455 oss << "_" << lastSplit ->getStr(splitFormat)456 << "-" << ( *lastSplit + split_freq.getValue() - 1 * Second).getStr(splitFormat);452 else splitFormat = split_freq_format; 453 oss << "_" << lastSplit.getStr(splitFormat) 454 << "-" << (lastSplit + split_freq.getValue() - 1 * Second).getStr(splitFormat); 457 455 } 458 456 … … 478 476 if (server->intraCommSize > 1) 479 477 { 480 oss << "_" 478 oss << "_"; 481 479 int width = 0, n = commSize - 1; 482 480 while (n != 0) { n = n / 10; width++; } … … 502 500 void CFile::close(void) 503 501 { 504 delete lastSync ;505 delete lastSplit ;506 502 if (!allDomainEmpty) 507 503 if (isOpen) … … 512 508 this->data_in->closeFile(); 513 509 } 514 if (fileComm != MPI_COMM_NULL) MPI_Comm_free(&fileComm) 510 if (fileComm != MPI_COMM_NULL) MPI_Comm_free(&fileComm); 515 511 } 516 512 //---------------------------------------------------------------- … … 530 526 if (node.getElementName()=="field" || node.getElementName()=="field_group") this->getVirtualFieldGroup()->parseChild(node); 531 527 else if (node.getElementName()=="variable" || node.getElementName()=="variable_group") this->getVirtualVariableGroup()->parseChild(node); 532 } while (node.goToNextElement()) 528 } while (node.goToNextElement()); 533 529 node.goToParentElement(); 534 530 } … … 649 645 CField* CFile::addField(const string& id) 650 646 { 651 return vFieldGroup->createChild(id) 647 return vFieldGroup->createChild(id); 652 648 } 653 649 … … 661 657 CFieldGroup* CFile::addFieldGroup(const string& id) 662 658 { 663 return vFieldGroup->createChildGroup(id) 659 return vFieldGroup->createChildGroup(id); 664 660 } 665 661 … … 676 672 CVariable* CFile::addVariable(const string& id) 677 673 { 678 return vVariableGroup->createChild(id) 674 return vVariableGroup->createChild(id); 679 675 } 680 676 … … 688 684 CVariableGroup* CFile::addVariableGroup(const string& id) 689 685 { 690 return vVariableGroup->createChildGroup(id) 686 return vVariableGroup->createChildGroup(id); 691 687 } 692 688 … … 697 693 void CFile::sendAddField(const string& id) 698 694 { 699 CContext* context =CContext::getCurrent();695 CContext* context = CContext::getCurrent(); 700 696 701 697 if (! context->hasServer ) 702 698 { 703 CContextClient* client =context->client;704 705 CEventClient event(this->getType(),EVENT_ID_ADD_FIELD) 699 CContextClient* client = context->client; 700 701 CEventClient event(this->getType(),EVENT_ID_ADD_FIELD); 706 702 if (client->isServerLeader()) 707 703 { 708 CMessage msg 709 msg <<this->getId();710 msg <<id;704 CMessage msg; 705 msg << this->getId(); 706 msg << id; 711 707 const std::list<int>& ranks = client->getRanksServerLeader(); 712 708 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 713 709 event.push(*itRank,1,msg); 714 client->sendEvent(event) 710 client->sendEvent(event); 715 711 } 716 else client->sendEvent(event) 712 else client->sendEvent(event); 717 713 } 718 714 … … 725 721 void CFile::sendAddFieldGroup(const string& id) 726 722 { 727 CContext* context =CContext::getCurrent();723 CContext* context = CContext::getCurrent(); 728 724 if (! context->hasServer ) 729 725 { 730 CContextClient* client =context->client;731 732 CEventClient event(this->getType(),EVENT_ID_ADD_FIELD_GROUP) 726 CContextClient* client = context->client; 727 728 CEventClient event(this->getType(),EVENT_ID_ADD_FIELD_GROUP); 733 729 if (client->isServerLeader()) 734 730 { 735 CMessage msg 736 msg <<this->getId();737 msg <<id;731 CMessage msg; 732 msg << this->getId(); 733 msg << id; 738 734 const std::list<int>& ranks = client->getRanksServerLeader(); 739 735 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 740 736 event.push(*itRank,1,msg); 741 client->sendEvent(event) 737 client->sendEvent(event); 742 738 } 743 else client->sendEvent(event) 739 else client->sendEvent(event); 744 740 } 745 741 … … 753 749 { 754 750 755 CBufferIn* buffer =event.subEvents.begin()->buffer;751 CBufferIn* buffer = event.subEvents.begin()->buffer; 756 752 string id; 757 *buffer>>id 758 get(id)->recvAddField(*buffer) 753 *buffer>>id; 754 get(id)->recvAddField(*buffer); 759 755 } 760 756 … … 765 761 void CFile::recvAddField(CBufferIn& buffer) 766 762 { 767 string id 768 buffer>>id 769 addField(id) 763 string id; 764 buffer>>id; 765 addField(id); 770 766 } 771 767 … … 777 773 { 778 774 779 CBufferIn* buffer =event.subEvents.begin()->buffer;775 CBufferIn* buffer = event.subEvents.begin()->buffer; 780 776 string id; 781 *buffer>>id 782 get(id)->recvAddFieldGroup(*buffer) 777 *buffer>>id; 778 get(id)->recvAddFieldGroup(*buffer); 783 779 } 784 780 … … 789 785 void CFile::recvAddFieldGroup(CBufferIn& buffer) 790 786 { 791 string id 792 buffer>>id 793 addFieldGroup(id) 787 string id; 788 buffer>>id; 789 addFieldGroup(id); 794 790 } 795 791 … … 828 824 void CFile::sendAddVariable(const string& id) 829 825 { 830 CContext* context =CContext::getCurrent();826 CContext* context = CContext::getCurrent(); 831 827 832 828 if (! context->hasServer ) 833 829 { 834 CContextClient* client =context->client;835 836 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE) 830 CContextClient* client = context->client; 831 832 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE); 837 833 if (client->isServerLeader()) 838 834 { 839 CMessage msg 840 msg <<this->getId();841 msg <<id;835 CMessage msg; 836 msg << this->getId(); 837 msg << id; 842 838 const std::list<int>& ranks = client->getRanksServerLeader(); 843 839 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 844 840 event.push(*itRank,1,msg); 845 client->sendEvent(event) 841 client->sendEvent(event); 846 842 } 847 else client->sendEvent(event) 843 else client->sendEvent(event); 848 844 } 849 845 … … 856 852 void CFile::sendAddVariableGroup(const string& id) 857 853 { 858 CContext* context =CContext::getCurrent();854 CContext* context = CContext::getCurrent(); 859 855 if (! context->hasServer ) 860 856 { 861 CContextClient* client =context->client;862 863 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP) 857 CContextClient* client = context->client; 858 859 CEventClient event(this->getType(),EVENT_ID_ADD_VARIABLE_GROUP); 864 860 if (client->isServerLeader()) 865 861 { 866 CMessage msg 867 msg <<this->getId();868 msg <<id;862 CMessage msg; 863 msg << this->getId(); 864 msg << id; 869 865 const std::list<int>& ranks = client->getRanksServerLeader(); 870 866 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 871 867 event.push(*itRank,1,msg); 872 client->sendEvent(event) 868 client->sendEvent(event); 873 869 } 874 else client->sendEvent(event) 870 else client->sendEvent(event); 875 871 } 876 872 … … 884 880 { 885 881 886 CBufferIn* buffer =event.subEvents.begin()->buffer;882 CBufferIn* buffer = event.subEvents.begin()->buffer; 887 883 string id; 888 *buffer>>id 889 get(id)->recvAddVariable(*buffer) 884 *buffer>>id; 885 get(id)->recvAddVariable(*buffer); 890 886 } 891 887 … … 896 892 void CFile::recvAddVariable(CBufferIn& buffer) 897 893 { 898 string id 899 buffer>>id 900 addVariable(id) 894 string id; 895 buffer>>id; 896 addVariable(id); 901 897 } 902 898 … … 908 904 { 909 905 910 CBufferIn* buffer =event.subEvents.begin()->buffer;906 CBufferIn* buffer = event.subEvents.begin()->buffer; 911 907 string id; 912 *buffer>>id 913 get(id)->recvAddVariableGroup(*buffer) 908 *buffer>>id; 909 get(id)->recvAddVariableGroup(*buffer); 914 910 } 915 911 … … 920 916 void CFile::recvAddVariableGroup(CBufferIn& buffer) 921 917 { 922 string id 923 buffer>>id 924 addVariableGroup(id) 918 string id; 919 buffer>>id; 920 addVariableGroup(id); 925 921 } 926 922 … … 955 951 bool CFile::dispatchEvent(CEventServer& event) 956 952 { 957 if (SuperClass::dispatchEvent(event)) return true 953 if (SuperClass::dispatchEvent(event)) return true; 958 954 else 959 955 { … … 961 957 { 962 958 case EVENT_ID_ADD_FIELD : 963 recvAddField(event) 964 return true 965 break 959 recvAddField(event); 960 return true; 961 break; 966 962 967 963 case EVENT_ID_ADD_FIELD_GROUP : 968 recvAddFieldGroup(event) 969 return true 970 break 964 recvAddFieldGroup(event); 965 return true; 966 break; 971 967 972 968 case EVENT_ID_ADD_VARIABLE : 973 recvAddVariable(event) 974 return true 975 break 969 recvAddVariable(event); 970 return true; 971 break; 976 972 977 973 case EVENT_ID_ADD_VARIABLE_GROUP : 978 recvAddVariableGroup(event) 979 return true 980 break 974 recvAddVariableGroup(event); 975 return true; 976 break; 981 977 default : 982 ERROR("bool CFile::dispatchEvent(CEventServer& event)", << "Unknown Event");983 return false 978 ERROR("bool CFile::dispatchEvent(CEventServer& event)", << "Unknown Event"); 979 return false; 984 980 } 985 981 }
Note: See TracChangeset
for help on using the changeset viewer.