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 00037 /* 00038 * (C) Ohio State University Biomedical Informatics - HPC Lab. http://www.bmi.osu.edu/hpc 00039 * 00040 * 02/16/2010 00041 * nicol_minus.c 00042 * 00043 * This function is the implementation of the nicols algorithm as it is presented in PinarAykanat 2004 in JPDC in figure 5a 00044 * 00045 */ 00046 00047 #include <oned/nicol_minus.hpp> 00048 00049 template <typename T, typename Pr> 00050 T oned::NicolMinus<T,Pr>::nicol_minus_internal(const Pr& w, int n, int p) 00051 { 00052 using namespace util; 00053 int *i_array = new int[p]; 00054 T* Bb_array = new T[p]; 00055 int b, ilow, ihigh, imid, i; 00056 T B, Bopt; 00057 i_array[0] = 1; 00058 for(b = 1; b <= p - 1; b++) 00059 { 00060 ilow = i_array[b - 1]; 00061 ihigh = n - 1; 00062 while(ilow < ihigh) 00063 { 00064 imid = (ilow + ihigh) / 2; 00065 B = w[imid] - w[i_array[b - 1] - 1]; 00066 if(ParametricSearch<T,Pr>::probe(B, p - 1, w, n)) 00067 ihigh = imid; 00068 else 00069 ilow = imid + 1; 00070 } 00071 i_array[b] = ihigh; 00072 Bb_array[b-1] = w[i_array[b]] - w[i_array[b-1]-1]; 00073 } 00074 Bb_array[p-1] = w[n-1] - w[i_array[p-1]-1]; 00075 Bopt = Bb_array[0]; 00076 for(i = 1; i < p; i++) 00077 { 00078 if(Bopt > Bb_array[i]) 00079 { 00080 Bopt = Bb_array[i]; 00081 } 00082 } 00083 delete[] i_array; 00084 delete[] Bb_array ; 00085 return Bopt; 00086 } 00087 00088 template <typename T, typename Pr> 00089 T oned::NicolMinus<T,Pr>::nicol_minus (int procCount, const Pr& prefixSumArray, 00090 int length, int *cutIndexes, T ) 00091 { 00092 using namespace util; 00093 T b = nicol_minus_internal (prefixSumArray, length, procCount); 00094 if (cutIndexes != NULL) 00095 ParametricSearch<T,Pr>::probeCut (b, procCount-1, prefixSumArray,length,cutIndexes); 00096 return b; 00097 }