root/ompi/mpi/c/group_range_incl.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Group_range_incl

   1 /*
   2  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2006      University of Houston. All rights reserved.
  13  * Copyright (c) 2006-2012 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2015      Research Organization for Information Science
  15  *                         and Technology (RIST). All rights reserved.
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 #include "ompi_config.h"
  23 #include <stdio.h>
  24 
  25 #include "ompi/mpi/c/bindings.h"
  26 #include "ompi/runtime/params.h"
  27 #include "ompi/group/group.h"
  28 #include "ompi/errhandler/errhandler.h"
  29 #include "ompi/communicator/communicator.h"
  30 
  31 #if OMPI_BUILD_MPI_PROFILING
  32 #if OPAL_HAVE_WEAK_SYMBOLS
  33 #pragma weak MPI_Group_range_incl = PMPI_Group_range_incl
  34 #endif
  35 #define MPI_Group_range_incl PMPI_Group_range_incl
  36 #endif
  37 
  38 static const char FUNC_NAME[] = "MPI_Group_range_incl";
  39 
  40 
  41 int MPI_Group_range_incl(MPI_Group group, int n_triplets, int ranges[][3],
  42                          MPI_Group *new_group)
  43 {
  44     int err, i,indx;
  45     int group_size;
  46     int * elements_int_list;
  47 
  48     /* can't act on NULL group */
  49     if( MPI_PARAM_CHECK ) {
  50         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  51 
  52         if ( (MPI_GROUP_NULL == group) || (NULL == group) ||
  53              (NULL == new_group) ) {
  54             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
  55                                           FUNC_NAME);
  56         }
  57 
  58         group_size = ompi_group_size ( group);
  59         elements_int_list = (int *) malloc(sizeof(int) * (group_size+1));
  60         if (NULL == elements_int_list) {
  61             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_OTHER, FUNC_NAME);
  62         }
  63         for (i = 0; i < group_size; i++) {
  64             elements_int_list[i] = -1;
  65         }
  66 
  67         for ( i=0; i < n_triplets; i++) {
  68             if ((0 > ranges[i][0]) || (ranges[i][0] > group_size)) {
  69                 goto error_rank;
  70             }
  71             if ((0 > ranges[i][1]) || (ranges[i][1] > group_size)) {
  72                 goto error_rank;
  73             }
  74             if (ranges[i][2] == 0) {
  75                 goto error_rank;
  76             }
  77 
  78             if ((ranges[i][0] < ranges[i][1])) {
  79                 if (ranges[i][2] < 0) {
  80                     goto error_rank;
  81                 }
  82                 /* positive stride */
  83                 for (indx = ranges[i][0]; indx <= ranges[i][1]; indx += ranges[i][2]) {
  84                     /* make sure rank has not already been selected */
  85                     if (elements_int_list[indx] != -1) {
  86                         goto error_rank;
  87                     }
  88                     elements_int_list[indx] = i;
  89                 }
  90             } else if (ranges[i][0] > ranges[i][1]) {
  91                 if (ranges[i][2] > 0) {
  92                     goto error_rank;
  93                 }
  94                 /* negative stride */
  95                 for (indx = ranges[i][0]; indx >= ranges[i][1]; indx += ranges[i][2]) {
  96                     /* make sure rank has not already been selected */
  97                     if (elements_int_list[indx] != -1) {
  98                         goto error_rank;
  99                     }
 100                     elements_int_list[indx] = i;
 101                 }
 102             } else {
 103                 /* first_rank == last_rank */
 104                 indx = ranges[i][0];
 105                 if (elements_int_list[indx] != -1) {
 106                     goto error_rank;
 107                 }
 108                 elements_int_list[indx] = i;
 109             }
 110         }
 111 
 112         free ( elements_int_list);
 113     }
 114 
 115     OPAL_CR_ENTER_LIBRARY();
 116 
 117     err = ompi_group_range_incl ( group, n_triplets, ranges, new_group );
 118     OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD, err, FUNC_NAME );
 119 
 120 error_rank:
 121     free(elements_int_list);
 122     return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK, FUNC_NAME);
 123 }

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