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 #ifndef BSP_DELIVTABLE_H
00028 #define BSP_DELIVTABLE_H
00029
00068 #include "bsp_exptable.h"
00069 #include "bsp_mesgqueue.h"
00070 #include <config.h>
00071
00072 void
00073 deliveryTable_execute (ExpandableTable *restrict , ExpandableTable *restrict ,
00074 MessageQueue *restrict, const int );
00075
00082 static inline void
00083 deliveryTable_initialize (ExpandableTable * restrict table, const int nprocs, const int rows)
00084 {
00085 union SpecInfo info;
00086 int p;
00087 const int index_size =
00088 no_slots(3 * 6 * sizeof(unsigned int), sizeof(ALIGNED_TYPE));
00089
00090
00091 info.deliv.count = bsp_malloc( nprocs, sizeof(unsigned int *));
00092 info.deliv.start = bsp_malloc( nprocs, sizeof(unsigned int *));
00093 info.deliv.end = bsp_malloc(nprocs, sizeof(unsigned int *));
00094 expandableTable_initialize (table, nprocs, rows + index_size , sizeof(ALIGNED_TYPE), info);
00095
00096
00097 for (p = 0; p < nprocs; p++)
00098 {
00099 table->info.deliv.start[p] = (unsigned int *)
00100 ((char *) table->data + p * table->rows * sizeof(ALIGNED_TYPE)) ;
00101 table->info.deliv.count[p] = (unsigned int *)
00102 ((char *) table->data + p * table->rows * sizeof(ALIGNED_TYPE)) + 6 ;
00103 table->info.deliv.end[p] = (unsigned int *)
00104 ((char *) table->data + p * table->rows * sizeof(ALIGNED_TYPE)) + 12 ;
00105
00106 memset((ALIGNED_TYPE *) table->data + p * table->rows , 0, sizeof(ALIGNED_TYPE) * index_size );
00107
00108 table->used_slot_count[p] = index_size;
00109 }
00110 }
00111
00115 static inline void
00116 deliveryTable_reset(ExpandableTable * restrict table)
00117 {
00118
00119 int p;
00120 const int index_size =
00121 no_slots(3 * 6 * sizeof(unsigned int), sizeof(ALIGNED_TYPE));
00122
00123 expandableTable_reset(table);
00124 for (p = 0; p < table->nprocs; p++)
00125 {
00126 memset((ALIGNED_TYPE *) table->data + p * table->rows , 0, sizeof(ALIGNED_TYPE) * index_size );
00127 table->used_slot_count[p] = index_size;
00128 }
00129
00130 }
00131
00134 static inline void
00135 deliveryTable_destruct (ExpandableTable * restrict table)
00136 {
00137 bsp_free(table->info.deliv.start);
00138 bsp_free(table->info.deliv.count);
00139 bsp_free(table->info.deliv.end);
00140 expandableTable_destruct (table);
00141 }
00142
00148 static inline void
00149 deliveryTable_expand (ExpandableTable * restrict table, const int rows)
00150 {
00151 int p;
00152
00153 expandableTable_expand (table, rows, table->info);
00154
00155 for (p = 0; p < table->nprocs; p++)
00156 {
00157 table->info.deliv.start[p] = (unsigned int *)
00158 ((char *) table->data + p * table->rows * sizeof(ALIGNED_TYPE)) ;
00159 table->info.deliv.count[p] = (unsigned int *)
00160 ((char *) table->data + p * table->rows * sizeof(ALIGNED_TYPE)) + 6 ;
00161 table->info.deliv.end[p] = (unsigned int *)
00162 ((char *) table->data + p * table->rows * sizeof(ALIGNED_TYPE)) + 12 ;
00163 }
00164 }
00165
00166
00175 static inline void *
00176 deliveryTable_push (ExpandableTable *restrict table, const int proc,
00177 const DelivElement element, const ItemType type)
00178 {
00179
00180
00181
00182 const unsigned int slot_size = sizeof(ALIGNED_TYPE);
00183 const unsigned int tag_size = no_slots(sizeof(DelivElement), slot_size);
00184 const unsigned int object_size = tag_size + no_slots(element.size, slot_size);
00185 ALIGNED_TYPE * restrict pointer;
00186
00187 int free_space = table->rows - table->used_slot_count[proc];
00188
00189 if (object_size > free_space)
00190 {
00191 int space_needed = MAX(table->rows, object_size - free_space);
00192 deliveryTable_expand(table, space_needed);
00193 }
00194
00195
00196 if (table->info.deliv.count[proc][type] == 0)
00197 table->info.deliv.start[proc][type] = table->used_slot_count[proc];
00198 else
00199 {
00200 pointer = (ALIGNED_TYPE *) table->data + table->info.deliv.end[proc][type] + proc * table->rows;
00201 ((DelivElement *) pointer)->next = table->used_slot_count[proc] - table->info.deliv.end[proc][type];
00202 }
00203
00204 table->info.deliv.end[proc][type] = table->used_slot_count[proc];
00205 table->info.deliv.count[proc][type]++;
00206
00207 pointer = (ALIGNED_TYPE *) table->data + table->used_slot_count[proc] + proc * table->rows;
00208 * (DelivElement *) pointer = element;
00209 pointer+=tag_size;
00210
00211 table->used_slot_count[proc] += object_size;
00212
00213 return pointer ;
00214 }
00215
00216
00217
00218 #endif