/[escript]/branches/arrayview_from_1695_trunk/escript/src/DataExpanded.cpp
ViewVC logotype

Diff of /branches/arrayview_from_1695_trunk/escript/src/DataExpanded.cpp

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

revision 1780 by jfenwick, Thu Sep 11 01:06:15 2008 UTC revision 1781 by jfenwick, Thu Sep 11 05:03:14 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  #include "DataMaths.h"  #include "DataMaths.h"
# Line 750  DataExpanded::setToZero(){ Line 753  DataExpanded::setToZero(){
753    }    }
754  }  }
755    
756    /* Append MPI rank to file name if multiple MPI processes */
757    char *Escript_MPI_appendRankToFileName(const char *fileName, int mpi_size, int mpi_rank) {
758      /* Make plenty of room for the mpi_rank number and terminating '\0' */
759      char *newFileName = (char *)malloc(strlen(fileName)+20);
760      strncpy(newFileName, fileName, strlen(fileName)+1);
761      if (mpi_size>1) sprintf(newFileName+strlen(newFileName), ".%04d", mpi_rank);
762      return(newFileName);
763    }
764    
765  void  void
766  DataExpanded::dump(const std::string fileName) const  DataExpanded::dump(const std::string fileName) const
767  {  {
    #ifdef PASO_MPI  
    throw DataException("Error - DataExpanded:: dump is not implemented for MPI yet.");  
    #endif  
768     #ifdef USE_NETCDF     #ifdef USE_NETCDF
769     const int ldims=2+DataTypes::maxRank;     const int ldims=2+DataTypes::maxRank;
770     const NcDim* ncdims[ldims];     const NcDim* ncdims[ldims];
# Line 767  DataExpanded::dump(const std::string fil Line 775  DataExpanded::dump(const std::string fil
775     long dims[ldims];     long dims[ldims];
776     const double* d_ptr=&(m_data[0]);     const double* d_ptr=&(m_data[0]);
777     const DataTypes::ShapeType& shape = getShape();     const DataTypes::ShapeType& shape = getShape();
778       int mpi_iam=0, mpi_num=1;
779    
780     // netCDF error handler     // netCDF error handler
781     NcError err(NcError::verbose_nonfatal);     NcError err(NcError::verbose_nonfatal);
782     // Create the file.     // Create the file.
783     NcFile dataFile(fileName.c_str(), NcFile::Replace);  #ifdef PASO_MPI
784       MPI_Comm_rank(MPI_COMM_WORLD, &mpi_iam);
785       MPI_Comm_size(MPI_COMM_WORLD, &mpi_num);
786    #endif
787       char *newFileName = Escript_MPI_appendRankToFileName(fileName.c_str(), mpi_num, mpi_iam);
788       NcFile dataFile(newFileName, NcFile::Replace);
789     // check if writing was successful     // check if writing was successful
790     if (!dataFile.is_valid())     if (!dataFile.is_valid())
791          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.1780  
changed lines
  Added in v.1781

  ViewVC Help
Powered by ViewVC 1.1.26