00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <oned/nicol_plus_interval.hpp>
00038
00039
00040 template <typename T, typename Pr>
00041 T oned::Nicol_plus_interval<T,Pr>::nicol_plus_internal(const Pr& wpre, int length,
00042 int numproc, T , int *sl, int *sh)
00043 {
00044 using namespace util;
00045 int ilast = 1, b;
00046 int ilow, ihigh, imid;
00047 T bottleneck, Bopt;
00048
00049 T lb = 0;
00050 T ub = wpre.interval(0,length - 1);
00051 int *s = new int[numproc];
00052 int *oris = s;
00053 Bopt = ub;
00054
00055 for(b=0; b < numproc - 1; b++)
00056 {
00057
00058 ilow = (sl[b]<ilast?ilast-1:sl[b]);
00059 ihigh=length-1;
00060 assert (ilow <= ihigh);
00061
00062 while(ilow < ihigh)
00063 {
00064 imid = (ilow + ihigh) / 2;
00065 bottleneck = wpre.interval(ilast - 1,imid);
00066 assert (bottleneck >=0);
00067 if((lb <= bottleneck) && (bottleneck < ub))
00068 {
00069 if(ParametricSearch<T,Pr>::rprobe_interval(wpre, length, bottleneck, numproc, s, sl, sh))
00070 {
00071 int *tmp;
00072 tmp=s;
00073 s=sh;
00074 sh=tmp;
00075 ub = bottleneck;
00076 ihigh = imid;
00077 }
00078 else
00079 {
00080 int *tmp;
00081 tmp=s;
00082 s=sl;
00083 sl=tmp;
00084 lb = bottleneck;
00085 ilow = imid + 1;
00086 }
00087 }
00088 else if(bottleneck >= ub)
00089 {
00090 ihigh = imid;
00091 }
00092 else
00093 {
00094 ilow = imid + 1;
00095 }
00096 }
00097 assert (ilow == ihigh);
00098 assert(b < numproc);
00099
00100 Bopt = std::min(Bopt, wpre.interval(ilast - 1, ihigh));
00101 ilast = ihigh;
00102 }
00103
00104 Bopt = std::min(Bopt, wpre.interval(ilast-1,length-1));
00105 delete[] oris;
00106 return Bopt;
00107 }
00108
00109
00110 template <typename T, typename Pr>
00111 T oned::Nicol_plus_interval<T,Pr>::nicol_plus(int procCount, const Pr& prefixSumArray,
00112 int length, int *cutIndexes, T max)
00113 {
00114 using namespace util;
00115 int i;
00116 int *sl = new int[procCount];
00117 int *sh = new int[procCount];
00118 T b;
00119
00120 for(i = 0; i < procCount; i++)
00121 {
00122 sl[i] = 1;
00123 sh[i] = length - 1;
00124 }
00125
00126 b = nicol_plus_internal (prefixSumArray, length, procCount, max, sl, sh);
00127
00128 if (cutIndexes != NULL)
00129 {
00130 #ifndef NDEBUG
00131 int valid = ParametricSearch<T,Pr>::probeCut_interval(b, procCount - 1, prefixSumArray, length, cutIndexes);
00132 assert(valid==1);
00133 #endif
00134 #ifdef NDEBUG
00135 ParametricSearch<T,Pr>::probeCut_interval(b, procCount - 1, prefixSumArray, length, cutIndexes);
00136 #endif
00137 }
00138 else
00139 {
00140 std::cerr << "Error: cutIndexes not allocated in nicol plus 2d!" << std::endl;
00141 }
00142
00143 delete[] sl;
00144 delete[] sh;
00145 return b;
00146 }
00147