bsp_memreg.c

Go to the documentation of this file.
00001 /*
00002     BSPonMPI. This is an implementation of the BSPlib standard on top of MPI
00003     Copyright (C) 2006  Wijnand J. Suijlen
00004                                                                                 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2.1 of the License, or (at your option) any later version.
00009                                                                                 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014                                                                                 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018                                                                                 
00019     You may contact me via electronic mail:
00020       wjsuijle@users.sourceforge.net
00021     or snail mail:
00022       W.J. Suijlen
00023       Kraaiheidelaan 10
00024       2803 VP Gouda
00025       The Netherlands
00026 */
00027 
00032 #include "bsp_abort.h"
00033 #include "bsp_memreg.h"
00034 #include "bsp_alloc.h"
00035 
00042 void
00043 memoryRegister_initialize (ExpandableTable * restrict table, const unsigned int nprocs, 
00044                            const unsigned int rows, const unsigned int src_proc)
00045 {
00046   union SpecInfo info;
00047   info.reg.removed = bsp_calloc (rows, sizeof (int));
00048   info.reg.numremov = 0;
00049   info.reg.memoized_data_iter = NULL;
00050   info.reg.memoized_end = NULL;
00051   info.reg.memoized_srccol=0;
00052   info.reg.memoized_src_proc = src_proc;
00053   fixedElSizeTable_initialize (table, nprocs, rows, sizeof (MemRegElement), info);
00054 }
00055 
00059 void
00060 memoryRegister_destruct (ExpandableTable * restrict table)
00061 {
00062   bsp_free(table->info.reg.removed);
00063   expandableTable_destruct (table);
00064 }
00065 
00070 void
00071 memoryRegister_expand (ExpandableTable * restrict table, const unsigned int rows)
00072 {
00073   union SpecInfo info;
00074   int *newremoved = bsp_calloc (rows + table->rows, sizeof (int));
00075   int i;
00076   for (i = 0 ; i < table->rows; i++) // copy old values
00077     newremoved[i] = table->info.reg.removed[i];
00078   bsp_free(newremoved);
00079   info.reg.removed = newremoved;
00080   info.reg.numremov = table->info.reg.numremov;
00081   info.reg.memoized_data_iter = NULL;// , should be calculated
00082   info.reg.memoized_end=NULL; // , should be calculated
00083   info.reg.memoized_srccol =
00084     table->info.reg.memoized_src_proc * (rows + table->rows);
00085   info.reg.memoized_src_proc = table->info.reg.memoized_src_proc;
00086 
00087   expandableTable_expand (table, rows, info);
00088 }
00089 
00095 static void
00096 newMemRegInfoAtPush (union SpecInfo * restrict info, unsigned int rows, unsigned int newrows)
00097 {
00098   int *newremoved = bsp_calloc(newrows, sizeof(int));
00099   int i;
00100   for (i = 0; i < rows; i ++)
00101     newremoved[i] = info->reg.removed[i];
00102   bsp_free(info->reg.removed);
00103   info->reg.removed = newremoved;
00104   
00105   info->reg.memoized_data_iter = NULL;
00106   info->reg.memoized_end = NULL;
00107   info->reg.memoized_srccol=0;
00108   //  info->reg.numremov = stays the same ;
00109 }
00110 
00116 void 
00117 memoryRegister_push (ExpandableTable *restrict table, const unsigned int proc, 
00118                      const char * const restrict pointer)
00119 {
00120   table->info.reg.memoized_data_iter = NULL;
00121 
00122   fixedElSizeTable_push (table, proc, &newMemRegInfoAtPush, &pointer);
00123 }
00124 
00130 void
00131 memoryRegister_pop (ExpandableTable * restrict table, const unsigned int proc,
00132                      const char * const restrict pointer)
00133 {
00134   int count, col;
00135   const MemRegElement * restrict array;
00136   
00137   table->info.reg.memoized_data_iter = NULL;
00138   
00139   col = table->rows * proc;
00140   array = (MemRegElement *) table->data + col;
00141   for (count = table->used_slot_count[proc]-1; count >= 0; count--)
00142     {
00143        if (array[count] == pointer && !table->info.reg.removed[count])
00144          {
00145            table->info.reg.removed[count] = 1;
00146            table->info.reg.numremov++;
00147            return;
00148          }
00149     }
00150   bsp_intern_abort (ERR_POP_REG_WITHOUT_PUSH, __func__, __FILE__,__LINE__);
00151   return;
00152 }
00153 
00158 void
00159 memoryRegister_pack (ExpandableTable * restrict table)
00160 {
00161   int i, count = 0, j;
00162   unsigned int displ;
00163   MemRegElement * restrict array;
00164 
00165   /* count */
00166   count = table->used_slot_count[0] - table->info.reg.numremov; 
00167   
00168   /* allocate memory and copy data */
00169   for (i = 0; i < table->nprocs; i++)   // set newcount & newbytecount
00170     {
00171       displ = 0;
00172       array = (MemRegElement *) table->data + i * table->rows;
00173       for (j = 0; j < table->used_slot_count[i]; j++)
00174         {
00175           if ( table->info.reg.removed[j] )
00176             {
00177               displ++;
00178               continue;
00179             }  
00180           array[j - displ] = array[j];
00181         }
00182       table->used_slot_count[i] = count ;
00183     }
00184    
00185   memset(table->info.reg.removed, 0, sizeof(int) * table->rows);
00186   table->info.reg.numremov = 0;
00187  
00188   /* set memoized variables */
00189   //  table->info.reg.memoized_src_proc stays the same
00190   table->info.reg.memoized_srccol =
00191     table->rows * table->info.reg.memoized_src_proc;
00192   table->info.reg.memoized_end = 
00193     ((MemRegElement *) table->data) + table->info.reg.memoized_srccol;
00194   table->info.reg.memoized_data_iter =
00195     table->info.reg.memoized_end 
00196       + table->used_slot_count[table->info.reg.memoized_src_proc] -1;
00197 }
00198 
00199 

Generated on Sat Apr 8 20:12:29 2006 for BSPonMPI by  doxygen 1.4.6