root/ompi/group/group_bitmap.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ompi_group_calc_bmap
  2. ompi_group_translate_ranks_bmap
  3. ompi_group_translate_ranks_bmap_reverse
  4. ompi_group_div_ceil
  5. check_ranks
  6. ompi_group_incl_bmap

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2006-2007 University of Houston. All rights reserved.
  14  * Copyright (c) 2007      Cisco Systems, Inc. All rights reserved.
  15  * Copyright (c) 2013      Los Alamos National Security, LLC.  All rights
  16  *                         reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 #include "ompi_config.h"
  25 #include "ompi/group/group.h"
  26 #include "ompi/constants.h"
  27 #include "mpi.h"
  28 
  29 static bool check_ranks (int, const int *);
  30 
  31 int ompi_group_calc_bmap ( int n, int orig_size , const int *ranks) {
  32     if (check_ranks(n,ranks)) {
  33         return ompi_group_div_ceil(orig_size,BSIZE);
  34     }
  35     else {
  36         return -1;
  37     }
  38 }
  39 
  40 /* from parent group to child group*/
  41 int ompi_group_translate_ranks_bmap ( ompi_group_t *parent_group,
  42                                       int n_ranks, const int *ranks1,
  43                                       ompi_group_t *child_group,
  44                                       int *ranks2)
  45 {
  46     int i,count,j,k,m;
  47     unsigned char tmp, tmp1;
  48     for (j=0 ; j<n_ranks ; j++) {
  49         if ( MPI_PROC_NULL == ranks1[j]) {
  50             ranks2[j] = MPI_PROC_NULL;
  51         }
  52         else {
  53             ranks2[j] = MPI_UNDEFINED;
  54             m = ranks1[j];
  55             count = 0;
  56             tmp = ( 1 << (m % BSIZE) );
  57             /* check if the bit that correponds to the parent rank is set in the bitmap */
  58             if ( tmp == (child_group->sparse_data.grp_bitmap.grp_bitmap_array[(int)(m/BSIZE)]
  59                          & (1 << (m % BSIZE)))) {
  60                 /*
  61                  * add up how many bits are set, till we get to the bit of parent
  62                  * rank that we want. The rank in the child will be the sum of the bits
  63                  * that are set on the way till we get to the correponding bit
  64                  */
  65                 for (i=0 ; i<=(int)(m/BSIZE) ; i++) {
  66                     for (k=0 ; k<BSIZE ; k++) {
  67                         tmp1 = ( 1 << k);
  68                         if ( tmp1 == ( child_group->sparse_data.grp_bitmap.grp_bitmap_array[i]
  69                                        & (1 << k) ) ) {
  70                             count++;
  71                         }
  72                         if( i==(int)(m/BSIZE) &&  k==m % BSIZE ) {
  73                             ranks2[j] = count-1;
  74                             i = (int)(m/BSIZE) + 1;
  75                             break;
  76                         }
  77                     }
  78                 }
  79             }
  80         }
  81     }
  82     return OMPI_SUCCESS;
  83 }
  84 /* from child group to parent group */
  85 int ompi_group_translate_ranks_bmap_reverse ( ompi_group_t *child_group,
  86                                               int n_ranks, const int *ranks1,
  87                                               ompi_group_t *parent_group,
  88                                               int *ranks2)
  89 {
  90     int i,j,count,m,k;
  91     unsigned char tmp;
  92     for (j=0 ; j<n_ranks ; j++) {
  93         if ( MPI_PROC_NULL == ranks1[j]) {
  94             ranks2[j] = MPI_PROC_NULL;
  95         }
  96         else {
  97             m = ranks1[j];
  98             count = 0;
  99             /*
 100              * Go through all the bits set in the bitmap up to the child rank.
 101              * The parent rank will be the sum of all bits passed (set and unset)
 102              */
 103             for (i=0 ; i<child_group->sparse_data.grp_bitmap.grp_bitmap_array_len ; i++) {
 104                 for (k=0 ; k<BSIZE ; k++) {
 105                     tmp = ( 1 << k);
 106                     if ( tmp == ( child_group->sparse_data.grp_bitmap.grp_bitmap_array[i]
 107                                   & (1 << k) ) ) {
 108                         count++;
 109                     }
 110                     if( m == count-1 ) {
 111                         ranks2[j] = i*BSIZE + k;
 112                         i = child_group->sparse_data.grp_bitmap.grp_bitmap_array_len + 1;
 113                         break;
 114                     }
 115                 }
 116             }
 117         }
 118     }
 119     return OMPI_SUCCESS;
 120 }
 121 
 122 int ompi_group_div_ceil (int num, int den)
 123 {
 124     if (0 == num%den) {
 125         return num/den;
 126     }
 127     else {
 128         return (int)(num/den) + 1;
 129     }
 130 }
 131 /*
 132  * This functions is to check that all ranks in the included list of ranks
 133  * are monotonically increasing. If not, the bitmap format can not be used
 134  * since we won't be able to translate the ranks corrently since the algorithms
 135  * assume that the ranks are in order in the bitmap list.
 136  */
 137 static bool check_ranks (int n, const int *ranks) {
 138     int i;
 139     for (i=1 ; i < n ; i++) {
 140         if ( ranks[i-1] > ranks [i] ) {
 141             return false;
 142         }
 143     }
 144     return true;
 145 }
 146 
 147 int ompi_group_incl_bmap(ompi_group_t* group, int n, const int *ranks,
 148                          ompi_group_t **new_group)
 149 {
 150     /* local variables */
 151     int my_group_rank,i,bit_set;
 152     ompi_group_t *group_pointer, *new_group_pointer;
 153 
 154     group_pointer = (ompi_group_t *)group;
 155 
 156     if ( 0 == n ) {
 157         *new_group = MPI_GROUP_EMPTY;
 158         OBJ_RETAIN(MPI_GROUP_EMPTY);
 159         return OMPI_SUCCESS;
 160     }
 161 
 162     new_group_pointer = ompi_group_allocate_bmap(group->grp_proc_count, n);
 163     if( NULL == new_group_pointer ) {
 164         return MPI_ERR_GROUP;
 165     }
 166     /* Initialize the bit array to zeros */
 167     for (i=0 ; i<new_group_pointer->sparse_data.grp_bitmap.grp_bitmap_array_len ; i++) {
 168         new_group_pointer->
 169             sparse_data.grp_bitmap.grp_bitmap_array[i] = 0;
 170     }
 171 
 172     /* set the bits */
 173     for (i=0 ; i<n ; i++) {
 174         bit_set = ranks[i] % BSIZE;
 175         new_group_pointer->
 176             sparse_data.grp_bitmap.grp_bitmap_array[(int)(ranks[i]/BSIZE)] |= (1 << bit_set);
 177     }
 178 
 179     new_group_pointer -> grp_parent_group_ptr = group_pointer;
 180 
 181     OBJ_RETAIN(new_group_pointer -> grp_parent_group_ptr);
 182     ompi_group_increment_proc_count(new_group_pointer -> grp_parent_group_ptr);
 183 
 184     ompi_group_increment_proc_count(new_group_pointer);
 185     my_group_rank=group_pointer->grp_my_rank;
 186 
 187     ompi_group_translate_ranks (group_pointer,1,&my_group_rank,
 188                                 new_group_pointer,&new_group_pointer->grp_my_rank);
 189 
 190     *new_group = (MPI_Group)new_group_pointer;
 191 
 192     return OMPI_SUCCESS;
 193 }

/* [<][>][^][v][top][bottom][index][help] */