root/ompi/datatype/ompi_datatype_create_vector.c

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

DEFINITIONS

This source file includes following definitions.
  1. ompi_datatype_create_vector
  2. ompi_datatype_create_hvector

   1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
   2 /*
   3  * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2019 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2006 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2009      Sun Microsystems, Inc. All rights reserved.
  14  * Copyright (c) 2009      Oak Ridge National Labs.  All rights reserved.
  15  * Copyright (c) 2010      Cisco Systems, Inc.  All rights reserved.
  16  * Copyright (c) 2017      Research Organization for Information Science
  17  *                         and Technology (RIST). All rights reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  23  */
  24 
  25 #include "ompi_config.h"
  26 
  27 #include <stddef.h>
  28 
  29 #include "ompi/datatype/ompi_datatype.h"
  30 
  31 int32_t ompi_datatype_create_vector( int count, int bLength, int stride,
  32                                      const ompi_datatype_t* oldType, ompi_datatype_t** newType )
  33 {
  34     ompi_datatype_t *pTempData, *pData;
  35     ptrdiff_t extent = oldType->super.ub - oldType->super.lb;
  36 
  37     if( (0 == count) || (0 == bLength) ) {
  38         return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType);
  39     }
  40 
  41     pData = ompi_datatype_create( oldType->super.desc.used + 2 );
  42     if( (bLength == stride) || (1 >= count) ) {  /* the elements are contiguous */
  43         ompi_datatype_add( pData, oldType, (size_t)count * bLength, 0, extent );
  44     } else {
  45         if( 1 == bLength ) {
  46             ompi_datatype_add( pData, oldType, count, 0, extent * stride );
  47         } else {
  48             ompi_datatype_add( pData, oldType, bLength, 0, extent );
  49             pTempData = pData;
  50             pData = ompi_datatype_create( oldType->super.desc.used + 2 + 2 );
  51             ompi_datatype_add( pData, pTempData, count, 0, extent * stride );
  52             OBJ_RELEASE( pTempData );
  53         }
  54     }
  55     *newType = pData;
  56     return OMPI_SUCCESS;
  57 }
  58 
  59 
  60 int32_t ompi_datatype_create_hvector( int count, int bLength, ptrdiff_t stride,
  61                                       const ompi_datatype_t* oldType, ompi_datatype_t** newType )
  62 {
  63     ompi_datatype_t *pTempData, *pData;
  64     ptrdiff_t extent = oldType->super.ub - oldType->super.lb;
  65 
  66     if( (0 == count) || (0 == bLength) ) {
  67         return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType);
  68     }
  69 
  70     pTempData = ompi_datatype_create( oldType->super.desc.used + 2 );
  71     if( ((extent * bLength) == stride) || (1 >= count) ) {  /* contiguous */
  72         pData = pTempData;
  73         ompi_datatype_add( pData, oldType, count * bLength, 0, extent );
  74     } else {
  75         if( 1 == bLength ) {
  76             pData = pTempData;
  77             ompi_datatype_add( pData, oldType, count, 0, stride );
  78         } else {
  79             ompi_datatype_add( pTempData, oldType, bLength, 0, extent );
  80             pData = ompi_datatype_create( oldType->super.desc.used + 2 + 2 );
  81             ompi_datatype_add( pData, pTempData, count, 0, stride );
  82             OBJ_RELEASE( pTempData );
  83         }
  84     }
  85      *newType = pData;
  86     return OMPI_SUCCESS;
  87 }

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