/[escript]/trunk/escript/src/DataExpanded.cpp
ViewVC logotype

Diff of /trunk/escript/src/DataExpanded.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1358 by gross, Wed Dec 5 03:41:06 2007 UTC revision 1748 by ksteube, Wed Sep 3 06:10:39 2008 UTC
# Line 20  Line 20 
20  #ifdef USE_NETCDF  #ifdef USE_NETCDF
21  #include <netcdfcpp.h>  #include <netcdfcpp.h>
22  #endif  #endif
23    #ifdef PASO_MPI
24    #include <mpi.h>
25    #endif
26    
27  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
28    
# Line 641  DataExpanded::setToZero(){ Line 644  DataExpanded::setToZero(){
644    for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {    for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
645      for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {      for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
646          p=&(m_data[getPointOffset(sampleNo,dataPointNo)]);          p=&(m_data[getPointOffset(sampleNo,dataPointNo)]);
647          for (int i=0; i<n ;++i) p[i]=0.;          for (i=0; i<n ;++i) p[i]=0.;
648      }      }
649    }    }
650  }  }
651    
652    /* Append MPI rank to file name if multiple MPI processes */
653    char *Escript_MPI_appendRankToFileName(const char *fileName, int mpi_size, int mpi_rank) {
654      /* Make plenty of room for the mpi_rank number and terminating '\0' */
655      char *newFileName = (char *)malloc(strlen(fileName)+20);
656      strncpy(newFileName, fileName, strlen(fileName)+1);
657      if (mpi_size>1) sprintf(newFileName+strlen(newFileName), ".%04d", mpi_rank);
658      return(newFileName);
659    }
660    
661  void  void
662  DataExpanded::dump(const std::string fileName) const  DataExpanded::dump(const std::string fileName) const
663  {  {
    #ifdef PASO_MPI  
    throw DataException("Error - DataExpanded:: dump is not implemented for MPI yet.");  
    #endif  
664     #ifdef USE_NETCDF     #ifdef USE_NETCDF
665     const int ldims=2+DataArrayView::maxRank;     const int ldims=2+DataArrayView::maxRank;
666     const NcDim* ncdims[ldims];     const NcDim* ncdims[ldims];
# Line 663  DataExpanded::dump(const std::string fil Line 671  DataExpanded::dump(const std::string fil
671     long dims[ldims];     long dims[ldims];
672     const double* d_ptr=&(m_data[0]);     const double* d_ptr=&(m_data[0]);
673     DataArrayView::ShapeType shape = getPointDataView().getShape();     DataArrayView::ShapeType shape = getPointDataView().getShape();
674       int mpi_iam=0, mpi_num=1;
675    
676     // netCDF error handler     // netCDF error handler
677     NcError err(NcError::verbose_nonfatal);     NcError err(NcError::verbose_nonfatal);
678     // Create the file.     // Create the file.
679     NcFile dataFile(fileName.c_str(), NcFile::Replace);  #ifdef PASO_MPI
680       MPI_Comm_rank(MPI_COMM_WORLD, &mpi_iam);
681       MPI_Comm_size(MPI_COMM_WORLD, &mpi_num);
682    #endif
683       char *newFileName = Escript_MPI_appendRankToFileName(fileName.c_str(), mpi_num, mpi_iam);
684       NcFile dataFile(newFileName, NcFile::Replace);
685     // check if writing was successful     // check if writing was successful
686     if (!dataFile.is_valid())     if (!dataFile.is_valid())
687          throw DataException("Error - DataExpanded:: opening of netCDF file for output failed.");          throw DataException("Error - DataExpanded:: opening of netCDF file for output failed.");
# Line 740  DataExpanded::setTaggedValue(int tagKey, Line 754  DataExpanded::setTaggedValue(int tagKey,
754      if (getFunctionSpace().getTagFromSampleNo(sampleNo) == tagKey ) {      if (getFunctionSpace().getTagFromSampleNo(sampleNo) == tagKey ) {
755          for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {          for (dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
756              p=&(m_data[getPointOffset(sampleNo,dataPointNo)]);              p=&(m_data[getPointOffset(sampleNo,dataPointNo)]);
757              for (int i=0; i<n ;++i) p[i]=in[i];              for (i=0; i<n ;++i) p[i]=in[i];
758          }          }
759      }      }
760    }    }
761  }  }
762    
763    void
764    DataExpanded::reorderByReferenceIDs(int *reference_ids)
765    {
766      int numSamples = getNumSamples();
767      DataArrayView& thisView=getPointDataView();
768      DataArrayView::ValueType::size_type n = thisView.noValues() * getNumDPPSample();
769      int sampleNo, sampleNo2,i;
770      double* p,*p2;
771      register double rtmp;
772      FunctionSpace fs=getFunctionSpace();
773    
774      for (sampleNo = 0; sampleNo < numSamples; sampleNo++) {
775         const int id_in=reference_ids[sampleNo];
776         const int id=fs.getReferenceIDOfSample(sampleNo);
777         if (id!=id_in) {
778             bool matched=false;
779             for (sampleNo2 = sampleNo+1; sampleNo2 < numSamples; sampleNo2++) {
780                  if (id == reference_ids[sampleNo2]) {
781                     p=&(m_data[getPointOffset(sampleNo,0)]);
782                     p2=&(m_data[getPointOffset(sampleNo2,0)]);
783                     for (i=0; i<n ;i++) {
784                             rtmp=p[i];
785                             p[i]=p2[i];
786                             p2[i]=rtmp;
787                     }
788                     reference_ids[sampleNo]=id;
789                     reference_ids[sampleNo2]=id_in;
790                     matched=true;
791                     break;
792                  }
793             }
794             if (! matched) {
795                throw DataException("Error - DataExpanded::reorderByReferenceIDs: unable to reorder sample data by reference ids");
796             }
797         }
798       }
799    }
800    
801    
802  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.1358  
changed lines
  Added in v.1748

  ViewVC Help
Powered by ViewVC 1.1.26