Blame src/mpi/datatype/type_indexed.c

Packit Service c5cf8c
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit Service c5cf8c
/*
Packit Service c5cf8c
 *
Packit Service c5cf8c
 *  (C) 2001 by Argonne National Laboratory.
Packit Service c5cf8c
 *      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
 */
Packit Service c5cf8c
Packit Service c5cf8c
#include "mpiimpl.h"
Packit Service c5cf8c
#include "datatype.h"
Packit Service c5cf8c
Packit Service c5cf8c
/* -- Begin Profiling Symbol Block for routine MPI_Type_indexed */
Packit Service c5cf8c
#if defined(HAVE_PRAGMA_WEAK)
Packit Service c5cf8c
#pragma weak MPI_Type_indexed = PMPI_Type_indexed
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit Service c5cf8c
#pragma _HP_SECONDARY_DEF PMPI_Type_indexed  MPI_Type_indexed
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit Service c5cf8c
#pragma _CRI duplicate MPI_Type_indexed as PMPI_Type_indexed
Packit Service c5cf8c
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit Service c5cf8c
int MPI_Type_indexed(int count, const int *array_of_blocklengths,
Packit Service c5cf8c
                     const int *array_of_displacements, MPI_Datatype oldtype,
Packit Service c5cf8c
                     MPI_Datatype * newtype) __attribute__ ((weak, alias("PMPI_Type_indexed")));
Packit Service c5cf8c
#endif
Packit Service c5cf8c
/* -- End Profiling Symbol Block */
Packit Service c5cf8c
Packit Service c5cf8c
/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
Packit Service c5cf8c
   the MPI routines */
Packit Service c5cf8c
#ifndef MPICH_MPI_FROM_PMPI
Packit Service c5cf8c
#undef MPI_Type_indexed
Packit Service c5cf8c
#define MPI_Type_indexed PMPI_Type_indexed
Packit Service c5cf8c
Packit Service c5cf8c
/*@
Packit Service c5cf8c
  MPIR_Type_indexed - create an indexed datatype
Packit Service c5cf8c
Packit Service c5cf8c
Input Parameters:
Packit Service c5cf8c
+ count - number of blocks in type
Packit Service c5cf8c
. blocklength_array - number of elements in each block
Packit Service c5cf8c
. displacement_array - offsets of blocks from start of type (see next
Packit Service c5cf8c
  parameter for units)
Packit Service c5cf8c
. dispinbytes - if nonzero, then displacements are in bytes (the
Packit Service c5cf8c
  displacement_array is an array of ints), otherwise they in terms of
Packit Service c5cf8c
  extent of oldtype (the displacement_array is an array of MPI_Aints)
Packit Service c5cf8c
- oldtype - type (using handle) of datatype on which new type is based
Packit Service c5cf8c
Packit Service c5cf8c
Output Parameters:
Packit Service c5cf8c
. newtype - handle of new indexed datatype
Packit Service c5cf8c
Packit Service c5cf8c
  Return Value:
Packit Service c5cf8c
  0 on success, -1 on failure.
Packit Service c5cf8c
@*/
Packit Service c5cf8c
Packit Service c5cf8c
int MPIR_Type_indexed(int count,
Packit Service c5cf8c
                      const int *blocklength_array,
Packit Service c5cf8c
                      const void *displacement_array,
Packit Service c5cf8c
                      int dispinbytes, MPI_Datatype oldtype, MPI_Datatype * newtype)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    int is_builtin, old_is_contig;
Packit Service c5cf8c
    int i;
Packit Service c5cf8c
    MPI_Aint contig_count;
Packit Service c5cf8c
    MPI_Aint el_sz, el_ct, old_ct, old_sz;
Packit Service c5cf8c
    MPI_Aint old_lb, old_ub, old_extent, old_true_lb, old_true_ub;
Packit Service c5cf8c
    MPI_Aint min_lb = 0, max_ub = 0, eff_disp;
Packit Service c5cf8c
    MPI_Datatype el_type;
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_Datatype *new_dtp;
Packit Service c5cf8c
Packit Service c5cf8c
    if (count == 0)
