bsp_mesgqueue.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 
00033 #ifndef BSP_MESGQUEUE_H
00034 #define BSP_MESGQUEUE_H
00035 #include "bsp_exptable.h"
00036 #include <config.h>
00037 
00043 static inline void
00044 messageQueue_initialize (ExpandableTable * restrict table, const int rows)
00045 {
00046   union SpecInfo info;
00047   info.mesgq.tag_size = 0;
00048   info.mesgq.slot_offset = 0;
00049   info.mesgq.inslot_offset = 0;
00050   info.mesgq.n_mesg_deq = 0;
00051   info.mesgq.n_mesg = 0;
00052   info.mesgq.accum_size = 0;
00053   varElSizeTable_initialize (table, 1, rows, info);
00054 }
00055 
00059 static inline void
00060 messageQueue_destruct (ExpandableTable * restrict table)
00061 {
00062   expandableTable_destruct (table);
00063 }
00064 
00068 static inline void
00069 messageQueue_reset( ExpandableTable * restrict table)
00070 {
00071   table->info.mesgq.slot_offset = 0;
00072   table->info.mesgq.inslot_offset = 0;
00073   table->info.mesgq.n_mesg_deq=0;
00074   table->info.mesgq.n_mesg = 0;
00075   table->info.mesgq.accum_size = 0;
00076   expandableTable_reset(table);
00077 }  
00078 
00083 static inline void
00084 messageQueue_expand (ExpandableTable * restrict table, const int rows)
00085 {
00086   expandableTable_expand (table, rows, table->info);
00087 }
00088 
00096 static inline void
00097 messageQueue_push (ExpandableTable * restrict table, char * restrict data, int size)
00098 {
00099   int free_space = table->rows - table->used_slot_count[0];
00100   VarSizeElement * restrict pointer ;
00101   size = no_slots(size, sizeof(VarSizeElement));
00102 
00103   if (size > free_space) 
00104     messageQueue_expand(table, MAX(table->rows * 2, size));
00105 
00106   pointer =  (VarSizeElement *) table->data + table->used_slot_count[0];
00107   memcpy(pointer, data, size * sizeof(VarSizeElement));
00108   
00109   table->info.mesgq.accum_size+=pointer->info.send.payload_size * pointer->info.send.item_count;
00110   table->info.mesgq.n_mesg += pointer->info.send.item_count;
00111   table->used_slot_count[0]+=size;
00112   table->count[0]++;
00113 }
00114 
00121 static inline int
00122 messageQueue_setTagSize (ExpandableTable * restrict table, const int tag_size)
00123 {
00124   const int a = table->info.mesgq.tag_size;
00125   table->info.mesgq.tag_size = tag_size;
00126   return a;
00127 }
00128 
00132 static inline int
00133 messageQueue_getTagSize (const ExpandableTable * restrict table)
00134 {
00135   return table->info.mesgq.tag_size;
00136 }
00137 
00138 /* Query number of messages in queue
00139   @param table Reference to MessageQueue
00140   @return Number of messages in queue
00141   */
00142 static inline int
00143 messageQueue_getNumber (const ExpandableTable * restrict table)
00144 {
00145    return table->info.mesgq.n_mesg - table->info.mesgq.n_mesg_deq;
00146 }
00147 
00152 static inline int
00153 messageQueue_getAccumSize (const ExpandableTable * restrict table)
00154 {
00155   return table->info.mesgq.accum_size;
00156 }
00157 
00164 static inline int
00165 messageQueue_getTag (ExpandableTable * restrict table, void * restrict tag)
00166 {
00167   VarSizeElement * restrict element = (VarSizeElement *) table->data + table->info.mesgq.slot_offset;
00168   int subslot = 
00169     table->info.mesgq.inslot_offset * (element->info.send.tag_size + element->info.send.payload_size);
00170   
00171   memcpy (tag, (char *) (element + 1) + subslot, element->info.send.tag_size);
00172   return element->info.send.payload_size;
00173 }
00174 
00183 static inline int
00184 messageQueue_dequeue (ExpandableTable * restrict table, void * restrict payload, int size)
00185 {
00186   VarSizeElement * restrict element = (VarSizeElement *) table->data + table->info.mesgq.slot_offset;
00187   int subslot = 
00188     table->info.mesgq.inslot_offset * 
00189       (element->info.send.tag_size + element->info.send.payload_size) +
00190        element->info.send.tag_size;
00191 
00192   size = MIN (size, element->info.send.payload_size);
00193   memcpy (payload, (char *) (element + 1) + subslot, size);
00194   
00195   table->info.mesgq.inslot_offset++;
00196   table->info.mesgq.slot_offset += 
00197     (table->info.mesgq.inslot_offset / element->info.send.item_count) *
00198      no_slots(sizeof (VarSizeElement) + element->size, sizeof(VarSizeElement));
00199   table->info.mesgq.inslot_offset %= element->info.send.item_count;
00200 
00201   table->info.mesgq.n_mesg_deq++;
00202   table->info.mesgq.accum_size -= element->info.send.payload_size;
00203   return size;
00204 }
00205 
00213 static inline int
00214 messageQueue_hpdequeue (ExpandableTable * restrict table, const void ** const tag,
00215                         const void ** const payload)
00216 {
00217   VarSizeElement * restrict element = (VarSizeElement *) table->data + table->info.mesgq.slot_offset;
00218   int subslot = 
00219     table->info.mesgq.inslot_offset * 
00220       (element->info.send.tag_size + element->info.send.payload_size) ;
00221   char * restrict data = (char*) (element + 1) + subslot ;
00222 
00223   *tag = data;
00224   *payload = (char *) data + element->info.send.tag_size;
00225   
00226   table->info.mesgq.inslot_offset++;
00227   table->info.mesgq.slot_offset += 
00228     (table->info.mesgq.inslot_offset / element->info.send.item_count) *
00229      no_slots(sizeof (VarSizeElement) + element->size, sizeof(VarSizeElement));
00230   table->info.mesgq.inslot_offset %= element->info.send.item_count;
00231 
00232   table->info.mesgq.n_mesg_deq++;
00233   table->info.mesgq.accum_size -= element->info.send.payload_size;
00234   return element->info.send.payload_size;
00235 }
00236 
00237 #endif

Generated on Sat Apr 8 12:56:54 2006 for BSPonMPI by  doxygen 1.4.6