00001 00002 // This file is part of SPart, Spatially Located Workload Partitioner. 00003 00004 // Copyright (C) 2011, The Ohio State University 00005 // SPart developed by Erdeniz O. Bas, Erik Saule and Umit V. Catalyurek 00006 00007 // For questions, comments, suggestions, bugs please send e-mail to: 00008 // Umit V. Catalyurek catalyurek.1@osu.edu 00009 00010 // SPart is free software; you can redistribute it and/or modify it under 00011 // the terms of the GNU General Public License as published by the Free 00012 // Software Foundation; either version 2 or (at your option) any later 00013 // version. 00014 00015 // SPart is distributed in the hope that it will be useful, but WITHOUT 00016 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00017 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00018 // for more details. 00019 00020 // You should have received a copy of the GNU General Public License 00021 // along with SPart; if not, write to the Free Software Foundation, Inc., 00022 // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 00023 00024 // As a special exception, if other files instantiate templates or use 00025 // macros or inline functions from this file, or you compile this file 00026 // and link it with other works to produce a work based on this file, 00027 // this file does not by itself cause the resulting work to be covered by 00028 // the GNU General Public License. However the source code for this file 00029 // must still be made available in accordance with section (3) of the GNU 00030 // General Public License. 00031 00032 // This exception does not invalidate any other reasons why a work based 00033 // on this file might be covered by the GNU General Public License. 00034 00035 // The full text of the GPL license version 2 is available in "gpl.txt". 00036 00048 #ifndef __REC_BISECT_H__ 00049 #define __REC_BISECT_H__ 00050 #include <util/prefix_sum_tools.hpp> 00051 #include <assert.h> 00052 #include <stdlib.h> 00053 #include <util/tools.hpp> 00054 #include <iostream> 00055 #include <stdio.h> 00056 00057 00058 namespace oned 00059 { 00069 template <typename T, typename Pr> 00070 class RecursiveBisection 00071 { 00072 static const bool debugFEC=false; 00073 static const bool debugRB=false; 00074 00075 00076 /*Returns the recursive bisection cuts in sorted order in 00077 *cutPoints. low and high included.*/ 00078 static T rec_bisection_internal(int numProc, int low, int high, 00079 const Pr& prefixSum, int *cutPoints); 00080 00081 00082 public: 00083 /*Calculates the abstract weight difference of two partitions which 00084 are seperated by the index "candidate". candidate remains in the 00085 left processor. prefixsum[i] is the sum of first i elements in a 00086 given array. prefixsum[0] = 0. low and high values are included 00087 while calculating the difference. rightProc is the number of 00088 processors on the right and leftProc is the number of processors on 00089 the left*/ 00090 static double calculateDiff(const Pr& prefixSum, int low, int high, 00091 int leftProc, int rightProc, int candidate); 00092 00093 00094 00095 00107 static int findEvenCut(const Pr& prefixSum, int low, int high, 00108 int leftProc, int rightProc); 00120 static T rec_bisection(int procCount, const Pr& prefixSumArray, 00121 int length, int *cutIndexes, T max); 00122 }; 00123 } 00124 #include <oned/rec_bisect_impl.hpp> 00125 00126 #endif