Changeset 1037 for XIOS/dev/branch_yushan/src/transformation
- Timestamp:
- 01/25/17 16:25:17 (7 years ago)
- Location:
- XIOS/dev/branch_yushan/src/transformation
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_yushan/src/transformation/Functions/average_reduction.cpp
r1018 r1037 3 3 \author Ha NGUYEN 4 4 \since 8 Sep 2016 5 \date 9 Jan 20175 \date 8 Sep 2016 6 6 7 7 \brief average reduction 8 8 */ 9 9 #include "average_reduction.hpp" 10 #include "utils.hpp"11 10 12 11 namespace xios { … … 30 29 const double* dataInput, 31 30 CArray<double,1>& dataOut, 32 std::vector<bool>& flagInitial, 33 const double& defaultValue) 31 std::vector<bool>& flagInitial) 34 32 { 35 33 if (resetWeight_) { weights_.resize(flagInitial.size()); weights_ = 1.0; resetWeight_ = false; } 36 bool hasMissingValue = NumTraits<double>::isnan(defaultValue);37 34 38 if (hasMissingValue) 35 int nbLocalIndex = localIndex.size(); 36 int currentlocalIndex = 0; 37 double currentWeight = 0.0; 38 for (int idx = 0; idx < nbLocalIndex; ++idx) 39 39 { 40 int nbLocalIndex = localIndex.size();41 int currentlocalIndex = 0;42 double currentWeight = 0.0; 43 for (int idx = 0; idx < nbLocalIndex; ++idx)40 currentlocalIndex = localIndex[idx].first; 41 currentWeight = localIndex[idx].second; 42 43 if (flagInitial[currentlocalIndex]) 44 44 { 45 currentlocalIndex = localIndex[idx].first; 46 currentWeight = localIndex[idx].second; 47 if (!NumTraits<double>::isnan(*(dataInput + idx))) 48 { 49 if (flagInitial[currentlocalIndex]) 50 { 51 dataOut(currentlocalIndex) = *(dataInput + idx); 52 flagInitial[currentlocalIndex] = false; 53 } 54 else 55 { 56 dataOut(currentlocalIndex) += *(dataInput + idx); 57 weights_(currentlocalIndex) += 1.0; 58 } 59 } 45 dataOut(currentlocalIndex) = *(dataInput + idx); 46 flagInitial[currentlocalIndex] = false; 60 47 } 61 } 62 else 63 { 64 int nbLocalIndex = localIndex.size(); 65 int currentlocalIndex = 0; 66 double currentWeight = 0.0; 67 for (int idx = 0; idx < nbLocalIndex; ++idx) 48 else 68 49 { 69 currentlocalIndex = localIndex[idx].first; 70 currentWeight = localIndex[idx].second; 71 72 if (flagInitial[currentlocalIndex]) 73 { 74 dataOut(currentlocalIndex) = *(dataInput + idx); 75 flagInitial[currentlocalIndex] = false; 76 } 77 else 78 { 79 dataOut(currentlocalIndex) += *(dataInput + idx); 80 weights_(currentlocalIndex) += 1.0; 81 } 50 dataOut(currentlocalIndex) += *(dataInput + idx); 51 weights_(currentlocalIndex) += 1.0; 82 52 } 83 53 } -
XIOS/dev/branch_yushan/src/transformation/Functions/average_reduction.hpp
r1018 r1037 26 26 const double* dataInput, 27 27 CArray<double,1>& dataOut, 28 std::vector<bool>& flagInitial, 29 const double& defaultValue); 28 std::vector<bool>& flagInitial); 30 29 31 30 virtual void updateData(CArray<double,1>& dataOut); -
XIOS/dev/branch_yushan/src/transformation/Functions/extract.cpp
r1018 r1037 29 29 const double* dataInput, 30 30 CArray<double,1>& dataOut, 31 std::vector<bool>& flagInitial, 32 const double& defaultValue) 31 std::vector<bool>& flagInitial) 33 32 { 34 33 int nbLocalIndex = localIndex.size(); -
XIOS/dev/branch_yushan/src/transformation/Functions/extract.hpp
r1018 r1037 26 26 const double* dataInput, 27 27 CArray<double,1>& dataOut, 28 std::vector<bool>& flagInitial, 29 const double& defaultValue); 28 std::vector<bool>& flagInitial); 30 29 31 30 virtual ~CExtractReductionAlgorithm() {} -
XIOS/dev/branch_yushan/src/transformation/Functions/max_reduction.cpp
r1018 r1037 8 8 */ 9 9 #include "max_reduction.hpp" 10 #include "utils.hpp"11 10 12 11 namespace xios { … … 30 29 const double* dataInput, 31 30 CArray<double,1>& dataOut, 32 std::vector<bool>& flagInitial, 33 const double& defaultValue) 31 std::vector<bool>& flagInitial) 34 32 { 35 bool hasMissingValue = NumTraits<double>::isnan(defaultValue); 36 37 if (hasMissingValue) 33 int nbLocalIndex = localIndex.size(); 34 int currentlocalIndex = 0; 35 double currentWeight = 0.0; 36 for (int idx = 0; idx < nbLocalIndex; ++idx) 38 37 { 39 int nbLocalIndex = localIndex.size();40 int currentlocalIndex = 0;41 for (int idx = 0; idx < nbLocalIndex; ++idx)38 currentlocalIndex = localIndex[idx].first; 39 currentWeight = localIndex[idx].second; 40 if (flagInitial[currentlocalIndex]) 42 41 { 43 currentlocalIndex = localIndex[idx].first; 44 if (!NumTraits<double>::isnan(*(dataInput + idx))) 45 { 46 if (flagInitial[currentlocalIndex]) 47 { 48 dataOut(currentlocalIndex) = *(dataInput + idx); 49 flagInitial[currentlocalIndex] = false; 50 } 51 else 52 { 53 dataOut(currentlocalIndex) = std::max(*(dataInput + idx), dataOut(currentlocalIndex)); 54 } 55 } 42 dataOut(currentlocalIndex) = *(dataInput + idx); 43 flagInitial[currentlocalIndex] = false; 56 44 } 57 } 58 else 59 { 60 int nbLocalIndex = localIndex.size(); 61 int currentlocalIndex = 0; 62 for (int idx = 0; idx < nbLocalIndex; ++idx) 45 else 63 46 { 64 currentlocalIndex = localIndex[idx].first; 65 if (flagInitial[currentlocalIndex]) 66 { 67 dataOut(currentlocalIndex) = *(dataInput + idx); 68 flagInitial[currentlocalIndex] = false; 69 } 70 else 71 { 72 dataOut(currentlocalIndex) = std::max(*(dataInput + idx), dataOut(currentlocalIndex)); 73 } 47 dataOut(currentlocalIndex) = std::max(*(dataInput + idx), dataOut(currentlocalIndex)); 74 48 } 75 49 } -
XIOS/dev/branch_yushan/src/transformation/Functions/max_reduction.hpp
r1018 r1037 26 26 const double* dataInput, 27 27 CArray<double,1>& dataOut, 28 std::vector<bool>& flagInitial, 29 const double& defaultValue); 28 std::vector<bool>& flagInitial); 30 29 31 30 virtual ~CMaxReductionAlgorithm() {} -
XIOS/dev/branch_yushan/src/transformation/Functions/min_reduction.cpp
r1018 r1037 3 3 \author Ha NGUYEN 4 4 \since 27 June 2016 5 \date 9 Jan 20175 \date 27 June 2016 6 6 7 7 \brief min reduction 8 8 */ 9 9 #include "min_reduction.hpp" 10 #include "utils.hpp"11 10 12 11 namespace xios { … … 30 29 const double* dataInput, 31 30 CArray<double,1>& dataOut, 32 std::vector<bool>& flagInitial, 33 const double& defaultValue) 31 std::vector<bool>& flagInitial) 34 32 { 35 bool hasMissingValue = NumTraits<double>::isnan(defaultValue);36 37 if (hasMissingValue)33 int nbLocalIndex = localIndex.size(); 34 int currentlocalIndex = 0; 35 for (int idx = 0; idx < nbLocalIndex; ++idx) 38 36 { 39 int nbLocalIndex = localIndex.size(); 40 int currentlocalIndex = 0; 41 for (int idx = 0; idx < nbLocalIndex; ++idx) 37 currentlocalIndex = localIndex[idx].first; 38 if (flagInitial[currentlocalIndex]) 42 39 { 43 currentlocalIndex = localIndex[idx].first; 44 if (!NumTraits<double>::isnan(*(dataInput + idx))) 45 { 46 if (flagInitial[currentlocalIndex]) 47 { 48 dataOut(currentlocalIndex) = *(dataInput + idx); 49 flagInitial[currentlocalIndex] = false; 50 } 51 else 52 { 53 dataOut(currentlocalIndex) = std::min(*(dataInput + idx), dataOut(currentlocalIndex)); 54 } 55 } 40 dataOut(currentlocalIndex) = *(dataInput + idx); 41 flagInitial[currentlocalIndex] = false; 56 42 } 57 } 58 else 59 { 60 int nbLocalIndex = localIndex.size(); 61 int currentlocalIndex = 0; 62 for (int idx = 0; idx < nbLocalIndex; ++idx) 43 else 63 44 { 64 currentlocalIndex = localIndex[idx].first; 65 if (flagInitial[currentlocalIndex]) 66 { 67 dataOut(currentlocalIndex) = *(dataInput + idx); 68 flagInitial[currentlocalIndex] = false; 69 } 70 else 71 { 72 dataOut(currentlocalIndex) = std::min(*(dataInput + idx), dataOut(currentlocalIndex)); 73 } 45 dataOut(currentlocalIndex) = std::min(*(dataInput + idx), dataOut(currentlocalIndex)); 74 46 } 75 47 } -
XIOS/dev/branch_yushan/src/transformation/Functions/min_reduction.hpp
r1018 r1037 26 26 const double* dataInput, 27 27 CArray<double,1>& dataOut, 28 std::vector<bool>& flagInitial, 29 const double& defaultValue); 28 std::vector<bool>& flagInitial); 30 29 31 30 virtual ~CMinReductionAlgorithm() {} -
XIOS/dev/branch_yushan/src/transformation/Functions/reduction.hpp
r1018 r1037 45 45 const double* dataInput, 46 46 CArray<double,1>& dataOut, 47 std::vector<bool>& flagInitial, 48 const double& defaultValue) = 0; 47 std::vector<bool>& flagInitial) = 0; 49 48 /*! 50 49 Update local data -
XIOS/dev/branch_yushan/src/transformation/Functions/sum_reduction.cpp
r1018 r1037 3 3 \author Ha NGUYEN 4 4 \since 27 June 2016 5 \date 9 Jan 20175 \date 27 June 2016 6 6 7 7 \brief sum reduction 8 8 */ 9 9 #include "sum_reduction.hpp" 10 #include "utils.hpp"11 10 12 11 namespace xios { … … 30 29 const double* dataInput, 31 30 CArray<double,1>& dataOut, 32 std::vector<bool>& flagInitial, 33 const double& defaultValue) 31 std::vector<bool>& flagInitial) 34 32 { 35 bool hasMissingValue = NumTraits<double>::isnan(defaultValue); 36 if (hasMissingValue) 33 int nbLocalIndex = localIndex.size(); 34 int currentlocalIndex = 0; 35 double currentWeight = 0.0; 36 for (int idx = 0; idx < nbLocalIndex; ++idx) 37 37 { 38 int nbLocalIndex = localIndex.size();39 int currentlocalIndex = 0;40 for (int idx = 0; idx < nbLocalIndex; ++idx)38 currentlocalIndex = localIndex[idx].first; 39 currentWeight = localIndex[idx].second; 40 if (flagInitial[currentlocalIndex]) 41 41 { 42 currentlocalIndex = localIndex[idx].first; 43 if (!NumTraits<double>::isnan(*(dataInput + idx))) 44 { 45 if (flagInitial[currentlocalIndex]) 46 { 47 dataOut(currentlocalIndex) = *(dataInput + idx); 48 flagInitial[currentlocalIndex] = false; 49 } 50 else 51 { 52 dataOut(currentlocalIndex) += *(dataInput + idx); 53 } 54 } 55 } 56 } 57 else 58 { 59 int nbLocalIndex = localIndex.size(); 60 int currentlocalIndex = 0; 61 for (int idx = 0; idx < nbLocalIndex; ++idx) 42 dataOut(currentlocalIndex) = *(dataInput + idx); 43 flagInitial[currentlocalIndex] = false; 44 } 45 else 62 46 { 63 currentlocalIndex = localIndex[idx].first; 64 if (flagInitial[currentlocalIndex]) 65 { 66 dataOut(currentlocalIndex) = *(dataInput + idx); 67 flagInitial[currentlocalIndex] = false; 68 } 69 else 70 { 71 dataOut(currentlocalIndex) += *(dataInput + idx); 72 } 47 dataOut(currentlocalIndex) += *(dataInput + idx); 73 48 } 74 49 } -
XIOS/dev/branch_yushan/src/transformation/Functions/sum_reduction.hpp
r1018 r1037 26 26 const double* dataInput, 27 27 CArray<double,1>& dataOut, 28 std::vector<bool>& flagInitial, 29 const double& defaultValue); 28 std::vector<bool>& flagInitial); 30 29 31 30 virtual ~CSumReductionAlgorithm() {} -
XIOS/dev/branch_yushan/src/transformation/axis_algorithm_extract_domain.cpp
r1018 r1037 71 71 const double& defaultValue) 72 72 { 73 reduction_->apply(localIndex, dataInput, dataOut, flagInitial , defaultValue);73 reduction_->apply(localIndex, dataInput, dataOut, flagInitial); 74 74 } 75 75 -
XIOS/dev/branch_yushan/src/transformation/axis_algorithm_inverse.cpp
r936 r1037 211 211 212 212 status.resize(requests.size()); 213 //printf("(%d) src/transformation/axis_algorithm_inverse 1st waitall\n", clientRank); 213 214 MPI_Waitall(requests.size(), &requests[0], &status[0]); 214 215 //printf("(%d) src/transformation/axis_algorithm_inverse 1st waitall OK\n", clientRank); 215 216 216 217 std::vector<MPI_Request>().swap(requests); … … 245 246 } 246 247 status.resize(requests.size()); 248 //printf("(%d) src/transformation/axis_algorithm_inverse 2nd waitall\n", clientRank); 249 247 250 MPI_Waitall(requests.size(), &requests[0], &status[0]); 248 251 //printf("(%d) src/transformation/axis_algorithm_inverse 2nd waitall OK\n", clientRank); 249 252 250 253 size_t nGloAxisDest = axisDest_->n_glo.getValue() - 1; -
XIOS/dev/branch_yushan/src/transformation/axis_algorithm_reduce_domain.cpp
r1018 r1037 79 79 const double& defaultValue) 80 80 { 81 reduction_->apply(localIndex, dataInput, dataOut, flagInitial , defaultValue);81 reduction_->apply(localIndex, dataInput, dataOut, flagInitial); 82 82 } 83 83 -
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(); -
XIOS/dev/branch_yushan/src/transformation/domain_algorithm_interpolate.hpp
r1014 r1037 48 48 CInterpolateDomain* interpDomain_; 49 49 bool writeToFile_; 50 bool readFromFile_;51 StdString fileToReadWrite_;52 50 53 51 // class WriteNetCdf; … … 59 57 int addVariableWrite(const StdString& name, nc_type type, 60 58 const std::vector<StdString>& dim); 61 void endDefinition();62 59 void writeDataIndex(const CArray<int,1>& data, const StdString& name, 63 60 bool collective, StdSize record, -
XIOS/dev/branch_yushan/src/transformation/generic_algorithm_transformation.cpp
r1018 r1037 11 11 #include "context_client.hpp" 12 12 #include "client_client_dht_template.hpp" 13 #include "utils.hpp"14 13 15 14 namespace xios { … … 32 31 const double& defaultValue) 33 32 { 34 int nbLocalIndex = localIndex.size(); 35 bool hasMissingValue = NumTraits<double>::isnan(defaultValue);33 int nbLocalIndex = localIndex.size(); 34 bool hasMissingValue = (0.0 != defaultValue) ? true : false; 36 35 if (hasMissingValue) 37 36 { 38 37 for (int idx = 0; idx < nbLocalIndex; ++idx) 39 38 { 40 if ( NumTraits<double>::isnan(*(dataInput + idx)))39 if (defaultValue == *(dataInput + idx)) 41 40 { 42 41 flagInitial[localIndex[idx].first] = false; -
XIOS/dev/branch_yushan/src/transformation/grid_transformation.cpp
r978 r1037 531 531 532 532 status.resize(requests.size()); 533 //printf("(%d) src/transformation/grid_transformation 1st waitall\n", clientRank); 533 534 MPI_Waitall(requests.size(), &requests[0], &status[0]); 535 //printf("(%d) src/transformation/grid_transformation 1st waitall OK\n", clientRank); 534 536 535 537 // Okie, now use the mask to identify which index source we need to send, then also signal the destination which masked index we will return … … 583 585 } 584 586 status.resize(requests.size()); 587 //printf("(%d) src/transformation/grid_transformation 2nd waitall\n", clientRank); 585 588 MPI_Waitall(requests.size(), &requests[0], &status[0]); 589 //printf("(%d) src/transformation/grid_transformation 2nd waitall OK\n", clientRank); 586 590 587 591 // Cool, now we can fill in local index of grid destination (counted for masked index) -
XIOS/dev/branch_yushan/src/transformation/scalar_algorithm_extract_axis.cpp
r1018 r1037 58 58 const double& defaultValue) 59 59 { 60 reduction_->apply(localIndex, dataInput, dataOut, flagInitial , defaultValue);60 reduction_->apply(localIndex, dataInput, dataOut, flagInitial); 61 61 } 62 62 -
XIOS/dev/branch_yushan/src/transformation/scalar_algorithm_reduce_axis.cpp
r1018 r1037 90 90 const double& defaultValue) 91 91 { 92 reduction_->apply(localIndex, dataInput, dataOut, flagInitial , defaultValue);92 reduction_->apply(localIndex, dataInput, dataOut, flagInitial); 93 93 } 94 94 -
XIOS/dev/branch_yushan/src/transformation/scalar_algorithm_reduce_domain.cpp
r1018 r1037 84 84 const double& defaultValue) 85 85 { 86 reduction_->apply(localIndex, dataInput, dataOut, flagInitial , defaultValue);86 reduction_->apply(localIndex, dataInput, dataOut, flagInitial); 87 87 } 88 88
Note: See TracChangeset
for help on using the changeset viewer.