bsp_exptable.c

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 
00028 #include "bsp_exptable.h"
00029 #include "bsp_alloc.h"
00030 #include "bsp_abort.h"
00046 void
00047 expandableTable_comm (const ExpandableTable * restrict send, 
00048                       ExpandableTable *restrict  recv, MPI_Comm communicator)
00049 {
00050   int total_bytes_and_counts_to_send[2 * send->nprocs];
00051   int total_bytes_and_counts_to_recv[2 * send->nprocs];
00052   int recv_offset[send->nprocs], send_offset[send->nprocs];
00053   int recv_bytes[send->nprocs], send_bytes[send->nprocs];
00054   int max_slots_used, i;
00055   /* 
00056      index % 2 == 0 -> total used_slot_count in all tables
00057      index % 2 == 1 -> total count in all tables
00058   */
00059   for (i = 0; i < send->nprocs; i++)
00060     {
00061       total_bytes_and_counts_to_send[2 * i] = send->used_slot_count[i];
00062       total_bytes_and_counts_to_send[2 * i + 1] = send->count[i];
00063     }
00064   
00065     /* communicate this number */
00066   MPI_Alltoall (total_bytes_and_counts_to_send, 2, MPI_INT,
00067                 total_bytes_and_counts_to_recv, 2, MPI_INT, communicator);
00068 
00069   for (i = 0; i < send->nprocs; i++)
00070     {
00071       recv->used_slot_count[i] = total_bytes_and_counts_to_recv[2 * i] ;
00072       recv->count[i] = total_bytes_and_counts_to_recv[2 * i + 1];
00073     }
00074 
00075   /* Expand recv table if necessary */
00076   max_slots_used = 0;
00077   /* calc maximal recv bytes */
00078   for (i = 0; i < send->nprocs; i++)
00079     max_slots_used = MAX (max_slots_used, recv->used_slot_count[i]);
00080 
00081   if (max_slots_used > recv->rows)      /* received data too big for current table */
00082     {
00083       /* I reallocate the memory */
00084       bsp_free (recv->data);
00085       recv->data =
00086         bsp_malloc (recv->nprocs * max_slots_used *2, recv->slot_size);
00087       recv->rows = max_slots_used * 2;
00088     }
00089   /* now the recv table can contain the receiving data in whole */
00090 
00091   /* initalize recv offsets */
00092   for (i = 0; i < recv->nprocs; i++)
00093     {
00094       recv_offset[i] = i * recv->rows * recv->slot_size;
00095       send_offset[i] = i * send->rows * send->slot_size;
00096       send_bytes[i] = send->used_slot_count[i] * send->slot_size;
00097       recv_bytes[i] = recv->used_slot_count[i] * recv->slot_size;
00098     }
00099   /* the next thing to do is to walk the send table and actually send the 
00100    * data */
00101   
00102   MPI_Alltoallv (send->data, send_bytes, send_offset, MPI_BYTE,
00103       recv->data, recv_bytes, recv_offset, MPI_BYTE, communicator);
00104 }
00105 
00106 

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