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 #include <twod/uniform_2d.hpp> 00038 #include <math.h> 00039 00040 template <typename T, typename Pr> 00041 T twod::Uniform<T, Pr>::part(int procCount, const Pr& prefixSumArray, util::RectList<T,Pr> &parts) 00042 { 00043 using namespace util; 00044 rectangle r; 00045 int x_parts; 00046 if (P==0) 00047 { 00048 x_parts = intfactor(procCount); 00049 } 00050 else 00051 { 00052 x_parts = P; 00053 } 00054 00055 00056 int y_parts = procCount / x_parts; 00057 00058 assert (x_parts>0); 00059 assert (x_parts<=procCount); 00060 assert (y_parts>0); 00061 assert (y_parts<=procCount); 00062 00063 double len_x_part = ((double)(prefixSumArray.prefixsizeX() - 1)) / x_parts; 00064 double len_y_part = ((double)(prefixSumArray.prefixsizeY() - 1)) / y_parts; 00065 int i,j; 00066 00067 int xl = 1; 00068 int xh; 00069 int yl; 00070 int yh; 00071 00072 for(i=1;i<=x_parts;i++) 00073 { 00074 if (i == x_parts) //to avoid rounding issues 00075 xh = prefixSumArray.prefixsizeX() - 1; 00076 else 00077 xh = (int) round(i*len_x_part); 00078 yl = 1; 00079 for(j=1;j<=y_parts;j++) 00080 { 00081 if (j == y_parts) //to avoid rounding issues 00082 yh = prefixSumArray.prefixsizeY() - 1; 00083 else 00084 yh = (int) round(j*len_y_part); 00085 00086 parts.add_rect( rectangle(xl,xh,yl,yh) ); 00087 yl = yh + 1; 00088 } 00089 xl = xh + 1; 00090 } 00091 00092 return parts.get_maximum_load(); 00093 }