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