root/ompi/group/group_sporadic.c

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

DEFINITIONS

This source file includes following definitions.
  1. ompi_group_calc_sporadic
  2. ompi_group_translate_ranks_sporadic
  3. ompi_group_translate_ranks_sporadic_reverse
  4. ompi_group_incl_spor

   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 int ompi_group_calc_sporadic ( int n , const int *ranks)
  30 {
  31     int i,l=0;
  32     for (i=0 ; i<n ; i++) {
  33         if(ranks[i] == ranks[i-1]+1) {
  34             if(l==0) {
  35                 l++;
  36             }
  37         }
  38         else {
  39             l++;
  40         }
  41     }
  42     return sizeof(struct ompi_group_sporadic_list_t ) * l;
  43 }
  44 
  45 /* from parent group to child group*/
  46 int ompi_group_translate_ranks_sporadic ( ompi_group_t *parent_group,
  47                                           int n_ranks, const int *ranks1,
  48                                           ompi_group_t *child_group,
  49                                           int *ranks2)
  50 {
  51     int i,count,j;
  52     for (j=0 ; j<n_ranks ; j++) {
  53         if (MPI_PROC_NULL == ranks1[j]) {
  54             ranks2[j] = MPI_PROC_NULL;
  55         }
  56         else {
  57             /*
  58              * if the rank is in the current range of the sporadic list, we calculate
  59              * the rank in the child by adding the length of all ranges that we passed
  60              * and the position in the current range
  61              */
  62             ranks2[j] = MPI_UNDEFINED;
  63             count = 0;
  64             for(i=0 ; i <child_group->sparse_data.grp_sporadic.grp_sporadic_list_len ; i++) {
  65                 if( child_group->sparse_data.grp_sporadic.grp_sporadic_list[i].rank_first
  66                     <= ranks1[j] && ranks1[j] <=
  67                     child_group->sparse_data.grp_sporadic.grp_sporadic_list[i].rank_first +
  68                     child_group->sparse_data.grp_sporadic.grp_sporadic_list[i].length -1 ) {
  69 
  70                     ranks2[j] = ranks1[j] - child_group->
  71                         sparse_data.grp_sporadic.grp_sporadic_list[i].rank_first + count;
  72                     break;
  73                 }
  74                 else {
  75                     count = count + child_group->sparse_data.grp_sporadic.grp_sporadic_list[i].length;
  76                 }
  77             }
  78         }
  79     }
  80     return OMPI_SUCCESS;
  81 }
  82 /* from child group to parent group*/
  83 int ompi_group_translate_ranks_sporadic_reverse ( ompi_group_t *child_group,
  84                                                   int n_ranks, const int *ranks1,
  85                                                   ompi_group_t *parent_group,
  86                                                   int *ranks2)
  87 {
  88     int i,j,count;
  89 
  90     for (j=0 ; j<n_ranks ; j++) {
  91         if (MPI_PROC_NULL == ranks1[j]) {
  92             ranks2[j] = MPI_PROC_NULL;
  93         }
  94         else {
  95             count = 0;
  96             /*
  97              * if the rank of the child is in the current range, the rank of the parent will be
  98              * the position in the current range of the sporadic list
  99              */
 100             for (i=0 ; i<child_group->sparse_data.grp_sporadic.grp_sporadic_list_len ; i++) {
 101                 if ( ranks1[j] > ( count +
 102                                    child_group->sparse_data.grp_sporadic.grp_sporadic_list[i].length
 103                                    - 1) ) {
 104                     count = count + child_group->sparse_data.grp_sporadic.grp_sporadic_list[i].length;
 105                 }
 106                 else {
 107                     ranks2[j] = child_group->sparse_data.grp_sporadic.grp_sporadic_list[i].rank_first
 108                         + (ranks1[j] - count);
 109                     break;
 110                 }
 111             }
 112         }
 113     }
 114     return OMPI_SUCCESS;
 115 }
 116 
 117 int ompi_group_incl_spor(ompi_group_t* group, int n, const int *ranks,
 118                          ompi_group_t **new_group)
 119 {
 120     /* local variables */
 121     int my_group_rank,l,i,j,proc_count;
 122     ompi_group_t *group_pointer, *new_group_pointer;
 123 
 124     group_pointer = (ompi_group_t *)group;
 125 
 126     if (0 == n) {
 127         *new_group = MPI_GROUP_EMPTY;
 128         OBJ_RETAIN(MPI_GROUP_EMPTY);
 129         return OMPI_SUCCESS;
 130     }
 131 
 132     l=0;
 133     j=0;
 134     proc_count = 0;
 135 
 136     for(i=0 ; i<n ; i++){
 137         if(ranks[i] == ranks[i-1]+1) {
 138             if(l==0) {
 139                 l++;
 140             }
 141         }
 142         else {
 143             l++;
 144         }
 145     }
 146 
 147     new_group_pointer = ompi_group_allocate_sporadic(l);
 148     if( NULL == new_group_pointer ) {
 149         return MPI_ERR_GROUP;
 150     }
 151 
 152     new_group_pointer ->
 153         sparse_data.grp_sporadic.grp_sporadic_list[j].rank_first = ranks[0];
 154     new_group_pointer ->
 155         sparse_data.grp_sporadic.grp_sporadic_list[j].length = 1;
 156 
 157     for(i=1 ; i<n ; i++){
 158         if(ranks[i] == ranks[i-1]+1) {
 159             new_group_pointer -> sparse_data.grp_sporadic.grp_sporadic_list[j].length ++;
 160         }
 161         else {
 162             j++;
 163             new_group_pointer ->
 164                 sparse_data.grp_sporadic.grp_sporadic_list[j].rank_first = ranks[i];
 165             new_group_pointer ->
 166                 sparse_data.grp_sporadic.grp_sporadic_list[j].length = 1;
 167         }
 168     }
 169 
 170     new_group_pointer->sparse_data.grp_sporadic.grp_sporadic_list_len = j+1;
 171     new_group_pointer -> grp_parent_group_ptr = group_pointer;
 172 
 173     OBJ_RETAIN(new_group_pointer -> grp_parent_group_ptr);
 174     ompi_group_increment_proc_count(new_group_pointer -> grp_parent_group_ptr);
 175 
 176     for(i=0 ; i<new_group_pointer->sparse_data.grp_sporadic.grp_sporadic_list_len ; i++) {
 177         proc_count = proc_count + new_group_pointer ->
 178             sparse_data.grp_sporadic.grp_sporadic_list[i].length;
 179     }
 180     new_group_pointer->grp_proc_count = proc_count;
 181 
 182     ompi_group_increment_proc_count(new_group_pointer);
 183     my_group_rank=group_pointer->grp_my_rank;
 184 
 185     ompi_group_translate_ranks (group_pointer,1,&my_group_rank,
 186                                 new_group_pointer,&new_group_pointer->grp_my_rank);
 187 
 188     *new_group = (MPI_Group)new_group_pointer;
 189 
 190     return OMPI_SUCCESS;
 191 }

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