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_EXPTABLE_H
00028 #define BSP_EXPTABLE_H
00029
00038 #define ALIGNED_TYPE double
00039
00041 #define MAX(x,y) ( ((x) > (y))?(x):(y))
00042
00044 #define MIN(x,y) ( ((x) < (y))?(x):(y))
00045
00046 #include <stdlib.h>
00047 #include <memory.h>
00048 #include "bsp_alloc.h"
00049
00050 #ifdef UNITTESTING
00051 #include "../tests/bsp_test.h"
00052 #else
00053 #include <mpi.h>
00054 #endif
00055
00056 #include <config.h>
00057
00062 inline static int no_slots(const int bytes, const int slot_size)
00063 {
00064 return (bytes + slot_size - 1) / slot_size;
00065 }
00066
00074 inline static unsigned int
00075 max(const unsigned int * restrict array, const int n, const int stride)
00076 {
00077 int i;
00078 unsigned int result = 0;
00079 for (i = 0; i < n; i+=stride)
00080 result = MAX(array[i], result);
00081 return result ;
00082 }
00083
00084
00089 typedef char * MemRegElement;
00090
00092 typedef struct
00093 {
00094 int numremov;
00095 int * restrict removed;
00096 int memoized_src_proc;
00097 const MemRegElement * memoized_data_iter;
00098 const MemRegElement * memoized_end;
00099 int memoized_srccol;
00100 } MemRegInfo;
00104 typedef struct
00105 {
00108 unsigned int * restrict data_sizes;
00109 } ReqInfo;
00110
00111
00116 typedef struct
00117 {
00119 int size;
00121 int offset;
00123 char *src;
00125 char *dst;
00126 } ReqElement;
00132 typedef enum _ItemType
00133 { popreg, pushreg, put, get, send, settag } ItemType;
00134
00136 typedef struct
00137 {
00139 char * dst;
00140 } PutObject;
00141
00143 typedef struct
00144 {
00145 unsigned int payload_size;
00146 } SendObject;
00147
00149 typedef struct
00150 {
00152 const char *address;
00153 } PushRegObject;
00154
00156 typedef struct
00157 {
00159 const char *address;
00160 } PopRegObject;
00161
00163 typedef struct
00164 {
00166 int tag_size;
00167 } SetTagObject;
00168
00170 union _DInfo
00171 {
00172 PutObject put;
00173 SendObject send;
00174 PushRegObject push;
00175 PopRegObject pop;
00176 SetTagObject settag;
00177 } ;
00178
00180 typedef struct
00181 {
00182 unsigned int size;
00183 unsigned int next;
00184 union _DInfo info;
00185 } DelivElement;
00189 typedef struct
00190 {
00193 unsigned int * * restrict start;
00194
00197 unsigned int * * restrict count;
00198
00201 unsigned int * * restrict end;
00202 } DelivInfo;
00203
00205 union SpecInfo
00206 {
00207 MemRegInfo reg;
00208 DelivInfo deliv;
00209 ReqInfo req;
00210 };
00211
00214
00219 typedef struct _ExpandableTable
00220 {
00221 unsigned int nprocs;
00222 unsigned int rows;
00225 unsigned int * restrict used_slot_count;
00227 unsigned int slot_size;
00228
00230 union SpecInfo info;
00231
00233 char *data;
00234 } ExpandableTable;
00235
00236
00237 void
00238 expandableTable_comm (const ExpandableTable * restrict send,
00239 ExpandableTable * restrict recv, MPI_Comm communicator );
00240
00241
00242
00243
00244
00245
00246
00247
00248 static inline void
00249 expandableTable_initialize (ExpandableTable * restrict table,
00250 const unsigned int nprocs, const unsigned int rows,
00251 const int unsigned elsize, const union SpecInfo info)
00252 {
00253 table->nprocs = nprocs;
00254 table->rows = rows;
00255 table->slot_size = elsize;
00256 table->info = info;
00257 table->data = bsp_malloc (nprocs * rows, elsize);
00258
00259 table->used_slot_count = bsp_calloc (nprocs, sizeof (unsigned int));
00260 }
00261
00265 static inline void
00266 expandableTable_reset (ExpandableTable * restrict table)
00267 {
00268 memset (table->used_slot_count, 0, sizeof (unsigned int) * table->nprocs);
00269 }
00270
00274 static inline void
00275 expandableTable_destruct (ExpandableTable * restrict table)
00276 {
00277 bsp_free (table->data);
00278 bsp_free (table->used_slot_count);
00279 }
00280
00287 static inline void
00288 expandableTable_expand (ExpandableTable * restrict table, const unsigned int rows,
00289 const union SpecInfo newinfo)
00290 {
00291 unsigned int newrows = rows + table->rows;
00292 char *newdata =
00293 bsp_malloc( newrows * table->nprocs, table->slot_size);
00294 int i;
00295
00296 for (i = 0; i < table->nprocs; i++)
00297 memcpy( newdata + i * newrows * table->slot_size,
00298 table->data + i * table->rows * table->slot_size,
00299 table->used_slot_count[i] * table->slot_size);
00300
00301 bsp_free(table->data);
00302 table->data = newdata;
00303 table->rows = newrows;
00304 table->info = newinfo;
00305 }
00320 static inline void
00321 fixedElSizeTable_initialize (ExpandableTable * restrict table, const unsigned int nprocs,
00322 const unsigned int rows, const unsigned int elsize,
00323 const union SpecInfo info)
00324 {
00325 expandableTable_initialize (table, nprocs, rows, elsize, info);
00326 }
00327
00337 static inline void
00338 fixedElSizeTable_push (ExpandableTable * restrict table, const unsigned int proc,
00339 void (*changeinfo) (union SpecInfo *restrict, unsigned int, unsigned int),
00340 const void *restrict element)
00341 {
00342 int j;
00343
00344
00345 if (table->used_slot_count[proc] == table->rows)
00346 {
00347 union SpecInfo info = table->info;
00348 (*changeinfo) (&info, table->rows, 2*table->rows );
00349 expandableTable_expand (table, table->rows , info);
00350 }
00351
00352
00353 j = table->used_slot_count[proc] + proc * table->rows;
00354 memcpy (table->data + j * table->slot_size,
00355 element, table->slot_size);
00356
00357 table->used_slot_count[proc] ++;
00358 }
00361 #endif