root/ompi/datatype/ompi_datatype_create_struct.c

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

DEFINITIONS

This source file includes following definitions.
  1. ompi_datatype_create_struct

   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_struct( int count, const int* pBlockLength, const ptrdiff_t* pDisp,
  32                                      ompi_datatype_t* const * pTypes, ompi_datatype_t** newType )
  33 {
  34     ptrdiff_t disp = 0, endto, lastExtent, lastDisp;
  35     ompi_datatype_t *pdt, *lastType;
  36     int lastBlock;
  37     int i, start_from;
  38 
  39     /* Find first non-zero length element */
  40     for( i = 0; (i < count) && (0 == pBlockLength[i]); i++ );
  41     if( i == count ) {  /* either nothing or nothing relevant */
  42         return ompi_datatype_duplicate( &ompi_mpi_datatype_null.dt, newType);
  43     }
  44     /* compute the total number of elements before we can
  45      * avoid increasing the size of the desc array often.
  46      */
  47     start_from = i;
  48     lastType = (ompi_datatype_t*)pTypes[start_from];
  49     lastBlock = pBlockLength[start_from];
  50     lastExtent = lastType->super.ub - lastType->super.lb;
  51     lastDisp = pDisp[start_from];
  52     endto = pDisp[start_from] + lastExtent * lastBlock;
  53 
  54     for( i = (start_from + 1); i < count; i++ ) {
  55         if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) {
  56             lastBlock += pBlockLength[i];
  57             endto = lastDisp + lastBlock * lastExtent;
  58         } else {
  59             disp += lastType->super.desc.used;
  60             if( lastBlock > 1 ) disp += 2;
  61             lastType = (ompi_datatype_t*)pTypes[i];
  62             lastExtent = lastType->super.ub - lastType->super.lb;
  63             lastBlock = pBlockLength[i];
  64             lastDisp = pDisp[i];
  65             endto = lastDisp + lastExtent * lastBlock;
  66         }
  67     }
  68     disp += lastType->super.desc.used;
  69     if( lastBlock != 1 ) disp += 2;
  70 
  71     lastType = (ompi_datatype_t*)pTypes[start_from];
  72     lastBlock = pBlockLength[start_from];
  73     lastExtent = lastType->super.ub - lastType->super.lb;
  74     lastDisp = pDisp[start_from];
  75     endto = pDisp[start_from] + lastExtent * lastBlock;
  76 
  77     pdt = ompi_datatype_create( (int32_t)disp );
  78 
  79     /* Do again the same loop but now add the elements */
  80     for( i = (start_from + 1); i < count; i++ ) {
  81         if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) {
  82             lastBlock += pBlockLength[i];
  83             endto = lastDisp + lastBlock * lastExtent;
  84         } else {
  85             ompi_datatype_add( pdt, lastType, lastBlock, lastDisp, lastExtent );
  86             lastType = (ompi_datatype_t*)pTypes[i];
  87             lastExtent = lastType->super.ub - lastType->super.lb;
  88             lastBlock = pBlockLength[i];
  89             lastDisp = pDisp[i];
  90             endto = lastDisp + lastExtent * lastBlock;
  91         }
  92     }
  93     ompi_datatype_add( pdt, lastType, lastBlock, lastDisp, lastExtent );
  94 
  95      *newType = pdt;
  96     return OMPI_SUCCESS;
  97 }

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