- Timestamp:
- 01/25/17 16:25:17 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_yushan/src/transformation/domain_algorithm_interpolate.cpp
r1014 r1037 48 48 49 49 CDomainAlgorithmInterpolate::CDomainAlgorithmInterpolate(CDomain* domainDestination, CDomain* domainSource, CInterpolateDomain* interpDomain) 50 : CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false), readFromFile_(false) 51 { 52 CContext* context = CContext::getCurrent(); 50 : CDomainAlgorithmTransformation(domainDestination, domainSource), interpDomain_(interpDomain), writeToFile_(false) 51 { 53 52 interpDomain_->checkValid(domainSource); 54 fileToReadWrite_ = "xios_interpolation_weights_"; 55 56 if (interpDomain_->weight_filename.isEmpty()) 57 { 58 fileToReadWrite_ += context->getId() + "_" + 59 domainSource->getDomainOutputName() + "_" + 60 domainDestination->getDomainOutputName() + ".nc"; 61 } 62 else 63 fileToReadWrite_ = interpDomain_->weight_filename; 64 65 ifstream f(fileToReadWrite_.c_str()); 66 switch (interpDomain_->mode) 67 { 68 case CInterpolateDomain::mode_attr::read: 69 readFromFile_ = true; 70 break; 71 case CInterpolateDomain::mode_attr::compute: 72 readFromFile_ = false; 73 break; 74 case CInterpolateDomain::mode_attr::read_or_compute: 75 if (!f.good()) 76 readFromFile_ = false; 77 else 78 readFromFile_ = true; 79 break; 80 default: 81 break; 82 } 83 84 writeToFile_ = interpDomain_->write_weight; 85 53 if ((CInterpolateDomain::mode_attr::write == interpDomain_->mode) && 54 (!interpDomain_->file.isEmpty())) 55 writeToFile_ = true; 86 56 } 87 57 … … 384 354 } 385 355 386 if (writeToFile_ && !readFromFile_)356 if (writeToFile_) 387 357 writeRemapInfo(interpMapValue); 388 358 exchangeRemapInfo(interpMapValue); … … 469 439 void CDomainAlgorithmInterpolate::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 470 440 { 471 if ( readFromFile_ && !writeToFile_)441 if (CInterpolateDomain::mode_attr::read == interpDomain_->mode) 472 442 readRemapInfo(); 473 443 else … … 478 448 479 449 void CDomainAlgorithmInterpolate::writeRemapInfo(std::map<int,std::vector<std::pair<int,double> > >& interpMapValue) 480 { 481 writeInterpolationInfo(fileToReadWrite_, interpMapValue); 450 { 451 std::string filename = interpDomain_->file.getValue(); 452 writeInterpolationInfo(filename, interpMapValue); 482 453 } 483 454 484 455 void CDomainAlgorithmInterpolate::readRemapInfo() 485 { 456 { 457 std::string filename = interpDomain_->file.getValue(); 486 458 std::map<int,std::vector<std::pair<int,double> > > interpMapValue; 487 readInterpolationInfo(file ToReadWrite_, interpMapValue);459 readInterpolationInfo(filename, interpMapValue); 488 460 489 461 exchangeRemapInfo(interpMapValue); … … 636 608 int countBuff = 0; 637 609 MPI_Get_count(&recvStatus, MPI_INT, &countBuff); 610 #ifdef _usingMPI 638 611 clientSrcRank = recvStatus.MPI_SOURCE; 639 612 #elif _usingEP 613 clientSrcRank = recvStatus.ep_src; 614 #endif 640 615 MPI_Recv((recvIndexSrcBuff + receivedSize), 641 616 recvBuffSize, … … 681 656 const StdSize size) 682 657 { 683 returnCONetCDF4::addDimension(name, size);658 CONetCDF4::addDimension(name, size); 684 659 } 685 660 … … 687 662 const std::vector<StdString>& dim) 688 663 { 689 return CONetCDF4::addVariable(name, type, dim); 690 } 691 692 void CDomainAlgorithmInterpolate::WriteNetCdf::endDefinition() 693 { 694 CONetCDF4::definition_end(); 664 CONetCDF4::addVariable(name, type, dim); 695 665 } 696 666 … … 756 726 MPI_Scan(&localNbWeight, &startIndex, 1, MPI_LONG, MPI_SUM, client->intraComm); 757 727 758 if (0 == globalNbWeight)759 {760 info << "There is no interpolation weights calculated between "761 << "domain source: " << domainSrc_->getDomainOutputName()762 << " and domain destination: " << domainDest_->getDomainOutputName()763 << std::endl;764 return;765 }766 767 728 std::vector<StdSize> start(1, startIndex - localNbWeight); 768 729 std::vector<StdSize> count(1, localNbWeight); 769 770 WriteNetCdf netCdfWriter(filename, client->intraComm); 730 731 WriteNetCdf netCdfWriter(filename, client->intraComm); 732 733 // netCdfWriter = CONetCDF4(filename, false, false, true, client->intraComm, false); 771 734 772 735 // Define some dimensions … … 782 745 netCdfWriter.addVariableWrite("weight", NC_DOUBLE, dims); 783 746 784 // End of definition785 netCdfWriter.endDefinition();786 787 747 // // Write variables 788 if (0 != localNbWeight) 789 { 790 netCdfWriter.writeDataIndex(src_idx, "src_idx", false, 0, &start, &count); 791 netCdfWriter.writeDataIndex(dst_idx, "dst_idx", false, 0, &start, &count); 792 netCdfWriter.writeDataIndex(weights, "weight", false, 0, &start, &count); 793 } 748 netCdfWriter.writeDataIndex(src_idx, "src_idx", true, 0, &start, &count); 749 netCdfWriter.writeDataIndex(dst_idx, "dst_idx", true, 0, &start, &count); 750 netCdfWriter.writeDataIndex(weights, "weight", true, 0, &start, &count); 794 751 795 752 netCdfWriter.closeFile();
Note: See TracChangeset
for help on using the changeset viewer.