Go to the documentation of this file.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/direct_ref_b.hpp>
00038
00039 template <typename T, typename Pr>
00040 T oned::DirectCutRefB<T,Pr>::direct_ref_b(int procCount, const Pr& prefixSumArray,
00041 int length, int *cutIndexes, T )
00042 {
00043 T v = direct_ref_b_internal(procCount, prefixSumArray, length, cutIndexes);
00044 return v;
00045 }
00046
00047
00048
00049 template <typename T, typename Pr>
00050 T oned::DirectCutRefB<T,Pr>::direct_ref_b_internal(int procCount, const Pr& prefixSumArray,
00051 int length, int *cutIndexes)
00052 {
00053 using namespace util;
00054 T avg;
00055 int inc = length / procCount, p, lastcut = 0;
00056 int step = inc;
00057 T bottleneck = 0, val;
00058 for(p = 0; p < procCount - 1; p++)
00059 {
00060 avg = (prefixSumArray[length-1] - prefixSumArray[lastcut])/ (procCount - p);
00061 val = prefixSumArray[lastcut] + avg;
00062 inc = (length - lastcut) / (procCount - p);
00063 if (inc == 0) inc++;
00064 while(prefixSumArray[step] <= val)
00065 {
00066 assert (inc > 0);
00067 step+=inc;
00068 if(step > length-1)
00069 {
00070 step = length-1;
00071 break;
00072 }
00073 }
00074 assert (step>=0);
00075 assert (step<length);
00076 cutIndexes[p] = binarySearchLeft(prefixSumArray, step - inc, step, val);
00077
00078 assert((prefixSumArray[cutIndexes[p]] >=val) || (cutIndexes[p] == length - 1));
00079
00080 assert(cutIndexes[p] >= step - inc);
00081 assert(cutIndexes[p] <= step);
00082 assert(cutIndexes[p] >=0);
00083 assert(lastcut <= cutIndexes[p]);
00084 assert(-1 != cutIndexes[p]);
00085
00086 if(prefixSumArray[cutIndexes[p]] - prefixSumArray[lastcut] > bottleneck)
00087 bottleneck = prefixSumArray[cutIndexes[p]] - prefixSumArray[lastcut];
00088 lastcut = cutIndexes[p];
00089 }
00090 if(prefixSumArray[length - 1] - prefixSumArray[lastcut] > bottleneck)
00091 return prefixSumArray[length - 1] - prefixSumArray[lastcut];
00092 else
00093 return bottleneck;
00094 }
00095