Packit Service c5cf8c
        return MPII_Type_zerolen(newtype);
Packit Service c5cf8c
Packit Service c5cf8c
    /* sanity check that blocklens are all non-negative */
Packit Service c5cf8c
    for (i = 0; i < count; ++i) {
Packit Service c5cf8c
        DLOOP_Assert(blocklength_array[i] >= 0);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* allocate new datatype object and handle */
Packit Service c5cf8c
    new_dtp = (MPIR_Datatype *) MPIR_Handle_obj_alloc(&MPIR_Datatype_mem);
Packit Service c5cf8c
    /* --BEGIN ERROR HANDLING-- */
Packit Service c5cf8c
    if (!new_dtp) {
Packit Service c5cf8c
        mpi_errno = MPIR_Err_create_code(MPI_SUCCESS,
Packit Service c5cf8c
                                         MPIR_ERR_RECOVERABLE,
Packit Service c5cf8c
                                         "MPIR_Type_indexed",
Packit Service c5cf8c
                                         __LINE__, MPI_ERR_OTHER, "**nomem", 0);
Packit Service c5cf8c
        return mpi_errno;
Packit Service c5cf8c
    }
Packit Service c5cf8c
    /* --END ERROR HANDLING-- */
Packit Service c5cf8c
Packit Service c5cf8c
    /* handle is filled in by MPIR_Handle_obj_alloc() */
Packit Service c5cf8c
    MPIR_Object_set_ref(new_dtp, 1);
Packit Service c5cf8c
    new_dtp->is_permanent = 0;
Packit Service c5cf8c
    new_dtp->is_committed = 0;
Packit Service c5cf8c
    new_dtp->attributes = NULL;
Packit Service c5cf8c
    new_dtp->cache_id = 0;
Packit Service c5cf8c
    new_dtp->name[0] = 0;
Packit Service c5cf8c
    new_dtp->contents = NULL;
Packit Service c5cf8c
Packit Service c5cf8c
    new_dtp->dataloop = NULL;
Packit Service c5cf8c
    new_dtp->dataloop_size = -1;
Packit Service c5cf8c
    new_dtp->dataloop_depth = -1;
Packit Service c5cf8c
Packit Service c5cf8c
    is_builtin = (HANDLE_GET_KIND(oldtype) == HANDLE_KIND_BUILTIN);
Packit Service c5cf8c
Packit Service c5cf8c
    if (is_builtin) {
Packit Service c5cf8c
        /* builtins are handled differently than user-defined types because
Packit Service c5cf8c
         * they have no associated dataloop or datatype structure.
Packit Service c5cf8c
         */
Packit Service c5cf8c
        el_sz = MPIR_Datatype_get_basic_size(oldtype);
Packit Service c5cf8c
        old_sz = el_sz;
Packit Service c5cf8c
        el_ct = 1;
Packit Service c5cf8c
        el_type = oldtype;
Packit Service c5cf8c
Packit Service c5cf8c
        old_lb = 0;
Packit Service c5cf8c
        old_true_lb = 0;
Packit Service c5cf8c
        old_ub = (MPI_Aint) el_sz;
Packit Service c5cf8c
        old_true_ub = (MPI_Aint) el_sz;
Packit Service c5cf8c
        old_extent = (MPI_Aint) el_sz;
Packit Service c5cf8c
        old_is_contig = 1;
Packit Service c5cf8c
Packit Service c5cf8c
        new_dtp->has_sticky_ub = 0;
Packit Service c5cf8c
        new_dtp->has_sticky_lb = 0;
Packit Service c5cf8c
Packit Service c5cf8c
        MPIR_Assign_trunc(new_dtp->alignsize, el_sz, MPI_Aint);
Packit Service c5cf8c
        new_dtp->builtin_element_size = el_sz;
Packit Service c5cf8c
        new_dtp->basic_type = el_type;
Packit Service c5cf8c
Packit Service c5cf8c
        new_dtp->max_contig_blocks = count;
Packit Service c5cf8c
    } else {
Packit Service c5cf8c
        /* user-defined base type (oldtype) */
Packit Service c5cf8c
        MPIR_Datatype *old_dtp;
Packit Service c5cf8c
Packit Service c5cf8c
        MPIR_Datatype_get_ptr(oldtype, old_dtp);
Packit Service c5cf8c
Packit Service c5cf8c
        /* Ensure that "builtin_element_size" fits into an int datatype. */
Packit Service c5cf8c
        MPIR_Ensure_Aint_fits_in_int(old_dtp->builtin_element_size);
Packit Service c5cf8c
Packit Service c5cf8c
        el_sz = old_dtp->builtin_element_size;
Packit Service c5cf8c
        old_sz = old_dtp->size;
Packit Service c5cf8c
        el_ct = old_dtp->n_builtin_elements;
Packit Service c5cf8c
        el_type = old_dtp->basic_type;
Packit Service c5cf8c
Packit Service c5cf8c
        old_lb = old_dtp->lb;
Packit Service c5cf8c
        old_true_lb = old_dtp->true_lb;
Packit Service c5cf8c
        old_ub = old_dtp->ub;
Packit Service c5cf8c
        old_true_ub = old_dtp->true_ub;
Packit Service c5cf8c
        old_extent = old_dtp->extent;
Packit Service c5cf8c
        MPIR_Datatype_is_contig(oldtype, &old_is_contig);
Packit Service c5cf8c
Packit Service c5cf8c
        new_dtp->has_sticky_lb = old_dtp->has_sticky_lb;
Packit Service c5cf8c
        new_dtp->has_sticky_ub = old_dtp->has_sticky_ub;
Packit Service c5cf8c
Packit Service c5cf8c
        new_dtp->alignsize = old_dtp->alignsize;
Packit Service c5cf8c
        new_dtp->builtin_element_size = (MPI_Aint) el_sz;
Packit Service c5cf8c
        new_dtp->basic_type = el_type;
Packit Service c5cf8c
Packit Service c5cf8c
        new_dtp->max_contig_blocks = 0;
Packit Service c5cf8c
        for (i = 0; i < count; i++)
Packit Service c5cf8c
            new_dtp->max_contig_blocks
Packit Service c5cf8c
                += old_dtp->max_contig_blocks * ((MPI_Aint) blocklength_array[i]);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* find the first nonzero blocklength element */
Packit Service c5cf8c
    i = 0;
Packit Service c5cf8c
    while (i < count && blocklength_array[i] == 0)
Packit Service c5cf8c
        i++;
Packit Service c5cf8c
Packit Service c5cf8c
    if (i == count) {
Packit Service c5cf8c
        MPIR_Handle_obj_free(&MPIR_Datatype_mem, new_dtp);
Packit Service c5cf8c
        return MPII_Type_zerolen(newtype);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* priming for loop */
Packit Service c5cf8c
    old_ct = blocklength_array[i];
Packit Service c5cf8c
    eff_disp = (dispinbytes) ? ((MPI_Aint *) displacement_array)[i] :
Packit Service c5cf8c
        (((MPI_Aint) ((int *) displacement_array)[i]) * old_extent);
Packit Service c5cf8c
Packit Service c5cf8c
    MPII_DATATYPE_BLOCK_LB_UB((MPI_Aint) blocklength_array[i],
Packit Service c5cf8c
                              eff_disp, old_lb, old_ub, old_extent, min_lb, max_ub);
Packit Service c5cf8c
Packit Service c5cf8c
    /* determine min lb, max ub, and count of old types in remaining
Packit Service c5cf8c
     * nonzero size blocks
Packit Service c5cf8c
     */
Packit Service c5cf8c
    for (i++; i < count; i++) {
Packit Service c5cf8c
        MPI_Aint tmp_lb, tmp_ub;
Packit Service c5cf8c
Packit Service c5cf8c
        if (blocklength_array[i] > 0) {
Packit Service c5cf8c
            old_ct += blocklength_array[i];     /* add more oldtypes */
Packit Service c5cf8c
Packit Service c5cf8c
            eff_disp = (dispinbytes) ? ((MPI_Aint *) displacement_array)[i] :
Packit Service c5cf8c
                (((MPI_Aint) ((int *) displacement_array)[i]) * old_extent);
Packit Service c5cf8c
Packit Service c5cf8c
            /* calculate ub and lb for this block */
Packit Service c5cf8c
            MPII_DATATYPE_BLOCK_LB_UB((MPI_Aint) (blocklength_array[i]),
Packit Service c5cf8c
                                      eff_disp, old_lb, old_ub, old_extent, tmp_lb, tmp_ub);
Packit Service c5cf8c
Packit Service c5cf8c
            if (tmp_lb < min_lb)
Packit Service c5cf8c
                min_lb = tmp_lb;
Packit Service c5cf8c
            if (tmp_ub > max_ub)
Packit Service c5cf8c
                max_ub = tmp_ub;
Packit Service c5cf8c
        }
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    new_dtp->size = old_ct * old_sz;
Packit Service c5cf8c
Packit Service c5cf8c
    new_dtp->lb = min_lb;
Packit Service c5cf8c
    new_dtp->ub = max_ub;
Packit Service c5cf8c
    new_dtp->true_lb = min_lb + (old_true_lb - old_lb);
Packit Service c5cf8c
    new_dtp->true_ub = max_ub + (old_true_ub - old_ub);
Packit Service c5cf8c
    new_dtp->extent = max_ub - min_lb;
Packit Service c5cf8c
Packit Service c5cf8c
    new_dtp->n_builtin_elements = old_ct * el_ct;
Packit Service c5cf8c
Packit Service c5cf8c
    /* new type is only contig for N types if it's all one big
Packit Service c5cf8c
     * block, its size and extent are the same, and the old type
Packit Service c5cf8c
     * was also contiguous.
Packit Service c5cf8c
     */
Packit Service c5cf8c
    new_dtp->is_contig = 0;
Packit Service c5cf8c
    if (old_is_contig) {
Packit Service c5cf8c
        MPI_Aint *blklens = MPL_malloc(count * sizeof(MPI_Aint), MPL_MEM_DATATYPE);
Packit Service c5cf8c
        MPIR_Assert(blklens != NULL);
Packit Service c5cf8c
        for (i = 0; i < count; i++)
Packit Service c5cf8c
            blklens[i] = blocklength_array[i];
Packit Service c5cf8c
        contig_count = MPIR_Type_indexed_count_contig(count,
Packit Service c5cf8c
                                                      blklens,
Packit Service c5cf8c
                                                      displacement_array, dispinbytes, old_extent);
Packit Service c5cf8c
        new_dtp->max_contig_blocks = contig_count;
Packit Service c5cf8c
        if ((contig_count == 1) && ((MPI_Aint) new_dtp->size == new_dtp->extent)) {
Packit Service c5cf8c
            new_dtp->is_contig = 1;
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPL_free(blklens);
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    *newtype = new_dtp->handle;
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIR_Type_indexed_impl
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
int MPIR_Type_indexed_impl(int count, const int *array_of_blocklengths,
Packit Service c5cf8c
                           const int *array_of_displacements,
Packit Service c5cf8c
                           MPI_Datatype oldtype, MPI_Datatype * newtype)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    MPI_Datatype new_handle;
Packit Service c5cf8c
    MPIR_Datatype *new_dtp;
Packit Service c5cf8c
    int i, *ints;
Packit Service c5cf8c
    MPIR_CHKLMEM_DECL(1);
Packit Service c5cf8c
Packit Service c5cf8c
    mpi_errno = MPIR_Type_indexed(count, array_of_blocklengths, array_of_displacements, 0,      /* displacements not in bytes */
Packit Service c5cf8c
                                  oldtype, &new_handle);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
    /* copy all integer values into a temporary buffer; this
Packit Service c5cf8c
     * includes the count, the blocklengths, and the displacements.
Packit Service c5cf8c
     */
Packit Service c5cf8c
    MPIR_CHKLMEM_MALLOC(ints, int *, (2 * count + 1) * sizeof(int), mpi_errno,
Packit Service c5cf8c
                        "contents integer array", MPL_MEM_BUFFER);
Packit Service c5cf8c
Packit Service c5cf8c
    ints[0] = count;
Packit Service c5cf8c
Packit Service c5cf8c
    for (i = 0; i < count; i++) {
Packit Service c5cf8c
        ints[i + 1] = array_of_blocklengths[i];
Packit Service c5cf8c
    }
Packit Service c5cf8c
    for (i = 0; i < count; i++) {
Packit Service c5cf8c
        ints[i + count + 1] = array_of_displacements[i];
Packit Service c5cf8c
    }
Packit Service c5cf8c
    MPIR_Datatype_get_ptr(new_handle, new_dtp);
Packit Service c5cf8c
    mpi_errno = MPIR_Datatype_set_contents(new_dtp, MPI_COMBINER_INDEXED, 2 * count + 1,        /* ints */
Packit Service c5cf8c
                                           0,   /* aints  */
Packit Service c5cf8c
                                           1,   /* types */
Packit Service c5cf8c
                                           ints, NULL, &oldtype);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        MPIR_ERR_POP(mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_OBJ_PUBLISH_HANDLE(*newtype, new_handle);
Packit Service c5cf8c
Packit Service c5cf8c
  fn_exit:
Packit Service c5cf8c
    MPIR_CHKLMEM_FREEALL();
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
  fn_fail:
Packit Service c5cf8c
    goto fn_exit;
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPI_Type_indexed
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
/*@
Packit Service c5cf8c
    MPI_Type_indexed - Creates an indexed datatype
Packit Service c5cf8c
Packit Service c5cf8c
Input Parameters:
Packit Service c5cf8c
+ count - number of blocks -- also number of entries in array_of_displacements and array_of_blocklengths
Packit Service c5cf8c
. array_of_blocklengths - number of elements in each block (array of nonnegative integers)
Packit Service c5cf8c
. array_of_displacements - displacement of each block in multiples of oldtype (array of
Packit Service c5cf8c
  integers)
Packit Service c5cf8c
- oldtype - old datatype (handle)
Packit Service c5cf8c
Packit Service c5cf8c
Output Parameters:
Packit Service c5cf8c
. newtype - new datatype (handle)
Packit Service c5cf8c
Packit Service c5cf8c
.N ThreadSafe
Packit Service c5cf8c
Packit Service c5cf8c
.N Fortran
Packit Service c5cf8c
Packit Service c5cf8c
The array_of_displacements are displacements, and are based on a zero origin.  A common error
Packit Service c5cf8c
is to do something like to following
Packit Service c5cf8c
.vb
Packit Service c5cf8c
    integer a(100)
Packit Service c5cf8c
    integer array_of_blocklengths(10), array_of_displacements(10)
Packit Service c5cf8c
    do i=1,10
Packit Service c5cf8c
         array_of_blocklengths(i)   = 1
Packit Service c5cf8c
10       array_of_displacements(i) = 1 + (i-1)*10
Packit Service c5cf8c
    call MPI_TYPE_INDEXED(10,array_of_blocklengths,array_of_displacements,MPI_INTEGER,newtype,ierr)
Packit Service c5cf8c
    call MPI_TYPE_COMMIT(newtype,ierr)
Packit Service c5cf8c
    call MPI_SEND(a,1,newtype,...)
Packit Service c5cf8c
.ve
Packit Service c5cf8c
expecting this to send "a(1),a(11),..." because the array_of_displacements have values
Packit Service c5cf8c
"1,11,...".   Because these are `displacements` from the beginning of "a",
Packit Service c5cf8c
it actually sends "a(1+1),a(1+11),...".
Packit Service c5cf8c
Packit Service c5cf8c
If you wish to consider the displacements as array_of_displacements into a Fortran array,
Packit Service c5cf8c
consider declaring the Fortran array with a zero origin
Packit Service c5cf8c
.vb
Packit Service c5cf8c
    integer a(0:99)
Packit Service c5cf8c
.ve
Packit Service c5cf8c
Packit Service c5cf8c
.N Errors
Packit Service c5cf8c
.N MPI_ERR_COUNT
Packit Service c5cf8c
.N MPI_ERR_TYPE
Packit Service c5cf8c
.N MPI_ERR_ARG
Packit Service c5cf8c
.N MPI_ERR_EXHAUSTED
Packit Service c5cf8c
@*/
Packit Service c5cf8c
int MPI_Type_indexed(int count,
Packit Service c5cf8c
                     const int *array_of_blocklengths,
Packit Service c5cf8c
                     const int *array_of_displacements,
Packit Service c5cf8c
                     MPI_Datatype oldtype, MPI_Datatype * newtype)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_TYPE_INDEXED);
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_ERRTEST_INITIALIZED_ORDIE();
Packit Service c5cf8c
Packit Service c5cf8c
    MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit Service c5cf8c
    MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_TYPE_INDEXED);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Validate parameters and objects (post conversion) */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPID_BEGIN_ERROR_CHECKS;
Packit Service c5cf8c
        {
Packit Service c5cf8c
            int j;
Packit Service c5cf8c
            MPIR_Datatype *datatype_ptr = NULL;
Packit Service c5cf8c
Packit Service c5cf8c
            MPIR_ERRTEST_COUNT(count, mpi_errno);
Packit Service c5cf8c
            if (count > 0) {
Packit Service c5cf8c
                MPIR_ERRTEST_ARGNULL(array_of_blocklengths, "array_of_blocklengths", mpi_errno);
Packit Service c5cf8c
                MPIR_ERRTEST_ARGNULL(array_of_displacements, "array_of_displacements", mpi_errno);
Packit Service c5cf8c
            }
Packit Service c5cf8c
            MPIR_ERRTEST_DATATYPE(oldtype, "datatype", mpi_errno);
Packit Service c5cf8c
Packit Service c5cf8c
            if (HANDLE_GET_KIND(oldtype) != HANDLE_KIND_BUILTIN) {
Packit Service c5cf8c
                MPIR_Datatype_get_ptr(oldtype, datatype_ptr);
Packit Service c5cf8c
                MPIR_Datatype_valid_ptr(datatype_ptr, mpi_errno);
Packit Service c5cf8c
            }
Packit Service c5cf8c
            /* verify that all blocklengths are >= 0 */
Packit Service c5cf8c
            for (j = 0; j < count; j++) {
Packit Service c5cf8c
                MPIR_ERRTEST_ARGNEG(array_of_blocklengths[j], "blocklength", mpi_errno);
Packit Service c5cf8c
            }
Packit Service c5cf8c
Packit Service c5cf8c
            MPIR_ERRTEST_ARGNULL(newtype, "newtype", mpi_errno);
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPID_END_ERROR_CHECKS;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif /* HAVE_ERROR_CHECKING */
Packit Service c5cf8c
Packit Service c5cf8c
    /* ... body of routine ...  */
Packit Service c5cf8c
Packit Service c5cf8c
    mpi_errno =
Packit Service c5cf8c
        MPIR_Type_indexed_impl(count, array_of_blocklengths, array_of_displacements, oldtype,
Packit Service c5cf8c
                               newtype);
Packit Service c5cf8c
    if (mpi_errno)
Packit Service c5cf8c
        goto fn_fail;
Packit Service c5cf8c
Packit Service c5cf8c
    /* ... end of body of routine ... */
Packit Service c5cf8c
Packit Service c5cf8c
  fn_exit:
Packit Service c5cf8c
    MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_TYPE_INDEXED);
Packit Service c5cf8c
    MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
Packit Service c5cf8c
  fn_fail:
Packit Service c5cf8c
    /* --BEGIN ERROR HANDLING-- */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        mpi_errno =
Packit Service c5cf8c
            MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER,
Packit Service c5cf8c
                                 "**mpi_type_indexed", "**mpi_type_indexed %d %p %p %D %p", count,
Packit Service c5cf8c
                                 array_of_blocklengths, array_of_displacements, oldtype, newtype);
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
    mpi_errno = MPIR_Err_return_comm(NULL, FCNAME, mpi_errno);
Packit Service c5cf8c
    goto fn_exit;
Packit Service c5cf8c
    /* --END ERROR HANDLING-- */
Packit Service c5cf8c
}