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
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++)
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;
00082 info.reg.memoized_end=NULL;
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
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
00166 count = table->used_slot_count[0] - table->info.reg.numremov;
00167
00168
00169 for (i = 0; i < table->nprocs; i++)
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
00189
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