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

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

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

revision 2471 by jfenwick, Thu Jun 11 23:33:06 2009 UTC revision 2476 by jfenwick, Wed Jun 17 04:42:13 2009 UTC
# Line 1956  Data::calc_minGlobalDataPoint(int& ProcN Line 1956  Data::calc_minGlobalDataPoint(int& ProcN
1956        }        }
1957      }      }
1958      #pragma omp critical      #pragma omp critical
1959      if (local_min<min) {      if (local_min<min) {    // If we found a smaller value than our sentinel
1960        min=local_min;        min=local_min;
1961        lowi=local_lowi;        lowi=local_lowi;
1962        lowj=local_lowj;        lowj=local_lowj;
# Line 1964  Data::calc_minGlobalDataPoint(int& ProcN Line 1964  Data::calc_minGlobalDataPoint(int& ProcN
1964    }    }
1965    
1966  #ifdef PASO_MPI  #ifdef PASO_MPI
1967      // determine the processor on which the minimum occurs    // determine the processor on which the minimum occurs
1968      next = temp.getDataPointRO(lowi,lowj);    next = temp.getDataPointRO(lowi,lowj);
1969      int lowProc = 0;    int lowProc = 0;
1970      double *globalMins = new double[get_MPISize()+1];    double *globalMins = new double[get_MPISize()+1];
1971      int error;    int error;
1972      error = MPI_Gather ( &next, 1, MPI_DOUBLE, globalMins, 1, MPI_DOUBLE, 0, get_MPIComm() );    error = MPI_Gather ( &next, 1, MPI_DOUBLE, globalMins, 1, MPI_DOUBLE, 0, get_MPIComm() );
1973    
1974      if( get_MPIRank()==0 ){    if( get_MPIRank()==0 ){
1975          next = globalMins[lowProc];      next = globalMins[lowProc];
1976          for( i=1; i<get_MPISize(); i++ )      for( i=1; i<get_MPISize(); i++ )
1977              if( next>globalMins[i] ){          if( next>globalMins[i] ){
1978                  lowProc = i;              lowProc = i;
1979                  next = globalMins[i];              next = globalMins[i];
1980              }          }
1981      }    }
1982      MPI_Bcast( &lowProc, 1, MPI_DOUBLE, 0, get_MPIComm() );    MPI_Bcast( &lowProc, 1, MPI_DOUBLE, 0, get_MPIComm() );
1983    
1984      delete [] globalMins;    delete [] globalMins;
1985      ProcNo = lowProc;    ProcNo = lowProc;
1986  #else  #else
1987      ProcNo = 0;    ProcNo = 0;
1988  #endif  #endif
1989    DataPointNo = lowj + lowi * numDPPSample;    DataPointNo = lowj + lowi * numDPPSample;
1990  }  }
1991    
1992    
1993    const boost::python::tuple
1994    Data::maxGlobalDataPoint() const
1995    {
1996      int DataPointNo;
1997      int ProcNo;
1998      calc_maxGlobalDataPoint(ProcNo,DataPointNo);
1999      return make_tuple(ProcNo,DataPointNo);
2000    }
2001    
2002    void
2003    Data::calc_maxGlobalDataPoint(int& ProcNo,
2004                            int& DataPointNo) const
2005    {
2006      if (isLazy())
2007      {
2008        Data temp(*this);   // to get around the fact that you can't resolve a const Data
2009        temp.resolve();
2010        return temp.calc_maxGlobalDataPoint(ProcNo,DataPointNo);
2011      }
2012      int i,j;
2013      int highi=0,highj=0;
2014    //-------------
2015      double max=numeric_limits<double>::min();
2016    
2017      Data temp=maxval();
2018    
2019      int numSamples=temp.getNumSamples();
2020      int numDPPSample=temp.getNumDataPointsPerSample();
2021    
2022      double next,local_max;
2023      int local_highi=0,local_highj=0;  
2024    
2025      #pragma omp parallel firstprivate(local_highi,local_highj) private(next,local_max)
2026      {
2027        local_max=max;
2028        #pragma omp for private(i,j) schedule(static)
2029        for (i=0; i<numSamples; i++) {
2030          for (j=0; j<numDPPSample; j++) {
2031            next=temp.getDataAtOffsetRO(temp.getDataOffset(i,j));
2032            if (next>local_max) {
2033              local_max=next;
2034              local_highi=i;
2035              local_highj=j;
2036            }
2037          }
2038        }
2039        #pragma omp critical
2040        if (local_max>max) {    // If we found a larger value than our sentinel
2041          max=local_max;
2042          highi=local_highi;
2043          highj=local_highj;
2044        }
2045      }
2046    
2047    #ifdef PASO_MPI
2048      // determine the processor on which the maximum occurs
2049      next = temp.getDataPointRO(highi,highj);
2050      int highProc = 0;
2051      double *globalMaxs = new double[get_MPISize()+1];
2052      int error;
2053      error = MPI_Gather ( &next, 1, MPI_DOUBLE, globalMaxs, 1, MPI_DOUBLE, 0, get_MPIComm() );
2054    
2055      if( get_MPIRank()==0 ){
2056      next = globalMaxs[highProc];
2057      for( i=1; i<get_MPISize(); i++ )
2058        if( next>globalMaxs[i] ){
2059            highProc = i;
2060            next = globalMaxs[i];
2061        }
2062      }
2063      MPI_Bcast( &highProc, 1, MPI_DOUBLE, 0, get_MPIComm() );
2064      delete [] globalMaxs;
2065      ProcNo = highProc;
2066    #else
2067      ProcNo = 0;
2068    #endif
2069      DataPointNo = highj + highi * numDPPSample;
2070    }
2071    
2072  void  void
2073  Data::saveDX(std::string fileName) const  Data::saveDX(std::string fileName) const
2074  {  {

Legend:
Removed from v.2471  
changed lines
  Added in v.2476

  ViewVC Help
Powered by ViewVC 1.1.26