/[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 1747 by phornby, Fri Jul 11 13:12:46 2008 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 646  DataExpanded::setToZero(){ Line 649  DataExpanded::setToZero(){
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.");

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

  ViewVC Help
Powered by ViewVC 1.1.26