bsp_exptable.h

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 #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 /* intializes an ExpandableTable object
00242    @param table Reference to an ExpandableTable object
00243    @param nprocs Number of processors you have / columns you want to have
00244    @param rows Number of rows to allocate 
00245    @param elsize Slot size in bytes
00246    @param info Object specific info
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   /* add table if necessary */
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   /* add pointer */
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

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