Changeset 1540 for XIOS/dev/branch_openmp/src
- Timestamp:
- 06/12/18 14:21:57 (6 years ago)
- Location:
- XIOS/dev/branch_openmp/src/transformation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_openmp/src/transformation/domain_algorithm_interpolate.cpp
r1520 r1540 714 714 CDomainAlgorithmInterpolate::WriteNetCdf::WriteNetCdf(const StdString& filename, const ep_lib::MPI_Comm comm) 715 715 : CNc4DataOutput(NULL, filename, false, false, true, comm, false, true) {} 716 717 CDomainAlgorithmInterpolate::WriteNetCdf::WriteNetCdf(const StdString& filename, bool exist, const ep_lib::MPI_Comm comm) 718 : CNc4DataOutput(NULL, filename, exist, false, true, comm, false, true) {} 719 716 720 int CDomainAlgorithmInterpolate::WriteNetCdf::addDimensionWrite(const StdString& name, 717 721 const StdSize size) … … 806 810 std::vector<StdSize> count(1, localNbWeight); 807 811 808 WriteNetCdf netCdfWriter(filename, client->intraComm); 809 810 // Define some dimensions 811 netCdfWriter.addDimensionWrite("n_src", n_src); 812 netCdfWriter.addDimensionWrite("n_dst", n_dst); 813 netCdfWriter.addDimensionWrite("n_weight", globalNbWeight); 814 815 std::vector<StdString> dims(1,"n_weight"); 816 817 // Add some variables 818 netCdfWriter.addVariableWrite("src_idx", NC_INT, dims); 819 netCdfWriter.addVariableWrite("dst_idx", NC_INT, dims); 820 netCdfWriter.addVariableWrite("weight", NC_DOUBLE, dims); 821 822 // End of definition 823 netCdfWriter.endDefinition(); 824 825 // // Write variables 826 if (0 != localNbWeight) 827 { 828 netCdfWriter.writeDataIndex(src_idx, "src_idx", false, 0, &start, &count); 829 netCdfWriter.writeDataIndex(dst_idx, "dst_idx", false, 0, &start, &count); 830 netCdfWriter.writeDataIndex(weights, "weight", false, 0, &start, &count); 831 } 832 833 netCdfWriter.closeFile(); 812 int my_rank_loc = client->intraComm->ep_comm_ptr->size_rank_info[1].first; 813 814 cout<<"begin write weight info"<< endl; 815 816 WriteNetCdf *netCdfWriter; 817 818 // #pragma omp barrier 819 // #pragma omp master 820 MPI_Barrier_local(client->intraComm); 821 if(my_rank_loc==0) 822 { 823 824 WriteNetCdf my_writer(filename, client->intraComm); 825 netCdfWriter = &my_writer; 826 827 // Define some dimensions 828 netCdfWriter->addDimensionWrite("n_src", n_src); 829 netCdfWriter->addDimensionWrite("n_dst", n_dst); 830 netCdfWriter->addDimensionWrite("n_weight", globalNbWeight); 831 832 std::vector<StdString> dims(1,"n_weight"); 833 834 // Add some variables 835 netCdfWriter->addVariableWrite("src_idx", NC_INT, dims); 836 netCdfWriter->addVariableWrite("dst_idx", NC_INT, dims); 837 netCdfWriter->addVariableWrite("weight", NC_DOUBLE, dims); 838 839 // End of definition 840 netCdfWriter->endDefinition(); 841 842 netCdfWriter->closeFile(); 843 } 844 845 // #pragma omp barrier 846 MPI_Barrier_local(client->intraComm); 847 848 #pragma omp critical (write_weight_data) 849 { 850 // open file 851 WriteNetCdf my_writer(filename, true, client->intraComm); 852 netCdfWriter = &my_writer; 853 854 // // Write variables 855 if (0 != localNbWeight) 856 { 857 netCdfWriter->writeDataIndex(src_idx, "src_idx", false, 0, &start, &count); 858 netCdfWriter->writeDataIndex(dst_idx, "dst_idx", false, 0, &start, &count); 859 netCdfWriter->writeDataIndex(weights, "weight", false, 0, &start, &count); 860 } 861 } 862 863 MPI_Barrier_local(client->intraComm); 864 865 // #pragma omp barrier 866 cout<<"end write weight info"<< endl; 834 867 } 835 868 … … 861 894 } 862 895 863 nc_open(filename.c_str(),NC_NOWRITE, &ncid) ; 864 nc_inq_dimid(ncid,"n_weight",&weightDimId) ; 865 nc_inq_dimlen(ncid,weightDimId,&nbWeightGlo) ; 866 867 size_t nbWeight ; 868 size_t start ; 869 size_t div = nbWeightGlo/clientSize ; 870 size_t mod = nbWeightGlo%clientSize ; 871 if (clientRank < mod) 872 { 873 nbWeight=div+1 ; 874 start=clientRank*(div+1) ; 875 } 876 else 877 { 878 nbWeight=div ; 879 start= mod * (div+1) + (clientRank-mod) * div ; 880 } 881 882 double* weight=new double[nbWeight] ; 883 int weightId ; 884 nc_inq_varid (ncid, "weight", &weightId) ; 885 nc_get_vara_double(ncid, weightId, &start, &nbWeight, weight) ; 886 887 long* srcIndex=new long[nbWeight] ; 888 int srcIndexId ; 889 nc_inq_varid (ncid, "src_idx", &srcIndexId) ; 890 nc_get_vara_long(ncid, srcIndexId, &start, &nbWeight, srcIndex) ; 891 892 long* dstIndex=new long[nbWeight] ; 893 int dstIndexId ; 894 nc_inq_varid (ncid, "dst_idx", &dstIndexId) ; 895 nc_get_vara_long(ncid, dstIndexId, &start, &nbWeight, dstIndex) ; 896 897 int indexOffset=0 ; 898 if (fortranConvention) indexOffset=1 ; 899 for(size_t ind=0; ind<nbWeight;++ind) 900 interpMapValue[dstIndex[ind]-indexOffset].push_back(make_pair(srcIndex[ind]-indexOffset,weight[ind])); 901 } 896 #pragma omp critical (read_weight_data) 897 { 898 nc_open(filename.c_str(),NC_NOWRITE, &ncid) ; 899 nc_inq_dimid(ncid,"n_weight",&weightDimId) ; 900 nc_inq_dimlen(ncid,weightDimId,&nbWeightGlo) ; 901 902 size_t nbWeight ; 903 size_t start ; 904 size_t div = nbWeightGlo/clientSize ; 905 size_t mod = nbWeightGlo%clientSize ; 906 if (clientRank < mod) 907 { 908 nbWeight=div+1 ; 909 start=clientRank*(div+1) ; 910 } 911 else 912 { 913 nbWeight=div ; 914 start= mod * (div+1) + (clientRank-mod) * div ; 915 } 916 917 double* weight=new double[nbWeight] ; 918 int weightId ; 919 nc_inq_varid (ncid, "weight", &weightId) ; 920 nc_get_vara_double(ncid, weightId, &start, &nbWeight, weight) ; 921 922 long* srcIndex=new long[nbWeight] ; 923 int srcIndexId ; 924 nc_inq_varid (ncid, "src_idx", &srcIndexId) ; 925 nc_get_vara_long(ncid, srcIndexId, &start, &nbWeight, srcIndex) ; 926 927 long* dstIndex=new long[nbWeight] ; 928 int dstIndexId ; 929 nc_inq_varid (ncid, "dst_idx", &dstIndexId) ; 930 nc_get_vara_long(ncid, dstIndexId, &start, &nbWeight, dstIndex) ; 931 932 int indexOffset=0 ; 933 if (fortranConvention) indexOffset=1 ; 934 for(size_t ind=0; ind<nbWeight;++ind) 935 interpMapValue[dstIndex[ind]-indexOffset].push_back(make_pair(srcIndex[ind]-indexOffset,weight[ind])); 936 } 937 } 902 938 903 939 void CDomainAlgorithmInterpolate::apply(const std::vector<std::pair<int,double> >& localIndex, -
XIOS/dev/branch_openmp/src/transformation/domain_algorithm_interpolate.hpp
r1482 r1540 71 71 public: 72 72 WriteNetCdf(const StdString& filename, const ep_lib::MPI_Comm comm); 73 WriteNetCdf(const StdString& filename, bool exist, const ep_lib::MPI_Comm comm); 73 74 int addDimensionWrite(const StdString& name, const StdSize size = UNLIMITED_DIM); 74 75 int addVariableWrite(const StdString& name, nc_type type,
Note: See TracChangeset
for help on using the changeset viewer.