root/ompi/mpi/c/group_range_excl.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_Group_range_excl

   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_excl = PMPI_Group_range_excl
  34 #endif
  35 #define MPI_Group_range_excl PMPI_Group_range_excl
  36 #endif
  37 
  38 static const char FUNC_NAME[] = "MPI_Group_range_excl";
  39 
  40 
  41 int MPI_Group_range_excl(MPI_Group group, int n_triplets, int ranges[][3],
  42                          MPI_Group *new_group)
  43 {
  44     int err, i, group_size, indx;
  45     int * elements_int_list;
  46 
  47     /* can't act on NULL group */
  48     if( MPI_PARAM_CHECK ) {
  49         OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
  50         if ( (MPI_GROUP_NULL == group) || (NULL == group) ||
  51              (NULL == new_group) ) {
  52             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_GROUP,
  53                                           FUNC_NAME);
  54         }
  55 
  56         group_size = ompi_group_size ( group );
  57         elements_int_list = (int *) malloc(sizeof(int) * (group_size+1));
  58         if (NULL == elements_int_list) {
  59             return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_OTHER,
  60                                           FUNC_NAME);
  61         }
  62         for (i = 0; i < group_size; i++) {
  63             elements_int_list[i] = -1;
  64         }
  65 
  66         for (i = 0; i < n_triplets; i++) {
  67             if ((0 > ranges[i][0]) || (ranges[i][0] > group_size)) {
  68                 goto error_rank;
  69             }
  70             if ((0 > ranges[i][1]) || (ranges[i][1] > group_size)) {
  71                 goto error_rank;
  72             }
  73             if (ranges[i][2] == 0) {
  74                 goto error_rank;
  75             }
  76 
  77             if (ranges[i][0] < ranges[i][1]) {
  78                 if (ranges[i][2] < 0) {
  79                     goto error_rank;
  80                 }
  81                 /* positive stride */
  82                 for (indx = ranges[i][0]; indx <= ranges[i][1]; indx += ranges[i][2]) {
  83                     /* make sure rank has not already been selected */
  84                     if (elements_int_list[indx] != -1) {
  85                         goto error_rank;
  86                     }
  87                     elements_int_list[indx] = i;
  88                 }
  89             } else if (ranges[i][0] > ranges[i][1]) {
  90                 if (ranges[i][2] > 0) {
  91                     goto error_rank;
  92                 }
  93                 /* negative stride */
  94                 for (indx = ranges[i][0]; indx >= ranges[i][1]; indx += ranges[i][2]) {
  95                     /* make sure rank has not already been selected */
  96                     if (elements_int_list[indx] != -1) {
  97                         goto error_rank;
  98                     }
  99                     elements_int_list[indx] = i;
 100                 }
 101             } else {
 102                 /* first_rank == last_rank */
 103                 indx = ranges[i][0];
 104                 if (elements_int_list[indx] != -1) {
 105                     goto error_rank;
 106                 }
 107                 elements_int_list[indx] = i;
 108             }
 109         }
 110 
 111         free (elements_int_list);
 112     }
 113 
 114     OPAL_CR_ENTER_LIBRARY();
 115 
 116     err = ompi_group_range_excl(group,n_triplets,ranges,new_group);
 117     OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD,err,FUNC_NAME);
 118 
 119 error_rank:
 120     free(elements_int_list);
 121     return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_RANK, FUNC_NAME);
 122 }

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