root/ompi/mca/coll/base/coll_base_util.c

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

DEFINITIONS

This source file includes following definitions.
  1. ompi_coll_base_sendrecv_actual
  2. ompi_mirror_perm
  3. ompi_rounddown

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2016 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) 2014-2017 Research Organization for Information Science
  13  *                         and Technology (RIST). All rights reserved.
  14  * $COPYRIGHT$
  15  *
  16  * Additional copyrights may follow
  17  *
  18  * $HEADER$
  19  */
  20 
  21 #include "ompi_config.h"
  22 
  23 #include "mpi.h"
  24 #include "ompi/constants.h"
  25 #include "ompi/datatype/ompi_datatype.h"
  26 #include "ompi/communicator/communicator.h"
  27 #include "ompi/mca/coll/base/coll_tags.h"
  28 #include "ompi/mca/coll/base/coll_base_functions.h"
  29 #include "ompi/mca/pml/pml.h"
  30 #include "coll_base_util.h"
  31 
  32 int ompi_coll_base_sendrecv_actual( const void* sendbuf, size_t scount,
  33                                     ompi_datatype_t* sdatatype,
  34                                     int dest, int stag,
  35                                     void* recvbuf, size_t rcount,
  36                                     ompi_datatype_t* rdatatype,
  37                                     int source, int rtag,
  38                                     struct ompi_communicator_t* comm,
  39                                     ompi_status_public_t* status )
  40 
  41 { /* post receive first, then send, then wait... should be fast (I hope) */
  42     int err, line = 0;
  43     size_t rtypesize, stypesize;
  44     ompi_request_t *req = MPI_REQUEST_NULL;
  45     ompi_status_public_t rstatus;
  46 
  47     /* post new irecv */
  48     ompi_datatype_type_size(rdatatype, &rtypesize);
  49     err = MCA_PML_CALL(irecv( recvbuf, rcount, rdatatype, source, rtag,
  50                               comm, &req));
  51     if (err != MPI_SUCCESS) { line = __LINE__; goto error_handler; }
  52 
  53     /* send data to children */
  54     ompi_datatype_type_size(sdatatype, &stypesize);
  55     err = MCA_PML_CALL(send( sendbuf, scount, sdatatype, dest, stag,
  56                              MCA_PML_BASE_SEND_STANDARD, comm));
  57     if (err != MPI_SUCCESS) { line = __LINE__; goto error_handler; }
  58 
  59     err = ompi_request_wait( &req, &rstatus);
  60     if (err != MPI_SUCCESS) { line = __LINE__; goto error_handler; }
  61 
  62     if (MPI_STATUS_IGNORE != status) {
  63         *status = rstatus;
  64     }
  65 
  66     return (MPI_SUCCESS);
  67 
  68  error_handler:
  69     /* Error discovered during the posting of the irecv or send,
  70      * and no status is available.
  71      */
  72     OPAL_OUTPUT ((ompi_coll_base_framework.framework_output, "%s:%d: Error %d occurred\n",
  73                   __FILE__, line, err));
  74     (void)line;  // silence compiler warning
  75     if (MPI_STATUS_IGNORE != status) {
  76         status->MPI_ERROR = err;
  77     }
  78     return (err);
  79 }
  80 
  81 /*
  82  * ompi_mirror_perm: Returns mirror permutation of nbits low-order bits
  83  *                   of x [*].
  84  * [*] Warren Jr., Henry S. Hacker's Delight (2ed). 2013.
  85  *     Chapter 7. Rearranging Bits and Bytes.
  86  */
  87 unsigned int ompi_mirror_perm(unsigned int x, int nbits)
  88 {
  89     x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
  90     x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
  91     x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
  92     x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
  93     x = ((x >> 16) | (x << 16));
  94     return x >> (sizeof(x) * CHAR_BIT - nbits);
  95 }
  96 
  97 /*
  98  * ompi_rounddown: Rounds a number down to nearest multiple.
  99  *     rounddown(10,4) = 8, rounddown(6,3) = 6, rounddown(14,3) = 12
 100  */
 101 int ompi_rounddown(int num, int factor)
 102 {
 103     num /= factor;
 104     return num * factor;    /* floor(num / factor) * factor */
 105 }

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