bsp_delivtable.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_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   /* allocate memory */
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   /* point the pointers to the correct places: the top each column */
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        /* don't overwrite this information */
00108        table->used_slot_count[p] = index_size;   
00109      }  
00110 }
00111 
00115 static inline void
00116 deliveryTable_reset(ExpandableTable * restrict table)
00117 {
00118   /* reset the index */
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 /* the percentages before a line refer to the costs of a line. These costs are
00180  * measured by the gnu profiler while running bspbench. This function is again
00181  * the most expensive function */
00182   const unsigned int slot_size = sizeof(ALIGNED_TYPE);
00183   const unsigned int tag_size = no_slots(sizeof(DelivElement), slot_size);
00184 /* 1.05% */  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 /* 1.57 */ 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   /* manage deliveryTable info */
00196   if (table->info.deliv.count[proc][type] == 0)
00197 /*1.84 */ table->info.deliv.start[proc][type] = table->used_slot_count[proc];
00198   else
00199     {
00200 /* 2.62% */  pointer = (ALIGNED_TYPE *) table->data + table->info.deliv.end[proc][type] + proc * table->rows;
00201 /* 5.25% */ ((DelivElement *) pointer)->next = table->used_slot_count[proc] - table->info.deliv.end[proc][type];
00202     }
00203  
00204 /* 3.41% */  table->info.deliv.end[proc][type] = table->used_slot_count[proc];
00205 /* 3.28% */  table->info.deliv.count[proc][type]++;
00206   
00207 /* 6.56% */ pointer = (ALIGNED_TYPE *) table->data + table->used_slot_count[proc] + proc * table->rows;
00208 /* 5.12% */  * (DelivElement *) pointer = element;
00209   pointer+=tag_size;
00210   /* increment counters */
00211 /*4.99%*/  table->used_slot_count[proc] += object_size;
00212 
00213   return pointer ;  
00214 }
00215 
00216 
00217 
00218 #endif

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